import { ShellPage } from "@/components/page-templates";
import { Button, SectionCard } from "@/components/ui";
import { getSession } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
import { redirect } from "next/navigation";

export default async function BusinessHoursSettingsPage() {
  const session = await getSession();
  if (!session) {
    redirect("/login");
  }

  if (session.role === "agent") {
    redirect("/unauthorized");
  }

  const tenant = await prisma.tenant.findUnique({
    where: { id: session.tenantId },
    select: {
      timezone: true
    }
  });

  if (!tenant) {
    redirect("/unauthorized");
  }

  return (
    <ShellPage shell="admin" title="Business Hours" description="Jam operasional tenant.">
      <SectionCard title="Schedule">
        <div className="grid gap-4 md:max-w-2xl">
          <input
            className="rounded-xl border border-line px-4 py-3"
            defaultValue={`Timezone aktif: ${tenant.timezone}`}
            readOnly
          />
          <p className="text-sm text-on-surface-variant">
            Saat ini pengaturan jam operasional belum memiliki tabel konfigurasi tersendiri di schema ini.
          </p>
          <div>
            <Button href="/settings">Back to Settings</Button>
          </div>
        </div>
      </SectionCard>
    </ShellPage>
  );
}
