1import{r as d,aY as c,F as e}from"./vendor-DcslW3r7.js";import{aN as Q,a6 as X,a5 as Z,ay as ee,I as ae}from"./icons-QrNumo1x.js";import{A as se}from"./AdminPanelSectionNav-IIxitCRF.js";import{A as re,a as x,S as j}from"./AuthenticatedHeader-i3AcHxFX.js";import{z as h,au as u,C as p,$ as f,a0 as y,av as b,a as K,B as N,a1 as w,aG as te}from"./index-B3mtz8tC.js";import{I as z}from"./input-CJWR-Bv0.js";import{L as C}from"./label-Eqn2xENe.js";import{m as oe}from"./motion-gwsoIjby.js";import"./dialog-BoBLshY4.js";import"./radix-Db5gH_GL.js";import"./password-6psNL3Sx.js";import"./PixQrDialog-B8qxzDAK.js";async function F(s,o){const r=await s.json().catch(()=>null);return(r==null?void 0:r.error)??o}async function ie(){const s=await h("/admin/plans/availability");if(s.status===403)throw new u;if(!s.ok)throw new Error(await F(s,"Não foi possÃvel carregar a disponibilidade dos planos."));return s.json()}async function ne(s,o){const r=await h(`/admin/plans/availability/${encodeURIComponent(s)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});if(r.status===403)throw new u;if(!r.ok)throw new Error(await F(r,"Não foi possÃvel salvar a disponibilidade do plano."));return r.json()}async function O(s,o){const r=await s.json().catch(()=>null);return(r==null?void 0:r.error)??o}async function de(){const s=await h("/admin/placement-config");if(s.status===403)throw new u;if(!s.ok)throw new Error(await O(s,"Não foi possÃvel carregar a config de alocação."));return s.json()}async function ce(s){const o=await h("/admin/placement-config",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(o.status===403)throw new u;if(!o.ok)throw new Error(await O(o,"Não foi possÃvel salvar a config de alocação."));return o.json()}async function le(s,o){const r=await h("/admin/subscriptions/os",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({clientId:s,osType:o})});if(r.status===403)throw new u;if(!r.ok)throw new Error(await O(r,"Não foi possÃvel alterar o sistema operacional da conta."))}const me=s=>s?new Date(s).toLocaleString("pt-BR",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit"}):"â";function B(s){return s.active?s.soldOut?"Esgotado":"DisponÃvel":"Oculto"}function ue(s){return s.active?s.soldOut?"destructive":"default":"secondary"}function Ae({userName:s,onLogout:o,onNavigateToComputer:r,onNavigateToShop:T,onNavigateToHistory:G,onNavigateToSupport:W,onNavigateToDownload:q}
1){const[V,E]=d.useState([]),[P,S]=d.useState(!0),[J,_]=d.useState(!1),[k,M]=d.useState(null),[n,l]=d.useState(null),[m,I]=d.useState(!1),[g,D]=d.useState(""),[v,L]=d.useState(!1),A=d.useCallback(async()=>{S(!0);try{const a=await ie();E(a);try{l(await de())}catch{}}catch(a){if(a instanceof u){_(!0);return}c.error(a instanceof Error?a.message:"Erro ao carregar disponibilidade dos planos.")}finally{S(!1)}},[]);d.useEffect(()=>{A()},[A]);const R=async(a,i)=>{M(a.productKey);try{const t=await ne(a.productKey,i);E(Y=>Y.map(U=>U.productKey===t.productKey?t:U)),t.productKey==="WEEKLY_PASS_START"&&te(null),c.success(`${t.displayName} atualizado: ${B(t).toLowerCase()}.`)}catch(t){c.error(t instanceof Error?t.message:"Erro ao salvar disponibilidade do plano.")}finally{M(null)}},H=async a=>{I(!0);try{l(await ce(a)),c.success("Configuração de alocação salva.")}catch(i){c.error(i instanceof Error?i.message:"Erro ao salvar a configuração de alocação.")}finally{I(!1)}},$=async a=>{const i=g.trim();if(!i){c.error("Informe o Client ID da conta.");return}if(window.confirm(`Definir SO=${a} para a conta ${i}? Isso FORMATA o disco do cliente (apaga dados).`)){L(!0);try{await le(i,a),c.success(`Conta ${i} definida para ${a}.`),D("")}catch(t){c.error(t instanceof Error?t.message:"Erro ao alterar o SO da conta.")}finally{L(!1)}}};return e.jsxs("div",{className:"min-h-screen bg-background text-foreground",children:[e.jsx(re,{active:"admin",userName:s,onLogout:o,onNavigateToComputer:r,onNavigateToShop:T,onNavigateToHistory:G,onNavigateToSupport:W,onNavigateToDownload:q}),e.jsxs("main",{className:"mx-auto flex w-full max-w-7xl flex-col gap-6 px-4 py-6 sm:px-6 lg:px-8",children:[e.jsx(se,{}),J?e.jsx(p,{className:"border-destructive/40",children:e.jsxs(f,{children:[e.jsx(y,{children:"Acesso restrito"}),e.jsx(b,{children:"Esta área só pode ser aberta por contas administrativas."})]})}):null,e.jsxs(oe.section,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.25},className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-end sm:justify-between",children:[e.jsxs("div",{children:[e.jsx(K,{variant:"secondary",className:"mb-3 rounded-full px-3 py-1",children:"Disponibilidade comercial"}),e.jsx("h1",{className:"text-3xl font-semibold tracking-tight",children:"Planos no site"}),e.jsx("p",{className:"mt-2 max-w-3xl text-sm text-muted-foreground sm:text-base",children:"Controle quais planos aparecem para venda e quais continuam visÃveis como esgotados. A API também bloqueia novos checkouts desses produtos."})]}),e.jsx(N,{type:"button",variant:"outline",onClick:()=>void A(),disabled:P||k!=null,children:"Atualizar"})]}),n?e.jsxs(p,{children:[e.jsxs(f,{children:[e.jsx(y,{className:"text-lg",children:"Alocação · Overcommit de CPU"}),e.jsx(b,{children:"Quando ligado, sobe VMs considerando apenas a RAM disponÃvel (ignora vCPU â o overcommit de CPU é feito no hypervisor). Ativador operacional, use quando necessário."})]}),e.jsxs(w,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3 rounded-lg border border-border/60 px-3 py-2",children:[e.jsx(x,{checked:n.standardOvercommitEnabled,disabled:m,onCheckedChange:a=>l({...n,standardOvercommitEnabled:a})}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[e.jsx("strong",{className:"text-foreground",children:"Planos padrão"})," (Light/Start/Prime/Elite) â alocar por RAM"]})]}),e.jsxs("div",{className:"flex items-center gap-3 rounded-lg border border-border/60 px-3 py-2",children:[e.jsx(x,{checked:n.ultraRenderOvercommitEnabled,disabled:m,onCheckedChange:a=>l({...n,ultraRenderOvercommitEnabled:a})}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[e.jsx("strong",{className:"text-foreground",children:"Ultra GPU"})," â alocar por RAM (co-locar mesmo com VMs rodando)"]})]}),e.jsxs("div",{className:"flex items-center gap-3 rounded-lg border border-border/60 px-3 py-2",children:[e.jsx(x,{checked:n.standardOvercommitDynamicMarginEnabled,disabled:m,onCheckedChange:a=>l({...n,standardOvercommitDynamicMarginEnabled:a})}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[e.jsx("strong",{className:"text-foreground",children:"Margem dinâmica"})," â reservar a RAM do maior plano aguardando na fila"]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{className:n.standardOvercommitDynamicMarginEnabled?"text-muted-foreground":void 0,children:"Margem de RAM livre (GB) â planos padrão"}),e.jsx(z,{type:"number",min:0,className:"max-w-[160px]",value:n.standardOvercommitMinFreeMemoryGb,disabled:m||n.standardOvercommitDynamicMarginEnabled,onChange:a=>l({...n,standardOvercommitMinFreeMemoryGb:Math.max(0,Number(a.target.value)||0)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n.standardOvercommitDynamicMarginEnabled?"Margem dinâmica ativa: a margem livre passa a ser a RAM do maior plano aguardando na fila (0 se a fila estiver vazia). O valor fixo é ignorado.":"RAM extra a manter livre no host ao alocar planos padrão em overcommit (0 = sem margem)."})]}),e.jsx(N,{onClick:()=>void H(n),disabled:m,children:m?"Salvandoâ¦":"Salvar alocação"})]})]}):null,e.jsxs(p,{children:[e.jsxs(f,{children:[e.jsx(y,{className:"text-lg",children:"Liberar Windows numa conta (Ultra GPU)"}),e.jsx(b,{children:"O Ultra GPU é Linux por padrão. Após validar o licenciamento com o cliente, libere o Windows informando o Client ID. â ï¸ A troca de SO formata o disco da conta (apaga dados) â use antes do 1º uso ou avisando o cliente."})]}),e.jsxs(w,{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{children:"Client ID"}),e.jsx(z,{className:"max-w-md",placeholder:"ex.: d763b3e2-3aa1-43f6-918e-8c3af276f360",value:g,disabled:v,onChange:a=>D(a.target.value)})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(N,{onClick:()=>void $("Windows"),disabled:v||!g.trim(),children:v?"Aplicandoâ¦":"Liberar Windows"}),e.jsx(N,{variant:"outline",onClick:()=>void $("Linux"),disabled:v||!g.trim(),children:"Voltar para Linux"})]})]})]}),P?e.jsx("div",{className:"grid gap-4 md:grid-cols-2 xl:grid-cols-3",children:Array.from({length:5}).map((a,i)=>e.jsxs(p,{children:[e.jsxs(f,{children:[e.jsx(j,{className:"h-5 w-36"}),e.jsx(j,{className:"h-4 w-52"})]}),e.jsxs(w,{className:"space-y-3",children:[e.jsx(j,{className:"h-10 w-full"}),e.jsx(j,{className:"h-10 w-full"})]})]},i))}):e.jsx("div",{className:"grid gap-4 md:grid-cols-2 xl:grid-cols-3",children:V.map(a=>{const i=k===a.productKey;return e.jsxs(p,{className:"flex h-full flex-col",children:[e.jsx(f,{className:"space-y-3",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs(y,{className:"flex items-center gap-2 text-lg",children:[e.jsx(Q,{size:18}),a.displayName]}),e.jsx(b,{children:a.productKey})]}),e.jsx(K,{variant:ue(a),children:B(a)})]})}),e.jsxs(w,{className:"flex flex-1 flex-col gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{children:"VisÃvel no site"}),e.jsxs("div",{className:"flex items-center gap-3 rounded-lg border border-border/60 px-3 py-2",children:[e.jsx(x,{checked:a.active,disabled:i,onCheckedChange:t=>void R(a,{active:t,soldOut:a.soldOut})}),a.active?e.jsx(X,{size:18,className:"text-primary"}):e.jsx(Z,{size:18,className:"text-muted-foreground"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:a.active?"Aparece nas telas de compra.":"Fica oculto das telas de compra."})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{children:"Marcar como esgotado"}),e.jsxs("div",{className:"flex items-center gap-3 rounded-lg border border-border/60 px-3 py-2",children:[e.jsx(x,{checked:a.soldOut,disabled:i,onCheckedChange:t=>void R(a,{active:a.active,soldOut:t})}),a.soldOut?e.jsx(ee,{size:18,className:"text-destructive"}):e.jsx(ae,{size:18,className:"text-primary"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:a.soldOut?"Aparece bloqueado como esgotado.":"Pode receber novos checkouts se estiver visÃvel."})]})]}),e.jsxs("p",{className:"mt-auto text-xs text-muted-foreground",children:["Ãltima atualização: ",me(a.updatedAt),a.updatedByClientId?` · actor ${a.updatedByClientId}`:""]})]})]},a.productKey)})})]})]})]})}export{Ae as AdminPlansPage};
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.