import { T as reactExports, K as jsxRuntimeExports } from "./server-ChzsfjB9.js";
import { h as useNavigate, f as useAuth, s as supabase, L as Link } from "./router-uu4vGjiO.js";
import { C as ChartColumn, I as Input, B as Button, L as LoaderCircle } from "./input-muzHTpl5.js";
import { L as Label } from "./label-2bHC70jG.js";
import { a as EyeOff, E as Eye, C as Checkbox } from "./checkbox-DydFtybM.js";
import { M as Mail } from "./mail-FNeJCwvC.js";
import { L as Lock } from "./lock-0me_4kb9.js";
import "node:async_hooks";
import "node:stream/web";
import "node:stream";
import "./index-BxBx9O65.js";
import "./index-CZazwQDH.js";
function LoginPage() {
  const navigate = useNavigate();
  const {
    login,
    isAuthenticated,
    loading
  } = useAuth();
  const [email, setEmail] = reactExports.useState("");
  const [password, setPassword] = reactExports.useState("");
  const [remember, setRemember] = reactExports.useState(true);
  const [showPw, setShowPw] = reactExports.useState(false);
  const [error, setError] = reactExports.useState(null);
  const [submitting, setSubmitting] = reactExports.useState(false);
  const [sysLogo, setSysLogo] = reactExports.useState(null);
  const [sysName, setSysName] = reactExports.useState("365-BI");
  reactExports.useEffect(() => {
    if (!loading && isAuthenticated) navigate({
      to: "/"
    });
  }, [loading, isAuthenticated, navigate]);
  reactExports.useEffect(() => {
    supabase.from("system_config").select("titulo_sistema, logo_url").limit(1).maybeSingle().then(({
      data
    }) => {
      if (data?.logo_url) setSysLogo(data.logo_url);
      if (data?.titulo_sistema) setSysName(data.titulo_sistema);
    });
  }, []);
  const onSubmit = async (e) => {
    e.preventDefault();
    setError(null);
    setSubmitting(true);
    try {
      await login(email, password, remember);
      navigate({
        to: "/"
      });
    } catch (err) {
      setError(err instanceof Error ? err.message : "Erro ao entrar.");
    } finally {
      setSubmitting(false);
    }
  };
  return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "min-h-screen w-full flex items-center justify-center bg-gradient-to-br from-muted/40 via-background to-accent/30 px-4 py-10", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "w-full max-w-md", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "mb-6 flex flex-col items-center", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex h-14 w-14 items-center justify-center rounded-xl bg-gradient-to-br from-primary to-primary-glow shadow-lg shadow-primary/20 overflow-hidden", children: sysLogo ? /* @__PURE__ */ jsxRuntimeExports.jsx("img", { src: sysLogo, alt: sysName, className: "h-full w-full object-contain" }) : /* @__PURE__ */ jsxRuntimeExports.jsx(ChartColumn, { className: "h-6 w-6 text-primary-foreground" }) }),
      /* @__PURE__ */ jsxRuntimeExports.jsx("h1", { className: "mt-3 text-xl font-bold tracking-tight", children: sysName }),
      /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-muted-foreground", children: "Business Intelligence Platform" })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "rounded-2xl border border-border bg-card p-6 shadow-xl shadow-black/[0.04] sm:p-8", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "mb-6 space-y-1", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx("h2", { className: "text-lg font-semibold", children: "Bem-vindo de volta" }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-muted-foreground", children: "Entre com seu e-mail e senha para acessar" })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("form", { onSubmit, className: "space-y-4", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-1.5", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Label, { htmlFor: "email", children: "E-mail" }),
          /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "relative", children: [
            /* @__PURE__ */ jsxRuntimeExports.jsx(Mail, { className: "absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" }),
            /* @__PURE__ */ jsxRuntimeExports.jsx(Input, { id: "email", type: "email", required: true, autoComplete: "email", placeholder: "voce@empresa.com", value: email, onChange: (e) => setEmail(e.target.value), className: "h-11 pl-9" })
          ] })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-1.5", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between", children: [
            /* @__PURE__ */ jsxRuntimeExports.jsx(Label, { htmlFor: "password", children: "Senha" }),
            /* @__PURE__ */ jsxRuntimeExports.jsx(Link, { to: "/recuperar-senha", className: "text-xs font-medium text-primary hover:underline", children: "Esqueci minha senha" })
          ] }),
          /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "relative", children: [
            /* @__PURE__ */ jsxRuntimeExports.jsx(Lock, { className: "absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" }),
            /* @__PURE__ */ jsxRuntimeExports.jsx(Input, { id: "password", type: showPw ? "text" : "password", required: true, autoComplete: "current-password", placeholder: "••••••••", value: password, onChange: (e) => setPassword(e.target.value), className: "h-11 pl-9 pr-10" }),
            /* @__PURE__ */ jsxRuntimeExports.jsx("button", { type: "button", onClick: () => setShowPw((s) => !s), className: "absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground", "aria-label": "Mostrar senha", children: showPw ? /* @__PURE__ */ jsxRuntimeExports.jsx(EyeOff, { className: "h-4 w-4" }) : /* @__PURE__ */ jsxRuntimeExports.jsx(Eye, { className: "h-4 w-4" }) })
          ] })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("label", { className: "flex items-center gap-2 text-sm text-muted-foreground cursor-pointer select-none", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Checkbox, { checked: remember, onCheckedChange: (v) => setRemember(!!v) }),
          "Lembrar acesso neste dispositivo"
        ] }),
        error && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive", children: error }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { type: "submit", className: "w-full h-11", disabled: submitting, children: submitting ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(LoaderCircle, { className: "h-4 w-4 animate-spin" }),
          " Entrando..."
        ] }) : "Entrar" })
      ] })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "mt-6 text-center text-xs text-muted-foreground", children: [
      "© ",
      (/* @__PURE__ */ new Date()).getFullYear(),
      " Diário de bordo · Todos os direitos reservados"
    ] })
  ] }) });
}
export {
  LoginPage as component
};
