import LoginClient from "@/app/login/login-client";
import SponsoredSupplierFormClient from "@/app/fornecedores-patrocinados/form-client";
import { createClient } from "@/lib/supabase-server";
import { isOwnerUser } from "@/lib/owner-auth";

export default async function OwnerSponsoredSupplierCreatePage() {
  const supabase = await createClient();
  const {
    data: { user },
  } = await supabase.auth.getUser();

  if (!user) {
    return <LoginClient />;
  }

  if (!isOwnerUser({ id: user.id, email: user.email })) {
    return (
      <div className="min-h-screen flex items-center justify-center p-6 bg-slate-50">
        <div className="w-full max-w-lg rounded-2xl bg-white p-8 shadow-sm border border-slate-200 text-center">
          <h1 className="text-xl font-semibold text-slate-900">Acesso negado</h1>
          <p className="text-sm text-slate-500 mt-2">Seu usuário não tem permissão para acessar este painel.</p>
        </div>
      </div>
    );
  }

  return <SponsoredSupplierFormClient mode="create" initial={null} />;
}
