// eslint-disable no-useless-spread

/* eslint-disable unicorn/numeric-separators-style */
// eslint-disable no-unused-vars

// https://en.wikipedia.org/wiki/Two-line_element_set#Format

export const DEMO_DATA = {
  // #############################
  tleJson: {
    ARG_OF_PERICENTER: 181.9338,
    BSTAR: 0.00039937,
    CLASSIFICATION_TYPE: 'U',
    ECCENTRICITY: 0.7375486,
    ELEMENT_SET_NO: 999,
    EPHEMERIS_TYPE: 0,
    EPOCH: '2025-03-12T15:49:04.420416',
    INCLINATION: 19.0363,
    MEAN_ANOMALY: 171.615,
    MEAN_MOTION: 2.21786616,
    MEAN_MOTION_DDOT: -5.0502e-7,
    MEAN_MOTION_DOT: 0.00072212,
    NORAD_CAT_ID: 63158,
    OBJECT_ID: '2025-045B',
    OBJECT_NAME: '2025-045B',
    RA_OF_ASC_NODE: 63.0294,
    REV_AT_EPOCH: 13,
  },
  get tleLine1() {
    return this.tleString.split('\n')[1];
  },
  get tleLine2() {
    return this.tleString.split('\n')[2];
  },
  get tleName() {
    return this.tleString.split('\n')[0];
  },
  tleString: `2025-045B
1 63158U 25045B   25071.65907894  .00072212 -50502-6  39937-3 0  9999
2 63158  19.0363  63.0294 7375486 181.9338 171.6150  2.21786616   127`,
};

export const TLE_LIST = [
  DEMO_DATA.tleString,
  ...[
    `STARLINK-32915
1 63152U 25043W   25070.91668981  .00451203  87802-4  12020-2 0  9994
2 63152  43.0011 279.4620 0003944 269.6759 119.1758 15.93738994  2341`,
    `STARLINK-32915 [测修改1]
1 00000U 00000W   25070.91668981  .00000000  00000-0  00000-0 0  0000
2 00000  43.0011 279.4620 0003944 269.6759 119.1758 15.93738994  0000`,
  ],
];

// 为了twoline2satrec函数需要哪些参数
// https://github.com/shashwatak/satellite-js/blob/0e921026d20b75f42553366994af70eed63a304f/src/io.js#L62
function twoline2satrecFake(longstr1: string, longstr2: string) {
  console.group('twoline2satrecFake');
  const satrec = {} as Record<string, any>;
  satrec.error = 0;

  satrec.satnum = longstr1.slice(2, 7);
  console.debug(`longstr1.substring(2, 7) :>>`, `"${longstr1.slice(2, 7)}"`);

  satrec.epochyr = Number.parseInt(longstr1.slice(18, 20), 10);
  console.debug(`longstr1.substring(18, 20) :>>`, `"${longstr1.slice(18, 20)}"`);

  satrec.epochdays = Number.parseFloat(longstr1.slice(20, 32));
  console.debug(`longstr1.substring(20, 32) :>>`, `"${longstr1.slice(20, 32)}"`);

  satrec.ndot = Number.parseFloat(longstr1.slice(33, 43));
  console.debug(`longstr1.substring(33, 43) :>>`, `"${longstr1.slice(33, 43)}"`);

  satrec.nddot = Number.parseFloat(`.${Number.parseInt(longstr1.slice(44, 50), 10)}E${longstr1.slice(50, 52)}`);
  console.debug(`longstr1.substring(44, 50) :>>`, `"${longstr1.slice(44, 50)}"`);
  console.debug(`longstr1.substring(50, 52) :>>`, `"${longstr1.slice(50, 52)}"`);

  satrec.bstar = Number.parseFloat(
    `${longstr1.slice(53, 54)}.${Number.parseInt(longstr1.slice(54, 59), 10)}E${longstr1.slice(59, 61)}`,
  );
  console.debug(`longstr1.substring(53, 54) :>>`, `"${longstr1.slice(53, 54)}"`);
  console.debug(`longstr1.substring(54, 59) :>>`, `"${longstr1.slice(54, 59)}"`);
  console.debug(`longstr1.substring(59, 61) :>>`, `"${longstr1.slice(59, 61)}"`);

  // satrec.satnum = longstr2.substring(2, 7);
  satrec.inclo = Number.parseFloat(longstr2.slice(8, 16));
  console.debug(`longstr2.substring(8, 16) :>>`, `"${longstr2.slice(8, 16)}"`);

  satrec.nodeo = Number.parseFloat(longstr2.slice(17, 25));
  console.debug(`longstr2.substring(17, 25) :>>`, `"${longstr2.slice(17, 25)}"`);

  satrec.ecco = Number.parseFloat(`.${longstr2.slice(26, 33)}`);
  console.debug(`longstr2.substring(26, 33) :>>`, `"${longstr2.slice(26, 33)}"`);
  satrec.argpo = Number.parseFloat(longstr2.slice(34, 42));
  console.debug(`longstr2.substring(34, 42) :>>`, `"${longstr2.slice(34, 42)}"`);
  satrec.mo = Number.parseFloat(longstr2.slice(43, 51));
  console.debug(`longstr2.substring(43, 51) :>>`, `"${longstr2.slice(43, 51)}"`);
  satrec.no = Number.parseFloat(longstr2.slice(52, 63));
  console.debug(`longstr2.substring(52, 63) :>>`, `"${longstr2.slice(52, 63)}"`);

  console.groupEnd();
  return satrec;
}
let line1 = '';
line1 += '1'; //
line1 += ' '; //
line1 += '62949'; // 卫星编号
line1 += 'U'; // 卫星分类
line1 += ' ';
line1 += '25';
line1 += '029';
line1 += 'B'.padEnd(3, ' ');
line1 += ' ';
line1 += '25070.91668981'; // 🛰️ 历元时间 25070.91668981（年份 2025，第 70 天加 0.91668981 天）
line1 += ' ';
line1 += '.00039463'.padStart(10, ' '); //
line1 += '00000+0'.padStart(9, ' '); //
line1 += '99294-3'.padStart(9, ' '); //
line1 += ' ';
line1 += '0';
line1 += ' ';
line1 += '999'.padStart(4, ' ');
line1 += '0';

