1import{_ as H}from"./DYbbRoDQ.js";import Q from"./CFfeWV9Q.js";import{_ as G}from"./BlcQtP8d.js";import{e as J,r as c,k as K,E as R,q as N,c as n,b as y,ac as W,h as o,w as U,i as X,j as w,o as i,a,d as v,F as B,g as O,t as f,z as C,v as x,H as Y,x as V,n as $,af as Z}from"#entry";import{c as ee,h as oe,j as q,a as I,V as te}from"./WUcDpGuR.js";import{p as ae}from"./DJ5xrh-k.js";import{C as se}from"./BcphZJD-.js";const le={key:0,class:"grid grid-cols-2 gap-5"},re={key:0,class:"col-span-2"},ne={class:"flex flex-col rounded border border-yellow-500 bg-yellow-100 p-3 py-2"},ie={class:"col-span-2 flex flex-col"},ue=["disabled"],de={value:0,disabled:""},ce=["value"],me={class:"flex flex-col"},pe={class:"flex flex-col"},ve={class:"col-span-2 flex flex-col"},fe={key:0,class:"mt-1 text-xs text-gray-500"},xe={key:1,class:"mt-1 text-xs text-emerald-700"},_e={key:2,class:"mt-1 text-xs text-red-600"},be={class:"col-span-2 flex items-center gap-2"},ye=["disabled"],ge={class:"col-span-2 flex flex-col"},he=["disabled"],ke="Criando voucher, aguarde...",Ue=J({__name:"CreateVoucherModal",emits:["success"],setup(we,{expose:P,emit:T}){const u=c([]),d=c(""),_=c(null),p=c(!1),b=c(!1),g=c(!1),h=c([]),r=c(null),{$notify:k}=K(),j=T,S={product_id:0,amount:1,customer_email:"",notes:"",total:null,split:!1},t=R({...S});N(()=>t.customer_email,()=>{r.value=null,d.value=""}),N(()=>t.amount,l=>{l<=1&&(t.split=!1)});const z=async()=>{b.value=!0;try{const l=await w("/company/products");h.value=l.data??[]}catch{k.error("Não foi possÃvel carregar os passaportes.")}finally{b.value=!1}},M=async()=>{const l=t.customer_email.trim();if(r.value=null,d.value="",!!l)try{g.value=!0,r.value=await w("/company/customers/lookup",{query:{email:l}})}catch(e){const m=e;d.value=m.response?.message||"Nenhum usuário encontrado com este e-mail."}finally{g.value=!1}},E=()=>{Object.assign(t,S),u.value=[],d.value="",r.value=null},A=async()=>{u.value=[];try{if(p.value=!0,ee({product_id:q().required("Selecione um passaporte.").min(1,"Selecione um passaporte."),amount:q().required("Informe a quantidade.").min(1),customer_email:I().required("O e-mail é obrigatório.").email("E-mail inválido."),notes:I().max(500).nullable().transform(e=>e||void 0),total:q().nullable().min(0).transform((e,m)=>m===""||m==null?null:e),split:oe()}).validateSync(t,{abortEarly:!1}),r.value||await M(),!r.value){u.value=[d.value||"Busque um cliente válido pelo e-mail."];return}const l=await w("/company/orders/voucher",{method:"POST",body:{product_id:t.product_id,amount:t.amount,customer_email:t.customer_email.trim(),customer_id:r.value.id,notes:t.notes.trim()||null,total:t.total||null,split:t.split}});k.success("Voucher criado com sucesso."),_.value?.close(),j("success",l),E()}catch(l){if(l instanceof te){u.value=l.errors;return}u.value=ae(l),u.value.length&&k.error(u.value[0])}finally{p.value=!1}};return P({open:async()=>{E(),_.value?.open(),h.value.length===0&&await z()},close:()=>_.value?.close()}),(l,e)=>{const m=H,D=Q,F=G;return i(),n("form",{onSubmit:X(A,["prevent"]),class:"space-y-4"},[y(F,{ref_key:"modal",ref:_,size:"xl",title:"Criar voucher"},W({default:U(()=>[y(m,{message:ke,loading:o(p)},null,8,["loading"]),o(p)?C("",!0):(i(),n("div",le,[o(u).length>0?(i(),n("div",re,[a("div",ne,[(i(!0),n(B,null,O(o(u),(s,L)=>(i(),n("p",{key:L,class:"text-sm text-yellow-800"},f(s),1))),128))])])):C("",!0),a("div",ie,[e[6]||(e[6]=a("label",{for:"voucher-product"},[v(" Passaporte "),a("span",{class:"text-red-500"},"*")],-1)),x(a("select",{id:"voucher-product","onUpdate:modelValue":e[0]||(e[0]=s=>o(t).product_id=s),class:"mt-1 w-full rounded border-2 border-dark-10 bg-white px-3 py-2",disabled:o(b)},[a("option",de,f(o(b)?"Carregando...":"Selecione um passaporte"),1),(i(!0),n(B,null,O(o(h),s=>(i(),n("option",{key:s.id,value:s.id},f(s.name),9,ce))),128))],8,ue),[[Y,o(t).product_id,void 0,{number:!0}]])]),a("div",me,[e[7]||(e[7]=a("label",{for:"voucher-amount"},[v(" Quantidade "),a("span",{class:"text-red-500"},"*")],-1)),x(a("input",{id:"voucher-amount","onUpdate:modelValue":e[1]||(e[1]=s=>o(t).amount=s),type:"number",min:"1",class:"mt-1 w-full rounded border-2 border-dark-10 px-3 py-2"},null,512),[[V,o(t).amount,void 0,{number:!0}]])]),a("div",pe,[e[8]||(e[8]=a("label",{for:"voucher-total"},"Total (opcional)",-1)),y(se,{id:"voucher-total",modelValue:o(t).total,"onUpdate:modelValue":e[2]||(e[2]=s=>o(t).total=s),cents:!0,"input-class":"mt-1 w-full rounded border-2 border-dark-10 px-3 py-2",placeholder:"0,00"},null,8,["modelValue"])]),a("div",ve,[e[10]||(e[10]=a("label",{for:"voucher-email"},[v(" E-mail do cliente "),a("span",{class:"text-red-500"},"*")],-1)),x(a("input",{id:"voucher-email","onUpdate:modelValue":e[3]||(e[3]=s=>o(t).customer_email=s),type:"email",placeholder:"[email protected]",class:$(["mt-1 w-full rounded border-2 border-dark-10 px-3 py-2",o(d)?"border-red-500 bg-red-50":""]),onBlur:M},null,34),[[V,o(t).customer_email]]),o(g)?(i(),n("p",fe,"Buscando usuário...")):o(r)?(i(),n("p",xe,[e[9]||(e[9]=v("
1Cliente encontrado: ",-1)),a("strong",null,f(o(r).name),1)])):o(d)?(i(),n("p",_e,f(o(d)),1)):C("",!0)]),a("div",be,[x(a("input",{id:"voucher-split","onUpdate:modelValue":e[4]||(e[4]=s=>o(t).split=s),type:"checkbox",class:"h-4 w-4 rounded border-gray-300",disabled:o(t).amount<=1},null,8,ye),[[Z,o(t).split]]),a("label",{for:"voucher-split",class:$(["text-sm",o(t).amount<=1?"text-gray-400":"text-gray-700"])}," Dividir ",2)]),a("div",ge,[e[11]||(e[11]=a("label",{for:"voucher-notes"},"Observação (opcional)",-1)),x(a("textarea",{id:"voucher-notes","onUpdate:modelValue":e[5]||(e[5]=s=>o(t).notes=s),rows:"3",class:"mt-1 w-full rounded border-2 border-dark-10 px-3 py-2",placeholder:"Motivo do voucher, evento, etc."},null,512),[[V,o(t).notes]])]),e[12]||(e[12]=a("p",{class:"col-span-2 text-xs text-gray-600"}," O cliente precisa estar cadastrado no sistema. Informe o total para vendas em dinheiro; deixe em branco para cortesia. Marque dividir para gerar um código por unidade (quantidade maior que 1). ",-1))]))]),_:2},[o(p)?void 0:{name:"buttons",fn:U(()=>[a("button",{type:"submit",class:"rounded bg-emerald-500 px-4 py-2 text-white disabled:opacity-60",disabled:!o(r)},[e[13]||(e[13]=v(" Criar voucher ",-1)),y(D,{name:"lucide:send"})],8,he)]),key:"0"}]),1536)],32)}}});export{Ue as _};
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.