1import{c as M,bD as O,j as e,B as m,m as k,r as h,I as f,L as y,t as u,X as U}from"./index-d8YKBRE-.js";import{L as g}from"./label-FcuyrJwU.js";import{T as J}from"./textarea-Sszhhbr-.js";import{r as W,M as Q}from"./gateway-fees-BWI3bDrZ.js";import{P as X}from"./page-header-DMYP2HXm.js";import{S as R}from"./storage-image-Bkp_uav8.js";import{C as w,a as C,b as _,c as S,d as A}from"./card-BM0RAWy2.js";import{D as K,b as Y,c as Z,d as ee,e as ae}from"./dialog-CWnjK0jt.js";import{S as se,a as te,b as re,c as ie,d as N}from"./select-Dy6Hq3pW.js";import{u as oe}from"./use-recipe-groups-CuYBp-Aq.js";import{R as ne}from"./stars-CxaCTu2x.js";import{v as T,y as $,c as ce,f as q,h as de,z as L,A as le,B as ue,C as me,D as pe,t as V,E as D}from"./use-packs-Cxq4-g_0.js";import{A as F}from"./arrow-left-Dq3cL-9L.js";import{E as xe}from"./external-link-9iPtlQTU.js";import{T as z}from"./trash-2-CaMRPJT-.js";import{U as he}from"./upload-CGKPq7S8.js";import{P as ge}from"./plus-Do-T7Pev.js";import{A as je}from"./arrow-right-C0RQmSAg.js";import{R as ve}from"./rocket-Cs_y7ewb.js";import"./index-BdQq_4o_.js";import"./index-8kBW4vgf.js";import"./index-Cfw_GmBb.js";import"./index-Bn9Dqe3-.js";import"./chevron-down-CUm_0sAC.js";import"./check-BrzIxAWT.js";import"./recipe-kinds-maBFEEbc.js";import"./paperclip-CPsIJLiG.js";import"./flask-conical-hq9Tpu9C.js";import"./pill-7qEJGWG8.js";import"./star-hI1QFG7b.js";const fe=[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2",key:"usdka0"}]],E=M("folder-open",fe);const be=[["path",{d:"M16 5h6",key:"1vod17"}],["path",{d:"M19 2v6",key:"4bpg5p"}],["path",{d:"M21 11.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7.5",key:"1ue2ih"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}]],Ne=M("image-plus",be);function ta(){const{packId:a}=O.useParams(),{data:r=[],isLoading:o}=T(),n=r.find(t=>t.pack_id===a);return o?e.jsx("div",{className:"mx-auto w-full max-w-3xl px-4 sm:px-6 py-8",children:e.jsx("div",{className:"h-64 rounded-xl border bg-card animate-pulse"})}):n?e.jsx(ke,{sale:n}):e.jsxs("div",{className:"mx-auto w-full max-w-3xl px-4 sm:px-6 py-16 text-center space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Este pack não é seu, ou não existe mais."}),e.jsx(m,{variant:"outline",asChild:!0,children:e.jsxs(k,{to:"/receitas/vendas",children:[e.jsx(F,{className:"h-4 w-4"})," Voltar"]})})]})}function ke({sale:a}){const r=$(),{data:o}=ce(),n=o?.fee_bps??2e3,[t,p]=h.useState(a.title),[c,x]=h.useState(a.tagline??""),[i,d]=h.useState(a.description??""),[s,j]=h.useState(a.category??""),[v,H]=h.useState((a.price_cents/100).toFixed(2).replace(".",",")),[I,B]=h.useState(a.status),b=Math.max(0,Math.round(Number(v.replace(/\./g,"").replace(",","."))*100)||0),G=()=>r.mutate({id:a.pack_id,title:t.trim(),tagline:c.trim()||null,description:i.trim()||null,category:s.trim()||null,price_cents:b,status:I},{onSuccess:()=>u.success("Pack atualizado"),onError:l=>u.error(l.message)});return e.jsxs("div",{className:"mx-auto w-full max-w-3xl px-4 sm:px-6 py-6 md:py-8 space-y-6",children:[e.jsx(m,{variant:"ghost",size:"sm",asChild:!0,className:"-ml-2",children:e.jsxs(k,{to:"/receitas/vendas",children:[e.jsx(F,{className:"h-4 w-4"})," Publicar e vender"]})}),e.jsx(X,{title:a.title,description:"O que a vitrine mostra, o que o pack entrega e quando isso vai ao ar.",actions:a.status==="published"?e.jsx(m,{variant:"outline",asChild:!0,children:e.jsxs(k,{to:"/loja/$slug",params:{slug:a.slug},children:[e.jsx(xe,{className:"h-4 w-4"})," Ver na loja"]})}):void 0}),a.latest_version>0&&e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsx(P,{label:"Instalações",value:String(a.installs)}),e.jsx(P,{label:"Recebido",value:q(Number(a.revenue_cents??0)),hint:a.installs?void 0:"Nenhuma venda ainda"}),e.jsx(P,{label:"Avaliação",value:a.rating_count?a.rating_avg?.toFixed(1).replace(".",",")??"â":"â",hint:a.rating_count?`${a.rating_count} avaliações`:"Sem avaliações"})]}),e.jsxs(w,{children:[e.jsxs(C,{children:[e.jsx(_,{children:"Vitrine"}),e.jsx(S,{children:"A capa e o texto são o que vendem o pack. Isto vale na hora â não espera versão nova."})]}),e.jsxs(A,{className:"space-y-4",children:[e.jsx(ye,{sale:a}),e.jsx(Pe,{packId:a.pack_id}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{htmlFor:"e-title",children:"Nome do pack"}),e.jsx(f,{id:"e-title",value:t,onChange:l=>p(l.target.value)})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{htmlFor:"e-tagline",children:"Chamada"}),e.jsx(f,{id:"e-tagline",value:c,onChange:l=>x(l.target.value),placeholder:"20 receitas de APS prontas para o PEC"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{htmlFor:"e-desc",children:"Descrição"}),e.jsx(J,{id:"e-desc",rows:5,value:i,onChange:l=>d(l.target.value),placeholder:"O que vem dentro, para quem serve, como você usa no dia a dia."})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{htmlFor:"e-cat",children:"Categoria"}),e.jsx(f,{id:"e-cat",value:s,onChange:l=>j(l.target.value),placeholder:"APS, Pediatriaâ¦"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{htmlFor:"e-price",children:"Preç
1o (R$)"}),e.jsx(f,{id:"e-price",inputMode:"decimal",value:v,onChange:l=>H(l.target.value)}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:b===0?"Grátis â qualquer pessoa instala.":`${de(b)} · você recebe ${q(W(b,n,Q[0].gatewayBps).autorCents)} no Pix, já sem as taxas.`})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{children:"Visibilidade"}),e.jsxs(se,{value:I,onValueChange:l=>B(l),children:[e.jsx(te,{children:e.jsx(re,{})}),e.jsxs(ie,{children:[e.jsx(N,{value:"draft",children:"Rascunho â só você vê"}),e.jsx(N,{value:"published",children:"Na loja â aparece na vitrine"}),e.jsx(N,{value:"unlisted",children:"Só por link â fora da vitrine"}),e.jsx(N,{value:"archived",children:"Arquivado â sem venda nova; quem já comprou continua com ele"})]})]})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(m,{disabled:r.isPending||!t.trim(),onClick:G,children:[r.isPending&&e.jsx(y,{className:"h-4 w-4 animate-spin"}),"Salvar"]})})]})]}),e.jsx(we,{sale:a}),e.jsx(Ce,{sale:a})]})}function ye({sale:a}){const r=L(),o=$(),n=r.isPending||o.isPending,t=async c=>{const x=c?.[0];if(!x)return;const i=a.cover_url;try{const d=await r.mutateAsync({packId:a.pack_id,file:x});await o.mutateAsync({id:a.pack_id,cover_url:d}),await D(i),u.success("Capa atualizada.")}catch(d){u.error(d.message)}},p=async()=>{try{await o.mutateAsync({id:a.pack_id,cover_url:null}),await D(a.cover_url),u.success("Capa removida.")}catch(c){u.error(c.message)}};return e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{children:"Capa da vitrine"}),e.jsxs("div",{className:"group relative aspect-[3/1] w-full overflow-hidden rounded-lg border-2 border-dashed bg-muted",children:[e.jsxs("label",{className:"absolute inset-0 cursor-pointer",children:[e.jsx("input",{type:"file",accept:"image/jpeg,image/png,image/webp",className:"hidden",onChange:c=>{t(c.target.files),c.target.value=""}}),a.cover_url?e.jsxs(e.Fragment,{children:[e.jsx(R,{src:a.cover_url,alt:"",className:"h-full w-full object-cover",style:{objectPosition:a.cover_position||"50% 50%"}}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/0 opacity-0 transition-all group-hover:bg-black/40 group-hover:opacity-100",children:e.jsx("span",{className:"text-xs font-semibold text-white",children:"Trocar capa"})})]}):e.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-1",children:[n?e.jsx(y,{className:"h-5 w-5 animate-spin text-muted-foreground"}):e.jsx(Ne,{className:"h-5 w-5 text-muted-foreground"}),e.jsx("span",{className:"text-[11px] text-muted-foreground",children:"Enviar capa"})]})]}),a.cover_url&&e.jsx(m,{type:"button",variant:"ghost",size:"icon",title:"Remover capa",disabled:n,onClick:p,className:"absolute right-2 top-2 h-8 w-8 bg-background/85 backdrop-blur hover:bg-destructive hover:text-destructive-foreground",children:e.jsx(z,{className:"h-4 w-4"})})]}),e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:["Deitada, 3:1 â é a tarja que aparece no diálogo do pack. Sem ela, entram as iniciais. Clique para trocar, ou use a lixeira para remover."," ",e.jsx("strong",{className:"font-medium",children:"Vale na hora"}),", sem passar pelo Salvar. JPG, PNG ou WebP, até 3 MB."]})]})}function Pe({packId:a}){const{data:r=[],isLoading:o}=le(a),{add:n,remove:t}=ue(a),p=L(),c=async i=>{const d=Array.from(i??[]);let s=r.length;for(const j of d)try{const v=await p.mutateAsync({packId:a,file:j});await n.mutateAsync({url:v,position:s}),s+=1}catch(v){u.error(`${j.name}: ${v.message}`)}d.length&&u.success(d.length===1?"Imagem adicionada":"Imagens adicionadas")},x=p.isPending||n.isPending;return e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{children:"Imagens"}),o?e.jsx("div",{className:"h-40 rounded-lg border bg-muted animate-pulse"}):e.jsxs("div",{className:"grid grid-cols-3 gap-2 sm:grid-cols-4",children:[r.map((i,d)=>e.jsxs("div",{className:"relative aspect-[9/16] rounded-lg border overflow-hidden bg-muted group",children:[e.jsx(R,{src:i.url,alt:"",className:"h-full w-full object-cover"}),e.jsx("div",{className:"absolute inset-x-0 bottom-0 flex justify-end gap-0.5 bg-gradient-to-t from-black/70 to-transparent p-1",children:e.jsx(m,{variant:"ghost",size:"icon",className:"h-7 w-7 text-white hover:bg-white/20",title:"Remover",disabled:t.isPending,onClick:()=>t.mutate({id:i.id,url:i.url}),children:e.jsx(z,{className:"h-3.5 w-3.5"})})})]},i.id)),e.jsxs("label",{className:"aspect-[9/16] rounded-lg border-2 border-dashed flex flex-col items-center justify-center gap-1 cursor-pointer hover:border-primary transition-colors",children:[e.jsx("input",{type:"file",accept:"image/jpeg,image/png,image/webp",multiple:!0,className:"hidden",onChange:i=>{c(i.target.files),i.target.value=""}}),x?e.jsx(y,{className:"h-5 w-5 animate-spin text-muted-foreground"}):e.jsx(he,{className:"h-5 w-5 text-muted-foreground"}),e.jsx("span",{className:"text-[11px] text-muted-foreground",children:"Adicionar"})]})]}),e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:["Formato 9:16, o mesmo do story. Estas aparecem na página do pack, não na vitrine â a capa da vitrine é a de cima."," ",e.jsx("strong",{className:"font-medium",children:"Valem na hora"}),": o Salvar aqui embaixo é só para os campos de texto. JPG, PNG ou WebP, até 3 MB cada."]})]})}function P({label:a,value:r,hint:o}){return e.jsxs("div",{className:"rounded-lg border bg-card px-3 py-2",children:[e.jsx("p",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:a}),e.jsx("p",{className:"text-lg font-semibold tabular-nums",children:r}),o&&e.jsx("p",{className:"text-[10px] text-muted-foreground",children:o})]})}function we({sale:a}){const{data:r=[]}=oe(),{data:o=[]}=T(),{add:n,remove:t}=me(),[p,c]=h.useState(!1),x=new Set(o.flatMap(s=>s.sources.map(j=>j.group_id))),i=r.filter(s=>s.myRole==="main_admin"&&!x.has(s.id)),d=s=>u.error(V(s?.message)??s.message);return e.jsxs(w,{children:[e.jsxs(C,{className:"flex-row items-start justify-between gap-2 space-y-0",children:[e.jsxs("div",{children:[e.jsx(_,{children:"Pastas do pack"}),e.jsxs(S,{children:[a.items_count," ",a.items_count===1?"padrão":"padrões"," na versão publicada. Mexer nas pastas não muda o que está na loja.",a.sources.length>1&&" Com mais de uma pasta, cada uma vira uma subpasta na biblioteca de quem instala."]})]}),e.jsxs(m,{variant:"outline",size:"sm",className:"shrink-0",disabled:i.length===0,title:i.length===0?"Nenhuma pasta sua está livre":void 0,onClick:()=>c(!0),children:[e.jsx(ge,{className:"h-4 w-4"})," Adicionar"]})]}),e.jsx(A,{className:"space-y-2",children:a.sources.map(s=>e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-dashed px-3 py-2",children:[e.jsx(E,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsx(k,{to:"/receitas/$groupId",params:{groupId:s.group_id},className:"flex-1 min-w-0 text-sm font-medium hover:underline truncate",children:s.name}),a.sources.length>1&&e.jsx(m,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 text-muted-foreground",title:"Tirar do pack",disabled:t.isPending,onClick:()=>t.mutate({packId:a.pack_id,groupId:s.group_id},{onSuccess:()=>u.success("Pasta tirada do pack"),onError:d}),children:e.jsx(U,{className:"h-4 w-4"})}),e.jsx(je,{className:"h-4 w-4 text-muted-foreground shrink-0"})]},s.group_id))}),e.jsx(K,{open:p,onOpenChange:s=>!s&&c(!1),children:e.jsxs(Y,{className:"max-w-sm",children:[e.jsxs(Z,{children:[e.jsx(ee,{children:"Adicionar pasta ao pack"}),e.jsx(ae,{children:"Só aparecem pastas suas que ainda não estão em nenhum pack."})]}),e.jsx("div",{className:"grid gap-1.5",children:i.map(s=>e.jsxs("button",{type:"button",disabled:n.isPending,className:"flex items-center gap-2 rounded-lg border px-3 py-2 text-left text-sm hover:border-primary hover:bg-accent transition-colors",onClick:()=>n.mutate({packId:a.pack_id,groupId:s.id},{onSuccess:()=>{u.success("Pasta adicionada ao pack"),c(!1)},onError:d}),children:[e.jsx(E,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsx("span",{className:"truncate",children:s.name})]},s.id))})]})})]})}function Ce({sale:a}){const r=pe(),[o,n]=h.useState("");return e.jsxs(w,{children:[e.jsxs(C,{children:[e.jsx(_,{children:a.latest_version>0?`Publicar a versão ${a.latest_version+1}`:"Publicar a primeira versão"}),e.jsxs(S,{children:["Tira uma foto nova das pastas. Quem já instalou recebe o aviso e escolhe quando trazer â o que a pessoa editou por conta dela não é sobrescrito.",a.outdated_users>0&&` Hoje ${a.outdated_users} estão em versão antiga.`]})]}),e.jsxs(A,{className:"space-y-2",children:[e.jsx(f,{value:o,onChange:t=>n(t.target.value),placeholder:"O que mudou nesta versão"}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(ne,{avg:a.rating_avg,count:a.rating_count}),e.jsxs(m,{disabled:r.isPending,onClick:()=>r.mutate({packId:a.pack_id,changelog:o},{onSuccess:t=>{u.success(`v${t.version} publicada com ${t.items} padrões.`),n("")},onError:t=>u.error(V(t?.message)??t.message)}),children:[r.isPending?e.jsx(y,{className:"h-4 w-4 animate-spin"}):e.jsx(ve,{className:"h-4 w-4"}),"Publicar versão"]})]})]})]})}export{ta as component};
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.