// ts/corps.ts
var main = document.querySelector("main");
(async () => {
  const loader = document.querySelector("#loader");
  loader.style.display = "block";
  try {
    await render();
  } catch (e) {
    main.textContent = e instanceof Error ? e.message : String(e);
  }
  loader.style.display = "none";
})();
async function render() {
  const corps = await fetch("corps.json").then((r) => r.json());
  corps.sort((a, b) => (a.headquartersAddress?.lines.find((line) => line.type === "SYSTEM").entity.naturalId ?? "").localeCompare(b.headquartersAddress?.lines.find((line) => line.type === "SYSTEM").entity.naturalId ?? ""));
  main.innerHTML = `<table>
		<thead>
			<tr>
				<th>code</th>
				<th>name</th>
				<th>shareholders</th>
				<th>HQ</th>
			</tr>
		</thead>
		<tbody>
			${corps.map(renderCorpRow).join("")}
		</tbody>
	</table>`;
}
function renderCorpRow(corp) {
  let hq = "";
  if (corp.headquartersAddress !== null) {
    const planet = corp.headquartersAddress.lines.find((line) => line.type === "PLANET").entity;
    hq = planet.name;
    if (planet.name !== planet.naturalId)
      hq += ` (${planet.naturalId})`;
    if (!corp.headquartersFinished)
      hq += " [unfinished]";
  }
  return `<tr>
		<td>${corp.code}</td>
		<td>${corp.name}</td>
		<td>${corp.shareholders.length}</td>
		<td>${hq}</td>
	</tr>`;
}

//# debugId=938663E409BCBBAE64756E2164756E21
