1import{r,j as e}from"./vendor-three-BGGFfWe7.js";import{a as b,u as f,bN as v,ar as j,ae as N,c5 as u,ak as w,ap as y,aN as C,ew as P,ex as k}from"./index-zO3nSPIa.js";import{P as E}from"./PageHeader-BBOBaEku.js";import{c as S}from"./index-A7ElDbZk.js";function R(){const p=b(),[i,h]=r.useState(""),[d,l]=r.useState(null),[c,m]=r.useState(""),t=f({queryKey:["clients-for-portal-preview"],queryFn:async()=>({items:await k()}),staleTime:6e4,retry:!1}),o=r.useMemo(()=>{var a;return((a=t.data)==null?void 0:a.items)||[]},[t.data]),x=r.useMemo(()=>{const a=i.trim().toLowerCase();return a?o.filter(s=>[s.entity_name||s.name,s.email,s.entity_document||s.document,s.phone].filter(Boolean).some(n=>String(n).toLowerCase().includes(a))):o},[o,i]),g=async a=>{m(""),l(a.id);try{const s=await P(a.id),n=`${S("PortalCliente")}?preview_client_id=${encodeURIComponent(a.id)}&grant_id=${encodeURIComponent(s.grant_id)}`;p(n)}catch{m("Não foi possÃvel criar a autorização temporária de visualização deste cliente.")}finally{l(null)}};return e.jsxs("div",{className:"w-full space-y-4 sm:space-y-5",children:[e.jsx(E,{title:"Ver como cliente",description:"Abra a experiência real do Portal do Cliente para revisar jornada, conteúdo e atendimento.",breadcrumbs:[{label:"Conta"},{label:"Ver como cliente"}]}),e.jsxs("section",{className:"hm-surface overflow-hidden",children:[e.jsx("div",{className:"border-b border-border bg-card p-4 sm:p-5",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"flex h-11 w-11 shrink-0 items-center justify-center rounded-2xl bg-primary text-white",children:e.jsx(v,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"hm-kicker",children:"Experiência do cliente"}),e.jsx("h2",{className:"hm-display mt-1 text-lg font-semibold text-foreground sm:text-xl",children:"Entre na jornada antes do cliente"}),e.jsx("p",{className:"mt-1 max-w-2xl text-xs leading-relaxed text-muted-foreground sm:text-sm",children:"A visualização respeita as permissões do portal e registra auditoria. Use-a para conferir dados, navegação mobile e o widget de atendimento."})]})]})}),e.jsxs("div",{className:"p-3 sm:p-4",children:[e.jsxs("div",{className:"relative mb-3",children:[e.jsx(j,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(N,{value:i,onChange:a=>h(a.target.value),placeholder:"Buscar cliente por nome, e-mail, documento ou telefone",className:"h-11 pl-9"})]}),t.isError&&e.jsxs("div",{className:"mb-3 rounded-2xl border border-amber-200 bg-amber-50 p-4 text-xs text-amber-900",children:[e.jsx("p",{className:"font-semibold",children:"Não foi possÃvel carregar os clientes deste escritório"}),e.jsx("p",{className:"mt-1",children:"A visualização administrativa usa exclusivamente a autoridade Base44 e exige uma sessão interna válida."})]}),c&&e.jsx("div",{className:"mb-3 rounded-xl border border-red-200 bg-red-50 p-3 text-xs text-red-700",children:c}),t.isLoading?e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 xl:grid-cols-3",children:[1,2,3,4,5,6].map(a=>e.jsx("div",{className:"h-24 animate-pulse rounded-2xl bg-muted"},a))}):x.length===0?e.jsxs("div",{className:"rounded-2xl border border-dashed border-border bg-muted p-8 text-center",children:[e.jsx(u,{className:"mx-auto mb-2 h-7 w-7 text-primary"}),e.jsx("p",{className:"text-sm font-medium",children:"Nenhum cliente encontrado"})]}):e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 xl:grid-cols-3",children:x.map(a=>e.jsxs("button",{onClick:()=>g(a),disabled:d===a.id,className:"group flex min-h-24 w-full items-center gap-3 rounded-2xl border border-border bg-card p-3 text-left transition hover:border-border disabled:opacity-60 sm:p-4",children:[e.jsx("div",{className:"flex h-11 w-11 shrink-0 items-center justify-center rounded-2xl bg-accent text-primary",children:e.jsx(u,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-sm font-semibold text-foreground",children:a.entity_name||a.name||"Cliente"}),e.jsx("p",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:a.email||a.phone||"Portal disponÃvel"}),e.jsxs("span",{className:"mt-2 inline-flex items-center gap-1 text-[10px] font-medium text-primary",children:[d===a.id?e.jsx(w,{className:"h-3 w-3 animate-spin"}):e.jsx(y,{className:"h-3 w-3"})," visualização auditada"]})]}),e.jsx(C,{className:"h-4 w-4 shrink-0 text-muted-foreground transition group-hover:translate-x-0.5 group-hover:text-primary"})]},a.id))})]})]})]})}export{R as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.