import { $ } from 'bun'

const GIT_HASH = process.env.RENDER_GIT_COMMIT?.slice(0, 7)
  || await $`git rev-parse --short HEAD`.text().then(s => s.trim()).catch(() => 'unknown')

export default () => <>
  <html lang="en">
    <head>
      <title>hype</title>
      <meta charset="utf-8" />
      <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      <meta name="color-scheme" content="light dark" />

      <link href={`/css/main.css?${GIT_HASH}`} rel="stylesheet" />
      <script dangerouslySetInnerHTML={{
        __html: `
        window.GIT_HASH = '${GIT_HASH}';
        ${(process.env.NODE_ENV !== 'production' || process.env.IS_PULL_REQUEST === 'true') ? 'window.DEBUG = true;' : ''}
        `
      }} />
    </head>
    <body>
      <div id="viewport">
        <main>
          <div id="root" />
          <script src={`/client/app.js?${GIT_HASH}`} type="module" />
        </main>
      </div>
    </body>
  </html>
</>
