1import{r as v,j as e}from"./react-vendor-pafHdoJx.js";import{E as C}from"./ErrorState-B9i6eo2M.js";import{a as A,u as S,j as M,b as D,d as u}from"./index-Db0fDLGN.js";import{L as d,ac as q,j as E,x as L,ap as N,X as P,aU as z,D as T}from"./ui-vendor-DLXJn6s3.js";import"./map-vendor-Dr8zbd0c.js";import"./firebase-vendor-D3UzkAhn.js";function V(){var f;const{role:b}=A(),{toast:r}=S(),{confirmar:y}=M(),{data:a,loading:h,error:n,refetch:c}=D(()=>u.orgModulesStore(),[]),[t,l]=v.useState(null),[i,o]=v.useState(null),x=b==="fleet_admin"||b==="super_admin",w=async s=>{l(s);try{await u.orgToggleModule(s,"ativar",!0),r({title:"Módulo ativado. As telas já aparecem no menu.",kind:"success"}),c()}catch(p){r({title:p.message||"Falha ao ativar",kind:"error"})}finally{l(null),o(null)}},k=async s=>{if(await y({titulo:"Desativar este módulo?",descricao:"Os dados são preservados. Ele só some do menu e para de cobrar.",confirmar:"Desativar",tom:"neutro"})){l(s);try{await u.orgToggleModule(s,"desativar",!1),r({title:"Módulo desativado.",kind:"success"}),c()}catch(p){r({title:p.message||"Falha ao desativar",kind:"error"})}finally{l(null)}}};if(h)return e.jsx("div",{className:"flex justify-center py-20",children:e.jsx(d,{className:"w-8 h-8 text-brand-500 animate-spin"})});const m=(a==null?void 0:a.itens)||[],j=m.filter(s=>!s.ativo),g=m.filter(s=>s.ativo);return e.jsxs("div",{className:"space-y-6",style:{color:"var(--page-text)"},children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-11 h-11 rounded-xl bg-brand-500/10 border border-brand-500/20 flex items-center justify-center",children:e.jsx(q,{className:"w-5 h-5 text-brand-400"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-bold",children:"Loja de módulos"}),e.jsx("p",{className:"text-sm text-slate-400",children:"Ative mais recursos da plataforma quando precisar â você paga só pelo que usar."})]})]}),(((f=a==null?void 0:a.base)==null?void 0:f.length)??0)>0&&e.jsxs("div",{className:"p-4 rounded-xl bg-emerald-500/5 border border-emerald-500/15",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(E,{className:"w-4 h-4 text-emerald-400"}),e.jsx("p",{className:"text-sm font-semibold text-emerald-300",children:"Sua base â já incluÃda"})]}),e.jsx("p",{className:"text-[11px] text-slate-400",children:"A fundação que conecta você ao ecossistema (rede, coletas, POD, rastreio). Grátis e sempre ligada."})]}),!x&&e.jsx("div",{className:"p-3 rounded-lg bg-amber-500/10 border border-amber-500/20 text-xs text-amber-300",children:"Só o administrador da organização pode ativar ou desativar módulos."}),j.length>0&&e.jsxs("section",{children:[e.jsx("p",{className:"text-xs font-semibold text-slate-400 uppercase tracking-wider mb-2",children:"DisponÃveis"}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:j.map(s=>e.jsxs("div",{className:"p-4 rounded-xl border border-slate-700/60 bg-slate-900/30 flex flex-col",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold text-slate-100",children:s.titulo}),e.jsx("p",{className:"text-[11px] text-slate-400 leading-snug",children:s.descricao})]}),s.status!=="ga"&&e.jsx("span",{className:"text-[9px] uppercase tracking-wider px-1.5 py-0.5 rounded bg-slate-800 text-slate-400 shrink-0",children:s.status})]}),e.jsxs("div",{className:"flex items-center justify-between mt-3 pt-3 border-t border-slate-800/60",children:[e.jsx("span",{className:"text-xs text-slate-300 tabular-nums",children:s.preco||"cobrança por uso"}),e.jsxs("button",{type:"button",disabled:!x||!!t,onClick:()=>o({id:s.id,titulo:s.titulo,preco:s.preco}),className:"px-3 py-1.5 rounded-lg bg-brand-600 hover:bg-brand-500 text-xs font-semibold flex items-center gap-1.5 disabled:opacity-50",children:[t===s.id?e.jsx(d,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(L,{className:"w-3.5 h-3.5"}),"Ativar"]})]})]},s.id))})]}),g.length>0&&e.jsxs("section",{children:[e.jsx("p",{className:"text-xs font-semibold text-slate-400 uppercase tracking-wider mb-2",children:"Ativos"}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:g.map(s=>e.jsxs("div",{className:"p-4 rounded-xl border border-emerald-500/25 bg-emerald-600/5 flex flex-col",children:[e.jsx("div",{className:"flex items-start justify-between gap-2",children:e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-sm font-semibold text-slate-100 flex items-center gap-1.5",children:[e.jsx(N,{className:"w-4 h-4 text-emerald-400"})," ",s.titulo]}),e.jsx("p",{className:"text-[11px] text-slate-400 leading-snug",children:s.descricao})]})}),e.jsxs("div",{className:"flex items-center justify-between mt-3 pt-3 border-t border-emerald-800/40",children:[e.jsx("span",{className:"text-xs text-slate-400 tabular-nums",children:s.preco||"cobrança por uso"}),e.jsxs("button",{type:"button",disabled:!x||!!t,onClick:()=>k(s.id),className:"px-3 py-1.5 rounded-lg border border-slate-700 text-xs text-slate-300 hover:bg-slate-800 flex items-center gap-1.5 disabled:opacity-50",children:[t===s.id?e.jsx(d,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(P,{className:"w-3.5 h-3.5"}),"Desativar"]})]})]},s.id))})]}),n&&!h&&e.jsx(C,{error:n,onRetry:c,title:"Não foi possÃvel carregar a loja"}),m.length===0&&!n&&e.jsxs("div",{className:"text-center py-16 text-slate-500",children:[e.jsx(z,{className:"w-8 h-8 mx-auto mb-3 opacity-50"}),e.jsx("p",{className:"text-sm",children:"Nenhum módulo adicional disponÃvel para o perfil desta organização."})]}),i&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4",onClick:()=>o(null),children:e.jsxs("div",{className:"w-full max-w-md rounded-2xl border border-slate-700 bg-slate-900 p-5",onClick:s=>s.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(T,{className:"w-5 h-5 text-brand-400"}),e.jsx("h3",{className:"text-base font-bold text-slate-100",children:"Confirmar ativação"})]}),e.jsxs("p",{className:"text-sm text-slate-300",children:["Ativar ",e.jsx("span",{className:"font-semibold text-white",children:i.titulo})," passa a cobrar conforme a régua ",e.jsx("span",{className:"text-brand-300",children:i.preco||"de uso"}),". As telas aparecem no menu imediatamente."]}),e.jsx("p",{className:"text-[11px] text-slate-500 mt-2",children:"A cobrança acompanha o uso real â módulo ativado sem uso não gera fatura por si. Você pode desativar quando quiser."}),e.jsxs("div",{className:"flex gap-3 mt-5",children:[e.jsx("button",{onClick:()=>o(null),className:"flex-1 px-4 py-2.5 rounded-xl border border-slate-700 text-sm text-slate-300 hover:bg-slate-800",children:"Cancelar"}),e.jsxs("button",{onClick:()=>w(i.id),disabled:!!t,className:"flex-1 px-4 py-2.5 rounded-xl bg-brand-600 hover:bg-brand-500 text-sm font-semibold flex items-center justify-center gap-2 disabled:opacity-50",children:[t?e.jsx(d,{className:"w-4 h-4 animate-spin"}):e.jsx(N,{className:"w-4 h-4"}),"Aceitar e ativar"]})]})]})})]})}export{V 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.