1import{a as I,u as f,b as h,j as e}from"./vendor-query-CmFN4-M1.js";import{r as T}from"./vendor-react-7PyNDetJ.js";import{av as j,aG as _,p as o,aD as L,aE as O,ab as N,aF as R,aM as b,aj as X,ak as z,al as B,am as K,an as M,ao as Q,ap as V,aq as H,ar as $,aA as n,r as y,v as C,x as w,y as S,z as m,I as c,b as l,c as x}from"./index-BZSaBQD0.js";import{S as W,a as G,b as J,c as U,d as Y,e as Z}from"./sheet-kCUyucS4.js";import{by as ee,S as se,bd as ae,L as D,br as re,X as te,u as ie,af as ne}from"./vendor-ui-DjI1iuvA.js";import"./vendor-supabase-BfoV2C50.js";const ce={plan_code:"",stripe_coupon_id_live:"",stripe_coupon_id_test:"",headline:"",subtitle:"",badge_text:"1º mês promocional",effective_first_price_cents:2990,interval_scope:"month",duration_months:1,is_active:!0,priority:0},E=d=>(d/100).toLocaleString("pt-BR",{style:"currency",currency:"BRL",minimumFractionDigits:2}),pe=()=>{const d=I(),[a,r]=T.useState(null),{data:g=[],isLoading:q}=f({staleTime:6e4,refetchOnWindowFocus:!1,queryKey:["admin-intro-offers"],queryFn:async()=>{const{data:s,error:t}=await l.from("intro_offers").select("*").order("priority",{ascending:!1}).order("created_at",{ascending:!1});if(t)throw t;return s??[]}}),{data:v=[]}=f({staleTime:6e4,refetchOnWindowFocus:!1,queryKey:["admin-intro-offers-plans"],queryFn:async()=>{const{data:s,error:t}=await l.from("subscription_plans").select("code, name").eq("is_active",!0).neq("code","free").neq("code","premium").order("display_order");if(t)throw t;return s??[]}}),p=h({mutationFn:async s=>{if(!s.plan_code)throw new Error("Selecione um plano");if(s.effective_first_price_cents<=0)throw new Error("Preço deve ser maior que zero");if(!s.stripe_coupon_id_live&&!s.stripe_coupon_id_test)throw new Error("Informe ao menos um coupon ID (test ou live)");const t={plan_code:s.plan_code,stripe_coupon_id_live:s.stripe_coupon_id_live||null,stripe_coupon_id_test:s.stripe_coupon_id_test||null,headline:s.headline||null,subtitle:s.subtitle||null,badge_text:s.badge_text||null,effective_first_price_cents:s.effective_first_price_cents,interval_scope:s.interval_scope,duration_months:s.duration_months,is_active:s.is_active,priority:s.priority};if(s.id){const{error:i}=await l.from("intro_offers").update(t).eq("id",s.id);if(i)throw i}else{const{error:i}=await l.from("intro_offers").insert(t);if(i)throw i}},onSuccess:()=>{x.success("Oferta salva com sucesso"),d.invalidateQueries({queryKey:["admin-intro-offers"]}),r(null)},onError:s=>x.error(s.message)}),k=h({mutationFn:async({id:s,is_active:t})=>{const{error:i}=await l.from("intro_offers").update({is_active:t}).eq("id",s);if(i)throw i},onSuccess:()=>d.invalidateQueries({queryKey:["admin-intro-offers"]}),onError:s=>x.error(s.message)}),A=h({mutationFn:async s=>{const{error:t}=await l.from("intro_offers").delete().eq("id",s);if(t)throw t},onSuccess:()=>{x.success("Oferta removida"),d.invalidateQueries({queryKey:["admin-intro-offers"]})},onError:s=>x.error(s.message)}),P=s=>{const{id:t,created_at:i,updated_at:u,...F}=s;r({...F,is_active:!1,priority:(s.priority??0)+1})};return e.jsxs("div",{className:"space-y-6",children:[e.jsx(j,{className:"border-amber-500/30 bg-amber-500/5",children:e.jsxs(_,{className:"flex items-start gap-3 pt-6",children:[e.jsx(ee,{className:"h-5 w-5 text-amber-600 shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-sm space-y-1",children:[e.jsx("p",{className:"font-medium",children:"Precedência aplicada no checkout"}),e.jsxs("p",{className:"text-muted-foreground",children:[e.jsx("strong",{children:"Promo de lançamento"})," (LANCAMENTO40) > ",e.jsx("strong",{children:"Intro Offer"})," > Preço cheio. Se a campanha de lançamento estiver ativa, as ofertas abaixo ficam pausadas automaticamente â nenhum cliente é cobrado duas vezes por descontos concorrentes."]})]})]})}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-2xl font-semibold flex items-center gap-2",children:[e.jsx(se,{className:"h-5 w-5 text-amber-500"}),"Ofertas do primeiro mês"]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Preço promocional para novos assinantes mensais. Cupons Stripe precisam existir com"," ",e.jsx("code",{className:"text-xs",children:"duration=repeating"})," e"," ",e.jsx("code",{className:"text-xs",children:"duration_in_months"})," compatÃveis."]})]}),e.jsxs(o,{onClick:()=>r({...ce}),className:"gap-2",children:[e.jsx(ae,{className:"h-4 w-4"})," Nova oferta"]})]}),q?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(D,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):g.length===0?e.jsx(j,{children:e.jsxs(_,{className:"py-12 text-center text-muted-foreground",children:["Nenhuma oferta cadastrada. Clique em ",e.jsx("strong",{children:"Nova oferta"})," para criar a primeira."]})}):e.jsx("div",{className:"grid gap-4",children:g.map(s=>{var i;const t=((i=v.find(u=>u.code===s.plan_code))==null?void 0:i.name)??s.plan_code;return e.jsxs(j,{className:s.is_active?"":"opacity-60",children:[e.jsx(L,{className:"pb-3",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs(O,{className:"text-lg flex items-center gap-2 flex-wrap",children:[t,e.jsx(N,{variant:"outline",className:"text-xs",children:s.plan_code}),s.badge_text&&e.jsx(N,{className:"bg-amber-500/15 text-amber-700 border-amber-500/30 text-xs",children:s.badge_text})]}),e.jsxs(R,{className:"mt-1",children:[s.headline??"â"," · ",s.subtitle??"sem subtÃtulo"]})]}),e.jsx("div",{className:"flex items-center gap-2 shrink-0",children:e.jsx(b,{checked:s.is_active,onCheckedChange:u=>k.mutate({id:s.id,is_active:u})})})]})}),e.jsxs(_,{className:"grid grid-cols-2 md:grid-cols-4 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"1º mês"}),e.jsx("p",{className:"text-2xl font-semibold text-amber-600",children:E(s.effective_first_price_cents)})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Duração"}),e.jsxs("p",{className:"font-medium",children:[s.duration_months," ",s.duration_months===1?"mês":"meses"]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Prioridade"}),e.jsx("p",{className:"font-medium",children:s.priority})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Coupon (live/test)"}),e.jsxs("p",{className:"font-mono text-xs truncate",children:[s.stripe_coupon_id_live??"â",e.jsx("br",{}),e.jsx("span",{className:"text-muted-foreground",children:s.stripe_coupon_id_test??"â"})]})]}),e.jsxs("div",{className:"col-span-2 md:col-span-4 flex flex-wrap items-center gap-2 pt-2 border-t",children:[e.jsxs(o,{size:"sm",variant:"outline",className:"gap-2",onClick:()=>r(s),children:[e.jsx(re,{className:"h-3.5 w-3.5"})," Editar"]}),e.jsxs(o,{size:"sm",variant:"outline",className:"gap-2",onClick:()=>P(s),children:[e.jsx(te,{className:"h-3.5 w-3.5"})," Duplicar"]}),e.jsxs(X,{children:[e.jsx(z,{asChild:!0,children:e.jsxs(o,{size:"sm",variant:"ghost",className:"gap-2 text-destructive",children:[e.jsx(ie,{className:"h-3.5 w-3.5"})," Excluir"]})}),e.jsxs(B,{children:[e.jsxs(K,{children:[e.jsx(M,{children:"Excluir oferta?"}),e.jsx(Q,{children:"Esta ação é irreversÃvel. Novos checkouts pararão de aplicar o cupom associado."})]}),e.jsxs(V,{children:[e.jsx(H,{children:"Cancelar"}),e.jsx($,{className:"bg-destructive text-destructive-foreground",onClick:()=>A.mutate(s.id),children:"Excluir"})]})]})]}),e.jsxs("a",{href:"https://dashboard.stripe.com/coupons",target:"_blank",rel:"noreferrer",className:"ml-auto text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1",children:["Ver cupons no Stripe ",e.jsx(ne,{className:"h-3 w-3"})]})]})]})]},s.id)})}),e.jsx(W,{open:a!==null,onOpenChange:s=>!s&&r(null),children:e.jsxs(G,{className:"sm:max-w-lg overflow-y-auto",children:[e.jsxs(J,{children:[e.jsx(U,{children:a!=null&&a.id?"Editar oferta":"Nova oferta do 1º mês"}),e.jsx(Y,{children:"O preço promocional é aplicado apenas ao primeiro ciclo (ou pela duração escolhida). A partir do próximo ciclo, o assinante paga o valor cheio do plano."})]}),a&&e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(n,{children:"Plano"}),e.jsxs(y,{value:a.plan_code,onValueChange:s=>r({...a,plan_code:s}),children:[e.jsx(C,{children:e.jsx(w,{placeholder:"Selecione um plano"})}),e.jsx(S,{children:v.map(s=>
1e.jsxs(m,{value:s.code,children:[s.name," (",s.code,")"]},s.code))})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(n,{children:"Preço do 1º mês (R$)"}),e.jsx(c,{type:"number",step:"0.01",min:"0.01",value:(a.effective_first_price_cents/100).toFixed(2),onChange:s=>r({...a,effective_first_price_cents:Math.round(parseFloat(s.target.value||"0")*100)})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(n,{children:"Duração (meses)"}),e.jsxs(y,{value:String(a.duration_months),onValueChange:s=>r({...a,duration_months:parseInt(s,10)}),children:[e.jsx(C,{children:e.jsx(w,{})}),e.jsxs(S,{children:[e.jsx(m,{value:"1",children:"1 mês"}),e.jsx(m,{value:"3",children:"3 meses"}),e.jsx(m,{value:"6",children:"6 meses"}),e.jsx(m,{value:"12",children:"12 meses"})]})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(n,{children:"Headline (destaque no card)"}),e.jsx(c,{value:a.headline??"",placeholder:"Ex.: Menos de R$ 1 por dia no primeiro mês",onChange:s=>r({...a,headline:s.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(n,{children:"SubtÃtulo"}),e.jsx(c,{value:a.subtitle??"",placeholder:"Ex.: depois R$ 169,90/mês · cancele quando quiser",onChange:s=>r({...a,subtitle:s.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(n,{children:"Badge"}),e.jsx(c,{value:a.badge_text??"",placeholder:"Ex.: 1º mês promocional",onChange:s=>r({...a,badge_text:s.target.value})})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(n,{children:"Coupon ID · TEST"}),e.jsx(c,{className:"font-mono text-xs",value:a.stripe_coupon_id_test??"",placeholder:"promo_XXX_test",onChange:s=>r({...a,stripe_coupon_id_test:s.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(n,{children:"Coupon ID · LIVE"}),e.jsx(c,{className:"font-mono text-xs",value:a.stripe_coupon_id_live??"",placeholder:"promo_XXX_live",onChange:s=>r({...a,stripe_coupon_id_live:s.target.value})})]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Crie primeiro no"," ",e.jsx("a",{href:"https://dashboard.stripe.com/coupons/create",target:"_blank",rel:"noreferrer",className:"underline",children:"Stripe Dashboard"})," ","com ",e.jsx("code",{children:"duration=repeating"}),", ",e.jsx("code",{children:"duration_in_months"})," igual à duração acima e desconto que resulte no preço final desejado."]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(n,{children:"Prioridade"}),e.jsx(c,{type:"number",value:a.priority,onChange:s=>r({...a,priority:parseInt(s.target.value||"0",10)})})]}),e.jsxs("div",{className:"flex items-end gap-2 pb-2",children:[e.jsx(b,{checked:a.is_active,onCheckedChange:s=>r({...a,is_active:s})}),e.jsx(n,{className:"cursor-pointer",children:"Ativa"})]})]}),e.jsxs("div",{className:"rounded-lg border bg-muted/30 p-4 space-y-1",children:[e.jsx("p",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"Preview"}),e.jsxs("p",{className:"text-3xl font-bold text-amber-600",children:[E(a.effective_first_price_cents),e.jsx("span",{className:"text-sm font-normal text-muted-foreground",children:"/1º mês"})]}),a.headline&&e.jsx("p",{className:"text-sm font-medium",children:a.headline}),a.subtitle&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a.subtitle})]})]}),e.jsxs(Z,{children:[e.jsx(o,{variant:"outline",onClick:()=>r(null),children:"Cancelar"}),e.jsxs(o,{onClick:()=>a&&p.mutate(a),disabled:p.isPending||!(a!=null&&a.plan_code),className:"gap-2",children:[p.isPending&&e.jsx(D,{className:"h-4 w-4 animate-spin"}),"Salvar oferta"]})]})]})})]})};export{pe as IntroOffersTab};
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.