PageSourceSearch

https://comprarseguidoresbr.com/assets/AdminPackages-BhAbCuhD.js

js comprarseguidoresbr.com collected 2026-10-04 08:38:04 UTC 16,363 bytes, 1 lines download raw bytes

1import{r as c,y as e,b7 as R,bJ as F,af as L,di as T,dj as U,cJ as W,bw as J,as as K,X as B,cV as O,ad as H,ae as G,ai as V,Q as d}from"./vendor-tKhk6VPq.js";import{_ as X,s as N,p as Y,B as b,a2 as Z,I as x,a4 as ee,a5 as se,a6 as re,a7 as te,aJ as j,aK as I}from"./index-BCMOZxNK.js";import{A as ae}from"./AdminContent-TLq4lof8.js";import{a as ne}from"./use-admin-page-BKeXdPn9.js";import{L as p}from"./label-bRX_cOTt.js";import{j as u}from"./admin-layout-classes-JC3WZwlh.js";import"./vendor-charts-CgjVniCl.js";function Q(o){const l=o??"";return l.startsWith("seguidores")?e.jsx(L,{className:"h-4 w-4"}):l.startsWith("curtidas")?e.jsx(H,{className:"h-4 w-4"}):l.startsWith("views")?e.jsx(G,{className:"h-4 w-4"}):e.jsx(V,{className:"h-4 w-4"})}const ie=o=>new Intl.NumberFormat("pt-BR",{style:"currency",currency:"BRL"}).format(o/100),he=()=>{const{adminWorkspaceId:o,ready:l,scopeQuery:$}=X(),[y,v]=c.useState([]),[q,E]=c.useState(!0),[A,M]=c.useState([]),[h,m]=c.useState(null),[k,_]=c.useState(!1),g=c.useCallback(async()=>{if(!l)return;E(!0);let s=N.from("service_packages").select("id, name, description, price_cents, is_active, created_at").order("created_at",{ascending:!1});s=$(s);let r=N.from("provider_services").select("provider_service_id, name, slot_key").eq("is_active",!0).order("sort_order").order("provider_service_id");r=$(r);const[{data:t},{data:i}]=await Promise.all([s,r]);v(t??[]),M(i??[]),E(!1)},[l,$]);ne({title:"Pacotes Especiais",onRefresh:g,loading:q}),c.useEffect(()=>{document.title=Y("Admin · Pacotes Especiais")},[]),c.useEffect(()=>{l&&g()},[l,o,g]);const D=async s=>{const[{data:r},{data:t}]=await Promise.all([N.from("service_package_items").select("id, provider_service_id, service_name, slot_key, quantity, min_per_use, max_posts").eq("package_id",s),N.from("service_package_access").select("user_id").eq("package_id",s)]);v(i=>i.map(a=>a.id===s?{...a,items:r??[],access_count:t?.length??0}:a))},C=async s=>{if(h===s){m(null);return}m(s),y.find(t=>t.id===s)?.items||await D(s)},P=async s=>{const{error:r}=await N.from("service_packages").update({is_active:!s.is_active}).eq("id",s.id);if(r){d.error(r.message);return}v(t=>t.map(i=>i.id===s.id?{...i,is_active:!i.is_active}:i))},n=async s=>{if(!confirm("Excluir este pacote? Créditos já concedidos não serão afetados."))return;const{error:r}=await N.from("service_packages").delete().eq("id",s);if(r){d.error(r.message);return}v(t=>t.filter(i=>i.id!==s)),d.success("Pacote excluído.")};return e.jsxs(ae,{className:"space-y-4",children:[e.jsxs(b,{onClick:()=>_(!0),className:"w-full h-12 bg-brand text-white rounded-2xl font-black text-sm shadow-lg shadow-brand/20",children:[e.jsx(R,{className:"h-4 w-4 mr-2"})," Criar Novo Pacote"]}),q&&y.length===0?e.jsx("div",{className:"space-y-3",children:[1,2,3].map(s=>e.jsx("div",{className:"h-24 bg-card rounded-2xl animate-pulse"},s))}):y.length===0?e.jsxs("div",{className:"text-center py-16",children:[e.jsx(F,{className:"h-12 w-12 text-muted-foreground/60 mx-auto mb-3"}),e.jsx("p",{className:"text-muted-foreground font-bold",children:"Nenhum pacote criado"}),e.jsx("p",{className:"text-muted-foreground/70 text-sm mt-1",children:"Crie pacotes especiais e atribua a clientes selecionados."})]}):e.jsx("div",{className:"space-y-3",children:y.map(s=>e.jsxs(Z,{className:"bg-card border-border rounded-2xl overflow-hidden",children:[e.jsx("div",{className:"p-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:`h-2 w-2 rounded-full shrink-0 ${s.is_active?"bg-green-400":"bg-muted-foreground/40"}`}),e.jsx("span",{className:"font-black text-foreground text-[15px] truncate",children:s.name})]}),s.description&&e.jsx("p",{className:"text-[11px] text-muted-foreground truncate mb-2",children:s.description}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-[13px] font-black text-brand",children:s.price_cents===0?"Gratuito":ie(s.price_cents)}),s.access_count!==void 0&&e.jsxs("span",{className:"text-[10px] text-muted-foreground flex items-center gap-1",children:[e.jsx(L,{className:"h-3 w-3"}),s.access_count," cliente",s.access_count!==1?"s":""]})]})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx(b,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-foreground hover:bg-muted rounded-xl",onClick:()=>P(s),children:s.is_active?e.jsx(T,{className:"h-4 w-4 text-green-600 dark:text-green-400"}):e.jsx(U,{className:"h-4 w-4"})}),e.jsx(b,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-red-400 hover:bg-red-500/10 rounded-xl",onClick:()=>n(s.id),children:e.jsx(W,{className:"h-3.5 w-3.5"})}),e.jsx(b,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-foreground hover:bg-muted rounded-xl",onClick:()=>C(s.id),children:h===s.id?e.jsx(J,{className:"h-4 w-4"}):e.jsx(K,{className:"h-4 w-4"})})]})]})}),h===s.id&&e.jsx(oe,{pkg:s,providerServices:A,onSaved:()=>{D(s.id),g()}})]},s.id))}),k&&e.jsx(ce,{providerServices:A,workspaceId:o??null,onClose:()=>_(!1),onCreated:()=>{_(!1),g()}})]})};function oe({pkg:o,providerServices:l,onSaved:$}){const[y,v]=c.useState(o.name),[q,E]=c.useState(o.description??""),[A,M]=c.useState((o.price_cents/100).toFixed(2).replace(".",",")),[h,m]=c.useState(o.items??[]),[k,_]=c.useState(!1);c.useEffect(()=>{o.items!==void 0&&m(o.items)},[o.items]);const g=()=>{const n=l[0];n&&m(s=>[...s,{provider_service_id:n.provider_service_id,service_name:n.name,slot_key:n.slot_key,quantity:1e3,min_per_use:j(n.slot_key,I(n.slot_key)),max_posts:null}])},D=n=>m(s=>s.filter((r,t)=>t!==n)),C=(n,s,r)=>
1{m(t=>t.map((i,a)=>{if(a!==n)return i;if(s==="provider_service_id"){const w=l.find(f=>f.provider_service_id===Number(r)),S=w?.slot_key??null;return{...i,provider_service_id:Number(r),service_name:w?.name??"",slot_key:S,min_per_use:j(S,I(S))}}return s==="min_per_use"?{...i,min_per_use:j(i.slot_key,Number(r))}:{...i,[s]:r}}))},P=async()=>{for(const r of h){const t=Number(r.quantity),i=j(r.slot_key,Number(r.min_per_use)),a=r.max_posts?Number(r.max_posts):null;if(t<100){d.error(`Quantidade total deve ser no mínimo 100 (${r.service_name}).`);return}if(i<100){d.error(`Mínimo por uso deve ser no mínimo 100 (${r.service_name}).`);return}if(a&&a>1&&Math.floor(t/a)<100){d.error(`${t} unidades em ${a} posts daria ${Math.floor(t/a)}/post — mínimo 100 por post (${r.service_name}).`);return}}_(!0);const n=Math.round(parseFloat(A.replace(",","."))*100)||0,{error:s}=await N.from("service_packages").update({name:y,description:q||null,price_cents:n}).eq("id",o.id);if(s){d.error(s.message),_(!1);return}if(await N.from("service_package_items").delete().eq("package_id",o.id),h.length>0){const{error:r}=await N.from("service_package_items").insert(h.map(t=>({package_id:o.id,provider_service_id:t.provider_service_id,service_name:t.service_name,slot_key:t.slot_key,quantity:Number(t.quantity),min_per_use:j(t.slot_key,Number(t.min_per_use)),max_posts:t.max_posts?Number(t.max_posts):null})));if(r){d.error(r.message),_(!1);return}}d.success("Pacote salvo!"),_(!1),$()};return e.jsxs("div",{className:"border-t border-border p-4 space-y-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(p,{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:"Nome"}),e.jsx(x,{value:y,onChange:n=>v(n.target.value),className:`mt-1 text-sm rounded-xl h-9 ${u}`})]}),e.jsxs("div",{children:[e.jsx(p,{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:"Preço (R$)"}),e.jsx(x,{value:A,onChange:n=>M(n.target.value),className:`mt-1 text-sm rounded-xl h-9 ${u}`,placeholder:"0,00"})]})]}),e.jsxs("div",{children:[e.jsx(p,{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:"Descrição"}),e.jsx(x,{value:q,onChange:n=>E(n.target.value),className:`mt-1 text-sm rounded-xl h-9 ${u}`,placeholder:"Opcional"})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-[10px] font-black text-muted-foreground uppercase tracking-wider",children:"Serviços incluídos"}),e.jsxs(b,{size:"sm",variant:"ghost",className:"h-7 px-2 text-brand text-[11px] font-black hover:bg-brand/10 rounded-lg",onClick:g,children:[e.jsx(R,{className:"h-3 w-3 mr-1"})," Adicionar"]})]}),e.jsxs("div",{className:"space-y-2",children:[h.map((n,s)=>e.jsxs("div",{className:"bg-muted/40 border border-border rounded-xl p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"text-muted-foreground",children:Q(n.slot_key)}),e.jsx("select",{value:n.provider_service_id,onChange:r=>C(s,"provider_service_id",Number(r.target.value)),className:`flex-1 border text-[11px] rounded-lg px-2 py-1.5 min-w-0 ${u}`,children:l.map(r=>e.jsx("option",{value:r.provider_service_id,children:r.name},r.provider_service_id))}),e.jsx(b,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground/70 hover:text-red-400 hover:bg-red-500/10 rounded-lg shrink-0",onClick:()=>D(s),children:e.jsx(B,{className:"h-3 w-3"})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{children:[e.jsx(p,{className:"text-[9px] text-muted-foreground/70 uppercase",children:"Qtd. total"}),e.jsx(x,{type:"number",value:n.quantity,onChange:r=>C(s,"quantity",Number(r.target.value)),className:`mt-0.5 h-8 text-xs rounded-lg ${u}`})]}),e.jsxs("div",{children:[e.jsx(p,{className:"text-[9px] text-muted-foreground/70 uppercase",children:"Mín. por uso"}),e.jsx(x,{type:"number",value:n.min_per_use,onChange:r=>C(s,"min_per_use",Number(r.target.value)),className:`mt-0.5 h-8 text-xs rounded-lg ${u}`,disabled:n.slot_key==="views_reels"})]}),e.jsxs("div",{children:[e.jsx(p,{className:"text-[9px] text-muted-foreground
1/70 uppercase",children:"Máx. posts"}),e.jsx(x,{type:"number",placeholder:"∞",value:n.max_posts??"",onChange:r=>C(s,"max_posts",r.target.value===""?null:Number(r.target.value)),className:`mt-0.5 h-8 text-xs rounded-lg ${u}`})]})]})]},s)),h.length===0&&e.jsx("p",{className:"text-[11px] text-muted-foreground/70 text-center py-3",children:"Nenhum serviço. Clique em Adicionar."})]})]}),e.jsxs(b,{onClick:P,disabled:k,className:"w-full h-10 bg-brand text-white rounded-xl font-black text-sm",children:[e.jsx(O,{className:"h-4 w-4 mr-2"}),k?"Salvando…":"Salvar Pacote"]})]})}function ce({providerServices:o,workspaceId:l,onClose:$,onCreated:y}){const[v,q]=c.useState(""),[E,A]=c.useState(""),[M,h]=c.useState("0,00"),[m,k]=c.useState([]),[_,g]=c.useState(!1),D=()=>{const s=o[0];s&&k(r=>[...r,{provider_service_id:s.provider_service_id,service_name:s.name,slot_key:s.slot_key,quantity:1e3,min_per_use:j(s.slot_key,I(s.slot_key)),max_posts:null}])},C=s=>k(r=>r.filter((t,i)=>i!==s)),P=(s,r,t)=>{k(i=>i.map((a,w)=>{if(w!==s)return a;if(r==="provider_service_id"){const S=o.find(z=>z.provider_service_id===Number(t)),f=S?.slot_key??null;return{...a,provider_service_id:Number(t),service_name:S?.name??"",slot_key:f,min_per_use:j(f,I(f))}}return r==="min_per_use"?{...a,min_per_use:j(a.slot_key,Number(t))}:{...a,[r]:t}}))},n=async()=>{if(!v.trim()){d.error("Nome obrigatório.");return}if(m.length===0){d.error("Adicione pelo menos 1 serviço.");return}for(const a of m){const w=Number(a.quantity),S=j(a.slot_key,Number(a.min_per_use)),f=a.max_posts?Number(a.max_posts):null;if(w<100){d.error(`Quantidade total deve ser no mínimo 100 (${a.service_name}).`);return}if(S<100){d.error(`Mínimo por uso deve ser no mínimo 100 (${a.service_name}).`);return}if(f&&f>1&&Math.floor(w/f)<100){d.error(`${w} unidades em ${f} posts daria ${Math.floor(w/f)}/post — mínimo 100 por post (${a.service_name}).`);return}}g(!0);const s=Math.round(parseFloat(M.replace(",","."))*100)||0,{data:r,error:t}=await N.from("service_packages").insert({name:v.trim(),description:E.trim()||null,price_cents:s,is_active:!0,workspace_id:l}).select("id").single();if(t||!r){d.error(t?.message??"Erro ao criar."),g(!1);return}const{error:i}=await N.from("service_package_items").insert(m.map(a=>({package_id:r.id,provider_service_id:a.provider_service_id,service_name:a.service_name,slot_key:a.slot_key,quantity:Number(a.quantity),min_per_use:j(a.slot_key,Number(a.min_per_use)),max_posts:a.max_posts?Number(a.max_posts):null})));if(i){d.error(i.message),g(!1);return}d.success("Pacote criado! Agora atribua clientes em Clientes > perfil do cliente."),y()};return e.jsx(ee,{open:!0,onOpenChange:s=>!s&&$(),children:e.jsxs(se,{className:"sm:max-w-md p-6 bg-card border-none rounded-[32px] shadow-2xl space-y-4 max-h-[90vh] overflow-y-auto",children:[e.jsx(re,{className:"flex flex-row items-center justify-between mb-1 space-y-0",children:e.jsx(te,{className:"text-[16px] font-black text-foreground",children:"Novo Pacote Especial"})}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(p,{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:"Nome *"}),e.jsx(x,{value:v,onChange:s=>q(s.target.value),placeholder:"Pacote Creator Pro",className:`mt-1 text-sm rounded-xl h-9 ${u}`})]}),e.jsxs("div",{children:[e.jsx(p,{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:"Preço (R$)"}),e.jsx(x,{value:M,onChange:s=>h(s.target.value),className:`mt-1 text-sm rounded-xl h-9 ${u}`,placeholder:"0,00"})]})]}),e.jsxs("div",{children:[e.jsx(p,{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:"Descrição"}),e.jsx(x,{value:E,onChange:s=>A(s.target.value),className:`mt-1 text-sm rounded-xl h-9 ${u}`,placeholder:"Opcional"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-[10px] font-black text-muted-foreground uppercase tracking-wider",children:"Serviços incluídos"}),e.jsxs(b,{size:"sm",variant:"ghost",className:"h-7 px-2 text-brand text-[11px] font-black hover:bg-brand/10 rounded-lg",onClick:D,children:[e.jsx(R,{className:"h-3 w-3 mr-1"})," Adicionar"]})]}),e.jsxs("div",{className:"space-y-2",children:[m.map((s,r)=>e.jsxs("div",{className:"bg-muted/40 border border-border rounded-xl p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"text-muted-foreground",children:Q(s.slot_key)}),e.jsx("select",{value:s.provider_service_id,onChange:t=>P(r,"provider_service_id",Number(t.target.value)),className:`flex-1 border text-[11px] rounded-lg px-2 py-1.5 min-w-0 ${u}`,children:o.map(t=>e.jsx("option",{value:t.provider_service_id,children:t.name},t.provider_service_id))}),e.jsx(b,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground
1/70 hover:text-red-400 hover:bg-red-500/10 rounded-lg shrink-0",onClick:()=>C(r),children:e.jsx(B,{className:"h-3 w-3"})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{children:[e.jsx(p,{className:"text-[9px] text-muted-foreground/70 uppercase",children:"Qtd. total"}),e.jsx(x,{type:"number",value:s.quantity,onChange:t=>P(r,"quantity",Number(t.target.value)),className:`mt-0.5 h-8 text-xs rounded-lg ${u}`})]}),e.jsxs("div",{children:[e.jsx(p,{className:"text-[9px] text-muted-foreground/70 uppercase",children:"Mín. por uso"}),e.jsx(x,{type:"number",value:s.min_per_use,onChange:t=>P(r,"min_per_use",Number(t.target.value)),className:`mt-0.5 h-8 text-xs rounded-lg ${u}`,disabled:s.slot_key==="views_reels"})]}),e.jsxs("div",{children:[e.jsx(p,{className:"text-[9px] text-muted-foreground/70 uppercase",children:"Máx. posts"}),e.jsx(x,{type:"number",placeholder:"∞",value:s.max_posts??"",onChange:t=>P(r,"max_posts",t.target.value===""?null:Number(t.target.value)),className:`mt-0.5 h-8 text-xs rounded-lg ${u}`})]})]})]},r)),m.length===0&&e.jsx("p",{className:"text-[11px] text-muted-foreground/70 text-center py-3",children:"Adicione pelo menos 1 serviço ao pacote."})]})]}),e.jsx(b,{onClick:n,disabled:_||!v.trim()||m.length===0,className:"w-full h-12 bg-brand text-white rounded-2xl font-black text-sm",children:_?"Criando…":"Criar Pacote"})]})})}export{he 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.