import { Handlers } from "$fresh/server.ts";
import { Content } from "../../components/Content.tsx";
import { Terminal } from "../../islands/terminal.tsx";
import { SERVER_STATE } from "../../state/serverState.ts";

export const handler: Handlers = {
  async GET(req,ctx) {
    if (!SERVER_STATE.eulaAccepted) {
      const url = new URL(req.url);
      return Response.redirect(`${url.origin}/setup/eula`)
    }
    
    const res = await ctx.render();
    return res;
  }
}

export default function StartFabric() {
  SERVER_STATE.startMCServer();
  return (
    <div class="container p-8">
      <Content>
        <Terminal channelId={SERVER_STATE.channelId} />
      </Content>
    </div>
  );
}