let line2 = '';
line2 += '2';
line2 += ' ';
line2 += '62949';
line2 += ' ';
line2 += '53.1596'.padStart(8, ' '); // 🛰️ 轨道倾角（度）
line2 += ' ';
line2 += '120.9032'; // 🛰️ 升交点赤经（度）
line2 += ' ';
line2 += '0001355'; // 🛰️ 偏心率
line2 += ' ';
line2 += '101.1211'; // 🛰️ 近地点角距（度）
line2 += ' ';
line2 += '35.9659'.padStart(8, ' '); // 🛰️ 平近点角（度）
line2 += ' ';
line2 += '15.39574303'; // 🛰️ 平均运动（圈/天）
line2 += '580'.padStart(5, ' ');
line2 += '9';

// console.debug(`xxxline2 :>>`, `"${line2}"`);
// console.debug('正确↓');
// console.debug(`longstr2 :>>`, `"${longstr2}"`);
// twoline2satrecFake('', line2);
// twoline2satrecFake('', longstr2);
// const numbers = '0123456789';
// twoline2satrecFake(
//   `${numbers}${numbers}${numbers}${numbers}${numbers}${numbers}`,
//   '',
// );

// if ($__DEV__) {
//   const tle = TLE_LIST[0] as string;
//   const line1 = tle.split('\n')[1] as string;
//   const line2 = tle.split('\n')[2] as string;
//   console.clear();
//   twoline2satrecFake(line1, line2);
// }

// if ($__DEV__) {
//   const satrec2 = twoline2satrec(
//     `1 62949           25070.91668981  .00039463  00000+0  99294-3        `,
//     `2        53.1596 120.9032 0001355 101.1211  35.9659 15.39574303      `,
//   );
//   const satrec1_str = JSON.stringify(satrec1, null, 2);
//   const satrec2_str = JSON.stringify(satrec2, null, 2);
//   console.debug(`satrec1_str === satrec2_str :>>`, satrec1_str === satrec2_str);
// }

// longstr1.substring(2, 7) :>>  "63157"
// longstr1.substring(18, 20) :>>  "25"
// longstr1.substring(20, 32) :>>  "069.35219743"
// longstr1.substring(33, 43) :>>  " .00000545"
// longstr1.substring(44, 50) :>>  "-65692"
// longstr1.substring(50, 52) :>>  "-6"
// longstr1.substring(53, 54) :>>  " "
// longstr1.substring(54, 59) :>>  "00000"
// longstr1.substring(59, 61) :>>  "+0"
//
// longstr2.substring(8, 16) :>>  " 19.0062"
// longstr2.substring(17, 25) :>>  " 64.6364"
// longstr2.substring(26, 33) :>>  "7327661"
// longstr2.substring(34, 42) :>>  "179.7218"
// longstr2.substring(43, 51) :>>  "141.4162"
// longstr2.substring(52, 63) :>>  " 2.26206155"
