1import{j as e}from"./motion-D4KdtZcL.js";import{r as x}from"./charts-CsoIqgpX.js";import{c as X,u as Z,ae as ee,y as se,m as ae,B as h,L as te,aT as re,E as oe}from"./index-0Va8w-ll.js";import{u as le}from"./useMutation-BJnlB1Y3.js";import{u as ne,a as R,D as ie,c as de,S as ce,v as me,b as xe,C as ue,s as he,K as pe,P as ge,d as ve}from"./dnd-BARxAuNg.js";import{C as v}from"./card-Dxu_2p2z.js";import{I as u}from"./input-BHaNoatV.js";import{L as n}from"./label-DETfs2aB.js";import{T as S}from"./textarea-DK1OJsZE.js";import{S as j}from"./switch-DLRflaro.js";import{B}from"./badge-DLkwLeGt.js";import{S as D,a as A,b as M,c as z,d as _}from"./select-DMD88oyG.js";import{D as F,b as U,B as je,a as fe,s as be,l as Ne}from"./quoteTemplate-GzQ4lcmR.js";import{generateQuotePdf as q}from"./quotePdf-7XRHN9SW.js";import{A as we}from"./arrow-left-BcukAu7O.js";import{R as ye}from"./rotate-ccw-MfCle73-.js";import{S as Ce}from"./save-BJBJ0JME.js";import{P as _e}from"./palette-CiWZ2Jov.js";import{T as Se}from"./type-Drd3UJ7E.js";import{G as ke}from"./grip-vertical-C5uw7KB5.js";import{E as Ee}from"./eye-off-ChSS0ywx.js";import"./pdf-CkDQjKPC.js";import"./chevron-up-DVHGRXYl.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const Te=X("PanelsTopLeft",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"M9 21V9",key:"1oto5p"}]]),Le=[{value:"band",label:"Faixa colorida",hint:"Cabeçalho com fundo na cor de destaque"},{value:"centered",label:"Centralizado clássico",hint:"Nome ao centro com linha embaixo"},{value:"minimal",label:"Minimal linha",hint:"Apenas nome e número, linha fina"}],Pe=["#111111","#0f172a","#1e40af","#0ea5e9","#059669","#b45309","#dc2626","#7c3aed"];function Re({block:t,onToggle:f,onOptionChange:a}){const{attributes:d,listeners:b,setNodeRef:k,transform:N,transition:E,isDragging:g}=xe({id:t.id}),w={transform:ue.Transform.toString(N),transition:E,opacity:g?.6:1},i=t.options||{};return e.jsxs("div",{ref:k,style:w,className:`rounded-lg border bg-card p-3 ${t.visible?"":"opacity-60"}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",...d,...b,className:"cursor-grab active:cursor-grabbing text-muted-foreground hover:text-foreground p-1 -ml-1","aria-label":"Arrastar bloco",children:e.jsx(ke,{className:"h-4 w-4"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm",children:je[t.id]}),e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:fe[t.id]})]}),e.jsx(h,{type:"button",size:"sm",variant:"ghost",onClick:()=>f(t.id,!t.visible),className:"h-8 w-8 p-0",title:t.visible?"Ocultar":"Mostrar",children:t.visible?e.jsx(oe,{className:"h-4 w-4"}):e.jsx(Ee,{className:"h-4 w-4"})})]}),t.visible&&t.id==="customer"&&e.jsxs("div",{className:"mt-2 pl-6 flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:"Mostrar endereço"}),e.jsx(j,{checked:i.show_address!==!1,onCheckedChange:o=>a(t.id,"show_address",o)})]}),t.visible&&t.id==="items"&&e.jsxs("div",{className:"mt-2 pl-6 space-y-1 text-xs",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Descrição do item"}),e.jsx(j,{checked:i.show_description!==!1,onCheckedChange:o=>a(t.id,"show_description",o)})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Coluna de desconto"}),e.jsx(j,{checked:i.show_discount!==!1,onCheckedChange:o=>a(t.id,"show_discount",o)})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Linhas alternadas"}),e.jsx(j,{checked:i.striped!==!1,onCheckedChange:o=>a(t.id,"striped",o)})]})]}),t.visible&&t.id==="totals"&&e.jsxs("div",{className:"mt-2 pl-6 space-y-1 text-xs",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Mostrar subtotal"}),e.jsx(j,{checked:i.show_subtotal!==!1,onCheckedChange:o=>a(t.id,"show_subtotal",o)})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Mostrar frete"}),e.jsx(j,{checked:i.show_shipping!==!1,onCheckedChange:o=>a(t.id,"show_shipping",o)})]})]})]})}function as(){Z();const t=ee(),{toast:f}=se(),[a,d]=x.useState(F),[b,k]=x.useState(""),[N,E]=x.useState("edit"),[g,w]=x.useState(""),i=x.useRef(""),{data:o,isLoading:I}=ae({queryKey:["quote-template"],queryFn:Ne});x.useEffect(()=>{o&&d(o)},[o]),x.useEffect(()=>{const s=setTimeout(()=>{try{const r=U(a);if(g.trim()){const C=g.split(` 7`).map(L=>{const[O,J,W]=L.split("|").map(Y=>Y.trim()),P=Number(W.replace(",","."))||0;
7return{name:O,description:J,quantity:1,unit_price:P,discount_percent:0,total:P}}).filter(L=>L.name);r.items=[...r.items,...C]}const m=q(r,a).output("blob"),y=URL.createObjectURL(m);i.current&&URL.revokeObjectURL(i.current),i.current=y,k(y)}catch(r){console.error("preview error",r)}},250);return()=>clearTimeout(s)},[a,g]),x.useEffect(()=>()=>{i.current&&URL.revokeObjectURL(i.current)},[]);const T=le({mutationFn:()=>be(a),onSuccess:()=>{t.invalidateQueries({queryKey:["quote-template"]}),f({title:"Modelo salvo",description:"Será usado nos próximos PDFs."})},onError:s=>f({title:"Erro ao salvar",description:s.message,variant:"destructive"})}),K=ne(R(ge,{activationConstraint:{distance:4}}),R(pe,{coordinateGetter:he})),Q=s=>{const{active:r,over:l}=s;if(!l||r.id===l.id)return;const m=a.blocks.findIndex(C=>C.id===r.id),y=a.blocks.findIndex(C=>C.id===l.id);m<0||y<0||d({...a,blocks:ve(a.blocks,m,y)})},$=(s,r)=>d({...a,blocks:a.blocks.map(l=>l.id===s?{...l,visible:r}:l)}),G=(s,r,l)=>d({...a,blocks:a.blocks.map(m=>m.id===s?{...m,options:{...m.options||{},[r]:l}}:m)}),p=s=>d({...a,branding:{...a.branding,...s}}),c=s=>d({...a,texts:{...a.texts,...s}}),V=()=>{const s=U(a);q(s,a).save("preview-orcamento.pdf")},H=x.useMemo(()=>a.blocks.filter(s=>s.visible).length,[a.blocks]);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(h,{variant:"ghost",size:"sm",asChild:!0,children:e.jsxs(te,{to:"/admin/orcamentos",children:[e.jsx(we,{className:"h-4 w-4 mr-1.5"})," Voltar"]})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Modelo do PDF"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Personalize o layout usado em todos os orçamentos gerados"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(B,{variant:"secondary",className:"hidden sm:inline-flex",children:[H," blocos ativos"]}),e.jsxs(h,{variant:"ghost",onClick:()=>d(F),children:[e.jsx(ye,{className:"h-4 w-4 mr-1.5"})," Restaurar padrão"]}),e.jsxs(h,{variant:"outline",onClick:V,children:[e.jsx(re,{className:"h-4 w-4 mr-1.5"})," Baixar preview"]}),e.jsxs(h,{onClick:()=>T.mutate(),disabled:T.isPending||I,className:"bg-foreground text-background hover:bg-foreground
7/90",children:[e.jsx(Ce,{className:"h-4 w-4 mr-1.5"}),T.isPending?"Salvandoâ¦":"Salvar modelo"]})]})]}),e.jsx("div",{className:"lg:hidden grid grid-cols-2 gap-1 p-1 rounded-lg bg-muted",children:[["edit","Editar"],["preview","Pré-visualizar"]].map(([s,r])=>e.jsx("button",{type:"button",onClick:()=>E(s),className:`h-10 rounded-md text-sm font-medium transition-colors ${N===s?"bg-background shadow-sm":"text-muted-foreground"}`,children:r},s))}),e.jsxs("div",{className:"grid lg:grid-cols-2 gap-4",children:[e.jsxs("div",{className:`${N==="edit"?"":"hidden lg:block"} space-y-4 lg:max-h-[calc(100vh-9rem)] lg:overflow-y-auto lg:pr-2`,children:[e.jsxs(v,{className:"p-4 sm:p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_e,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("h3",{className:"font-semibold text-sm",children:"Identidade visual"})]}),e.jsxs("div",{children:[e.jsx(n,{className:"text-xs",children:"Logo"}),e.jsx("p",{className:"text-[11px] text-muted-foreground mb-1.5",children:"PNG ou JPG. Fundo transparente funciona melhor. Até ~2MB."}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"h-20 w-20 rounded-md border border-dashed border-border flex items-center justify-center overflow-hidden shrink-0",style:{backgroundColor:a.header_style==="band"?a.branding.accent_color:"hsl(var(--muted))"},children:a.branding.logo_url?e.jsx("img",{src:a.branding.logo_url,alt:"logo",className:"max-h-full max-w-full object-contain"}):e.jsx("span",{className:"text-[10px] text-muted-foreground",children:"Sem logo"})}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(h,{type:"button",size:"sm",variant:"outline",onClick:()=>document.getElementById("tpl-logo-file")?.click(),children:"Enviar arquivo"}),a.branding.logo_url&&e.jsx(h,{type:"button",size:"sm",variant:"ghost",onClick:()=>p({logo_url:""}),children:"Remover"}),e.jsx("input",{id:"tpl-logo-file",type:"file",accept:"image/png,image/jpeg,image/webp",className:"hidden",onChange:s=>{const r=s.target.files?.[0];if(s.currentTarget.value="",!r)return;if(r.size>2*1024*1024){f({title:"Arquivo grande",description:"Envie um logo até 2MB.",variant:"destructive"});return}const l=new FileReader;l.onload=()=>p({logo_url:l.result}),l.readAsDataURL(r)}})]}),e.jsx(u,{value:a.branding.logo_url||"",onChange:s=>p({logo_url:s.target.value}),placeholder:"ou cole uma URL https://...",className:"text-xs"})]})]})]}),e.jsxs("div",{children:[e.jsx(n,{className:"text-xs",children:"Cor de destaque"}),e.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[e.jsx("input",{type:"color",value:a.branding.accent_color,onChange:s=>p({accent_color:s.target.value}),className:"h-9 w-12 rounded-md border border-input bg-background cursor-pointer"}),e.jsx(u,{value:a.branding.accent_color,onChange:s=>p({accent_color:s.target.value}),className:"max-w-[140px] font-mono text-xs"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:Pe.map(s=>e.jsx("button",{type:"button",onClick:()=>p({accent_color:s}),className:"h-6 w-6 rounded-md border hover:scale-110 transition-transform",style:{backgroundColor:s},title:s},s))})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsxs(n,{className:"text-xs flex items-center gap-1",children:[e.jsx(Se,{className:"h-3 w-3"})," Fonte"]}),e.jsxs(D,{value:a.branding.font,onValueChange:s=>p({font:s}),children:[e.jsx(A,{className:"mt-1.5",children:e.jsx(M,{})}),e.jsxs(z,{children:[e.jsx(_,{value:"helvetica",children:"Helvetica (moderno)"}),e.jsx(_,{value:"times",children:"Times (clássico)"})]})]})]}),e.jsxs("div",{children:[e.jsx(n,{className:"text-xs",children:"Densidade"}),e.jsxs(D,{value:a.branding.density,onValueChange:s=>p({density:s}),children:[e.jsx(A,{className:"mt-1.5",children:e.jsx(M,{})}),e.jsxs(z,{children:[e.jsx(_,{value:"compact",children:"Compacto"}),e.jsx(_,{value:"normal",children:"Normal"}),e.jsx(_,{value:"relaxed",children:"Espaçado"})]})]})]})]})]}),e.jsxs(v,{className:"p-4 sm:p-5 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Te,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("h3",{className:"font-semibold text-sm",children:"Estilo do cabeçalho"})]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:Le.map(s=>{const r=a.header_style===s.value;return e.jsxs("button",{type:"button",onClick:()=>d({...a,header_style:s.value}),className:`text-left rounded-lg border-2 p-3 transition-all ${r?"border-foreground bg-foreground
7/5":"border-border hover:border-foreground/40"}`,children:[e.jsxs("div",{className:"h-10 rounded mb-2 flex items-center justify-between px-2",style:{backgroundColor:s.value==="band"?a.branding.accent_color:"transparent",borderBottom:s.value==="centered"?`1.5px solid ${a.branding.accent_color}`:s.value==="minimal"?"1px solid hsl(var(--border))":"none"},children:[s.value==="band"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-1.5 w-8 bg-background/80 rounded"}),e.jsx("div",{className:"h-1.5 w-4 bg-background/80 rounded"})]}),s.value==="centered"&&e.jsx("div",{className:"h-1.5 w-12 bg-foreground/70 rounded mx-auto"}),s.value==="minimal"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-1 w-6 bg-foreground/70 rounded"}),e.jsx("div",{className:"h-1 w-4 bg-muted-foreground/50 rounded"})]})]}),e.jsx("p",{className:"text-xs font-medium",children:s.label}),e.jsx("p",{className:"text-[10px] text-muted-foreground leading-tight mt-0.5",children:s.hint})]},s.value)})})]}),e.jsxs(v,{className:"p-4 sm:p-5 space-y-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-sm",children:"Blocos do PDF"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Arraste para reordenar. Use o olho para mostrar ou ocultar."})]}),e.jsx(ie,{sensors:K,collisionDetection:de,onDragEnd:Q,children:e.jsx(ce,{items:a.blocks.map(s=>s.id),strategy:me,children:e.jsx("div",{className:"space-y-2",children:a.blocks.map(s=>e.jsx(Re,{block:s,onToggle:$,onOptionChange:G},s.id))})})})]}),e.jsxs(v,{className:"p-4 sm:p-5 space-y-3",children:[e.jsx("h3",{className:"font-semibold text-sm",children:"Textos padrão"}),e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{children:[e.jsx(n,{className:"text-xs",children:"Nome da empresa"}),e.jsx(u,{value:a.texts.company_name,onChange:s=>c({company_name:s.target.value})})]}),e.jsxs("div",{children:[e.jsx(n,{className:"text-xs",children:"TÃtulo padrão da proposta"}),e.jsx(u,{value:a.texts.default_title,onChange:s=>c({default_title:s.target.value})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(n,{className:"text-xs",children:"Nome do vendedor"}),e.jsx(u,{value:a.texts.seller_name,onChange:s=>c({seller_name:s.target.value}),placeholder:"Ex: Ana Souza"})]}),e.jsxs("div",{children:[e.jsx(n,{className:"text-xs",children:"Cargo"}),e.jsx(u,{value:a.texts.seller_role,onChange:s=>c({seller_role:s.target.value})})]})]}),e.jsxs("div",{children:[e.jsx(n,{className:"text-xs",children:"Texto de garantia"}),e.jsx(S,{value:a.texts.warranty_text,onChange:s=>c({warranty_text:s.target.value}),rows:2})]}),e.jsxs("div",{children:[e.jsx(n,{className:"text-xs",children:"Forma de pagamento sugerida (padrão)"}),e.jsx(S,{value:a.texts.default_payment,onChange:s=>c({default_payment:s.target.value}),rows:2,placeholder:"Usado quando o orçamento não preencher esse campo"})]}),e.jsxs("div",{children:[e.jsx(n,{className:"text-xs",children:"Condições padrão"}),e.jsx(S,{value:a.texts.default_terms,onChange:s=>c({default_terms:s.target.value}),rows:2})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsxs("div",{children:[e.jsx(n,{className:"text-xs",children:"Site (rodapé)"}),e.jsx(u,{value:a.texts.footer_site,onChange:s=>c({footer_site:s.target.value})})]}),e.jsxs("div",{children:[e.jsx(n,{className:"text-xs",children:"WhatsApp (rodapé)"}),e.jsx(u,{value:a.texts.footer_whatsapp,onChange:s=>c({footer_whatsapp:s.target.value})})]}),e.jsxs("div",{children:[e.jsx(n,{className:"text-xs",children:"Email (rodapé)"}),e.jsx(u,{value:a.texts.footer_email,onChange:s=>c({footer_email:s.target.value})})]})]})]})]}),e.jsxs(v,{className:"p-4 sm:p-5 space-y-3",children:[e.jsx("h3",{className:"font-semibold text-sm",children:"Itens padrão"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:'Itens que serão incluÃdos automaticamente nos orçamentos. Use "nome | descrição | preço" por linha.'}),e.jsx(S,{value:g,onChange:s=>w(s.target.value),rows:3,placeholder:"Ex: Kit limpeza | Spray + flanela + estojo | 49,00\\nExame de vista | Refração completa | 120,00",className:"w-full mt-2 rounded-md border border-input bg-background p-2 text-sm"}),e.jsxs("div",{className:"mt-3 grid grid-cols-2 gap-2",children:[e.jsx(h,{type:"button",size:"sm",variant:"ghost",onClick:()=>w("Kit limpeza | Spray + flanela + estojo | 49,00"),children:"Kit limpeza"}),e.jsx(h,{type:"button",size:"sm",variant:"ghost",onClick:()=>w("Exame de vista | Refração completa | 120,00"),children:"Exame de vista"})]})]})]}),e.jsx("div",{className:`${N==="preview"?"":"hidden lg:block"} lg:sticky lg:top-4 lg:self-start`,children:e.jsxs(v,{className:"overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b bg-secondary/40",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:"Preview ao vivo"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Dados fictÃcios · atualiza enquanto você edita"})]}),e.jsx(B,{variant:"outline",className:"text-[10px]",children:"A4"})]}),e.jsx("div",{className:"bg-muted/40 h-[calc(100vh-11rem)] min-h-[520px]",children:b?e.jsx("iframe",{src:`${b}#toolbar=0&navpanes=0&view=FitH`,title:"Preview do PDF",className:"w-full h-full"},b):e.jsx("div",{className:"w-full h-full flex items-center justify-center text-sm text-muted-foreground",children:"Gerando previewâ¦"})})]})})]})]})}export{as 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.