import { subdomainPackageInfo } from "../orchestrator"
import type { LoaderProps } from "@workshop/nano-remix"

export const loader = async (_req: Request) => {
  const packagePaths = await subdomainPackageInfo()
  return { packagePaths }
}

export default function Index({ packagePaths }: LoaderProps<typeof loader>) {
  const url = new URL(import.meta.url)

  return (
    <div>
      <h1>Subdomain Servers</h1>
      <ul>
        {packagePaths.map((pkg) => (
          <li key={pkg.packageName}>
            <a href={`${url.protocol}//${pkg.packageName}.${url.host}`}>{pkg.packageName}</a>
          </li>
        ))}
      </ul>
    </div>
  )
}
