vendor: 5,902 bytes, lines 1-11
1import{h as Fe,r as s,j as e,al as xe,d as w,f as ne,I as $,B as k,q as st,K as rt,ab as nt,g as S,aL as lt,aM as Ae,u as it,aN as ot,c as ct,aO as Te,a as dt,b as ut,L as re,W as Me,aP as Re,e as Oe,M as Be,aQ as mt,A as pt,aR as ht,C as ft,aS as Le}from"./index-FWKSGZPO.js";import{C as Z,a as ge,b as ve,d as je,c as K}from"./card-DTQVPU97.js";import{L as X}from"./label--tnD4pjg.js";import{B as be}from"./badge-Cpd-8HxK.js";import{T as Ie,a as $e,b as ce,c as pe}from"./tabs-BQ8VhpUK.js";import{A as xt,h as gt,a as vt,b as jt,c as bt,d as yt,e as wt,f as Nt,g as Ct}from"./alert-dialog-Ch5-74qd.js";import{M as _t}from"./message-circle-D33wQSco.js";import{P as St}from"./pencil-BFL_pWo_.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 kt=Fe("Circle",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]]);/** 7 * @license lucide-react v0.462.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const Et=Fe("Dot",[["circle",{cx:"12.1",cy:"12.1",r:"1",key:"18d7e5"}]]);var Pt=Object.defineProperty,Dt=Object.defineProperties,At=Object.getOwnPropertyDescriptors,ye=Object.getOwnPropertySymbols,Ve=Object.prototype.hasOwnProperty,qe=Object.prototype.propertyIsEnumerable,We=(t,a,l)=>a in t?Pt(t,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):t[a]=l,Tt=(t,a)=>{for(var l in a||(a={}))Ve.call(a,l)&&We(t,l,a[l]);if(ye)for(var l of ye(a))qe.call(a,l)&&We(t,l,a[l]);return t},Mt=(t,a)=>Dt(t,At(a)),Rt=(t,a)=>{var l={};for(var i in t)Ve.call(t,i)&&a.indexOf(i)<0&&(l[i]=t[i]);if(t!=null&&ye)for(var i of ye(t))a.indexOf(i)<0&&qe.call(t,i)&&(l[i]=t[i]);return l};function Ot(t){let a=setTimeout(t,0),l=setTimeout(t,10),i=setTimeout(t,50);return[a,l,i]}function Bt(t){let a=s.useRef();return s.useEffect(()=>{a.current=t}),a.current}var Lt=18,He=40,It=`${He}px`,$t=["[data-lastpass-icon-root]","com-1password-button","[data-dashlanecreated]",'[style$="2147483647 !important;"]'].join(",");function Wt({containerRef:t,inputRef:a,pushPasswordManagerStrategy:l,isFocused:i}){let[v,c]=s.useState(!1),[u,N]=s.useState(!1),[j,A]=s.useState(!1),m=s.useMemo(()=>l==="none"?!1:(l==="increase-width"||l==="experimental-no-flickering")&&v&&u,[v,u,l]),C=s.useCallback(()=>{let x=t.current,D=a.current;if(!x||!D||j||l==="none")return;let p=x,E=p.getBoundingClientRect().left+p.offsetWidth,_=p.getBoundingClientRect().top+p.offsetHeight/2,f=E-Lt,R=_;document.querySelectorAll($t).length===0&&document.elementFromPoint(f,R)===x||(c(!0),A(!0))},[t,a,j,l]);return s.useEffect(()=>{let x=t.current;if(!x||l==="none")return;function D(){let E=window.innerWidth-x.getBoundingClientRect().right;N(E>=He)}D();let p=setInterval(D,1e3);return()=>{clearInterval(p)}},[t,l]),s.useEffect(()=>{let x=i||document.activeElement===a.current;if(l==="none"||!x)return;let D=setTimeout(C,0),p=setTimeout(C,2e3),E=setTimeout(C,5e3),_=setTimeout(()=>{A(!0)},6e3);return()=>{clearTimeout(D),clearTimeout(p),clearTimeout(E),clearTimeout(_)}},[a,i,l,C]),{hasPWMBadge:v,willPushPWMBadge:m,PWM_BADGE_SPACE_WIDTH:It}}var ze=s.createContext({}),Ge=s.forwardRef((t,a)=>{var l=t,{value:i,onChange:v,maxLength:c,textAlign:u="left",pattern:N,placeholder:j,inputMode:A="numeric",onComplete:m,pushPasswordManagerStrategy:C="increase-width",pasteTransformer:x,containerClassName:D,noScriptCSSFallback:p=Ft,render:E,children:_}=l,f=Rt(l,["value","onChange","maxLength","textAlign","pattern","placeholder","inputMode","onComplete","pushPasswordManagerStrategy","pasteTransformer","containerClassName","noScriptCSSFallback","render","children"]),R,V,Q,J,le;let[n,W]=s.useState(typeof f.defaultValue=="string"?f.defaultValue:""),y=i??n,q=Bt(y),Y=s.useCallback(o=>{v==null||v(o),W(o)},[v]),O=s.useMemo(()=>N?typeof N=="string"?new RegExp(N):N:null,[N]),r=s.useRef(null),h=s.useRef(null),B=s.useRef({value:y,onChange:Y,isIOS:typeof window<"u"&&((V=(R=window==null?void 0:window.CSS)==null?void 0:R.supports)==null?void 0:V.call(R,"-webkit-touch-callout","none"))}),g=s.useRef({prev:[(Q=r.current)==null?void 0:Q.selectionStart,(J=r.current)==null?void 0:J.selectionEnd,(le=r.current)==null?void 0:le.selectionDirection]});s.useImperativeHandle(a,()=>r.current,[]),s.useEffect(()=>{let o=r.current,d=h.current;if(!o||!d)return;B.current.value!==o.value&&B.current.onChange(o.value),g.current.prev=[o.selectionStart,o.selectionEnd,o.selectionDirection];function P(){if(document.activeElement!==o){ue(null),me(null);return}let b=o.selectionStart,M=o.selectionEnd,fe=o.selectionDirection,F=o.maxLength,te=o.value,H=g.current.prev,G=-1,U=-1,ae;if(te.length!==0&&b!==null&&M!==null){let et=b===M,tt=b===te.length&&te.length<F;if(et&&!tt){let se=b;if(se===0)G=0,U=1,ae="forward";else if(se===F)G=se-1,U=se,ae="backward";else if(F>1&&te.length>1){let Ce=0;if(H[0]!==null&&H[1]!==null){ae=se<H[1]?"backward":"forward";let at=H[0]===H[1]&&H[0]<F;ae==="backward"&&!at&&(Ce=-1)}G=Ce+se,U=Ce+se+1}}G!==-1&&U!==-1&&G!==U&&r.current.setSelectionRange(G,U,ae)}let Pe=G!==-1?G:b,De=U!==-1?U:M,Ye=ae??fe;ue(Pe),me(De),g.current.prev=[Pe,De,Ye]}if(document.addEventListener("selectionchange",P,{capture:!0}),P(),document.activeElement===o&&we(!0),!document.getElementById("input-otp-style")){let b=document.createElement("style");if(b.id="input-otp-style",document.head.appendChild(b),b.sheet){let M="background: transparent !important; color: transparent !important; border-color: transparent !important; opacity: 0 !important; box-shadow: none !important; -webkit-box-shadow: none !important; -webkit-text-fill-color: transparent !important;";he(b.sheet,"[data-input-otp]::selection { background: transparent !important; color: transparent !important; }"),he(b.sheet,`[data-input-otp]:autofill { ${M} }`),he(b.sheet,`[data-input-otp]:-webkit-autofill { ${M} }
11`),he(b.sheet,"@supports (-webkit-touch-callout: none) { [data-input-otp] { letter-spacing: -.6em !important; font-weight: 100 !important; font-stretch: ultra-condensed; font-optical-sizing: none !important; left: -1px !important; right: 1px !important; } }"),he(b.sheet,"[data-input-otp] + * { pointer-events: all !important; }")}}let L=()=>{d&&d.style.setProperty("--root-height",`${o.clientHeight}px`)};L();let I=new ResizeObserver(L);return I.observe(o),()=>{document.removeEventListener("selectionchange",P,{capture:!0}),I.disconnect()}},[]);let[T,z]=s.useState(!1),[de,we]=s.useState(!1),[ee,ue]=s.useState(null),[ie,me]=s.useState(null);s.useEffect(()=>{Ot(()=>{var o,d,P,L;(o=r.current)==null||o.dispatchEvent(new Event("input"));let I=(d=r.current)==null?void 0:d.selectionStart,b=(P=r.current)==null?void 0:P.selectionEnd,M=(L=r.current)==null?void 0:L.selectionDirection;I!==null&&b!==null&&(ue(I),me(b),g.current.prev=[I,b,M])})},[y,de]),s.useEffect(()=>{q!==void 0&&y!==q&&q.length<c&&y.length===c&&(m==null||m(y))},[c,m,q,y]);let oe=Wt({containerRef:h,inputRef:r,pushPasswordManagerStrategy:C,isFocused:de}),_e=s.useCallback(o=>{let d=o.currentTarget.value.slice(0,c);if(d.length>0&&O&&!O.test(d)){o.preventDefault();return}typeof q=="string"&&d.length<q.length&&document.dispatchEvent(new Event("selectionchange")),Y(d)},[c,Y,q,O]),Se=s.useCallback(()=>{var o;if(r.current){let d=Math.min(r.current.value.length,c-1),P=r.current.value.length;(o=r.current)==null||o.setSelectionRange(d,P),ue(d),me(P)}we(!0)},[c]),ke=s.useCallback(o=>{var d,P;let L=r.current;if(!x&&(!B.current.isIOS||!o.clipboardData||!L))return;let I=o.clipboardData.getData("text/plain"),b=x?x(I):I;o.preventDefault();let M=(d=r.current)==null?void 0:d.selectionStart,fe=(P=r.current)==null?void 0:P.selectionEnd,F=(M!==fe?y.slice(0,M)+b+y.slice(fe):y.slice(0,M)+b+y.slice(M)).slice(0,c);if(F.length>0&&O&&!O.test(F))return;L.value=F,Y(F);let te=Math.min(F.length,c-1),H=F.length;L.setSelectionRange(te,H),ue(te),me(H)},[c,Y,O,y]),Ke=s.useMemo(()=>({position:"relative",cursor:f.disabled?"default":"text",userSelect:"none",WebkitUserSelect:"none",pointerEvents:"none"}),[f.disabled]),Ee=s.useMemo(()=>({position:"absolute",inset:0,width:oe.willPushPWMBadge?`calc(100% + ${oe.PWM_BADGE_SPACE_WIDTH})`:"100%",clipPath:oe.willPushPWMBadge?`inset(0 ${oe.PWM_BADGE_SPACE_WIDTH} 0 0)`:void 0,height:"100%",display:"flex",textAlign:u,opacity:"1",color:"transparent",pointerEvents:"all",background:"transparent",caretColor:"transparent",border:"0 solid transparent",outline:"0 solid transparent",boxShadow:"none",lineHeight:"1",letterSpacing:"-.5em",fontSize:"var(--root-height)",fontFamily:"monospace",fontVariantNumeric:"tabular-nums"}),[oe.PWM_BADGE_SPACE_WIDTH,oe.willPushPWMBadge,u]),Qe=s.useMemo(()=>s.createElement("input",Mt(Tt({autoComplete:f.autoComplete||"one-time-code"},f),{"data-input-otp":!0,"data-input-otp-placeholder-shown":y.length===0||void 0,"data-input-otp-mss":ee,"data-input-otp-mse":ie,inputMode:A,pattern:O==null?void 0:O.source,"aria-placeholder":j,style:Ee,maxLength:c,value:y,ref:r,onPaste:o=>{var d;ke(o),(d=f.onPaste)==null||d.call(f,o)},onChange:_e,onMouseOver:o=>{var d;z(!0),(d=f.onMouseOver)==null||d.call(f,o)},onMouseLeave:o=>{var d;z(!1),(d=f.onMouseLeave)==null||d.call(f,o)},onFocus:o=>{var d;Se(),(d=f.onFocus)==null||d.call(f,o)},onBlur:o=>{var d;we(!1),(d=f.onBlur)==null||d.call(f,o)}})),[_e,Se,ke,A,Ee,c,ie,ee,f,O==null?void 0:O.source,y]),Ne=s.useMemo(()=>({slots:Array.from({length:c}).map((o,d)=>{var P;let L=de&&ee!==null&&ie!==null&&(ee===ie&&d===ee||d>=ee&&d<ie),I=y[d]!==void 0?y[d]:null,b=y[0]!==void 0?null:(P=j==null?void 0:j[d])!=null?P:null;return{char:I,placeholderChar:b,isActive:L,hasFakeCaret:L&&I===null}}),isFocused:de,isHovering:!f.disabled&&T}),[de,T,c,ie,ee,f.disabled,y]),Je=s.useMemo(()=>E?E(Ne):s.createElement(ze.Provider,{value:Ne},_),[_,Ne,E]);return s.createElement(s.Fragment,null,p!==null&&s.createElement("noscript",null,s.createElement("style",null,p)),s.createElement("div",{ref:h,"data-input-otp-container":!0,style:Ke,className:D},Je,s.createElement("div",{style:{position:"absolute",inset:0,pointerEvents:"none"}},Qe)))});Ge.displayName="Input";function he(t,a){try{t.insertRule(a)}catch{console.error("input-otp could not insert CSS rule:",a)}}var Ft=` 12[data-input-otp] { 13 --nojs-bg: white !important; 14 --nojs-fg: black !important; 15 16 background-color: var(--nojs-bg) !important; 17 color: var(--nojs-fg) !important; 18 caret-color: var(--nojs-fg) !important; 19 letter-spacing: .25em !important; 20 text-align: center !important; 21 border: 1px solid var(--nojs-fg) !important; 22 border-radius: 4px !important; 23 width: 100% !important; 24} 25@media (prefers-color-scheme: dark) { 26 [data-input-otp] { 27 --nojs-bg: black !important; 28 --nojs-fg: white !important; 29 } 30}`;const Ue=s.forwardRef(({className:t,containerClassName:a,...l},i)=>e.jsx(Ge,{ref:i,containerClassName:xe("flex items-center gap-2 has-[:disabled]:opacity-50",a),className:xe("disabled:cursor-not-allowed",t),...l}));Ue.displayName="InputOTP";const Xe=s.forwardRef(({className:t,...a},l)=>e.jsx("div",{ref:l,className:xe("flex items-center",t),...a}));Xe.displayName="InputOTPGroup";const Ze=s.forwardRef(({index:t,className:a,...l},i)=>{const v=s.useContext(ze),{char:c,hasFakeCaret:u,isActive:N}=v.slots[t];return e.jsxs("div",{ref:i,className:xe("relative flex h-10 w-10 items-center justify-center border-y border-r border-input text-sm transition-all first:rounded-l-md first:border-l last:rounded-r-md",N&&"z-10 ring-2 ring-ring ring-offset-background",a),...l,children:[c,u&&e.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",children:e.jsx("div",{className:"animate-caret-blink h-4 w-px bg-foreground duration-1000"})})]})});Ze.displayName="InputOTPSlot";const Vt=s.forwardRef(({...t},a)=>e.jsx("div",{ref:a,role:"separator",...t,children:e.jsx(Et,{})}));Vt.displayName="InputOTPSeparator";const qt=t=>{const a=t.toUpperCase().replace(/[^A-Z0-9]/g,"").slice(0,7);return a.length<=3?a:`${a.slice(0,3)}-${a.slice(3)}`},Ht=t=>t.replace(/\D/g,"").slice(0,11).replace(/(\d{3})(\d)/,"$1.$2").replace(/(\d{3})(\d)/,"$1.$2").replace(/(\d{3})(\d{1,2})$/,"$1-$2"),zt=t=>{let a=t.replace(/\D/g,"");return a.length>11&&a.startsWith("55")&&(a=a.slice(2)),a=a.slice(0,11),a.length<10?a:`(${a.slice(0,2)}) ${a.slice(2,a.length-4)}-${a.slice(-4)}`};function Gt({userId:t,email:a,startEditing:l=!1}){const[i,v]=s.useState(!0),[c,u]=s.useState(!1),[N,j]=s.useState(l),A=()=>window.dispatchEvent(new Event("perfil-updated")),[m,C]=s.useState({full_name:"",phone:"",cpf:"",birth_date:"",city:""}),[x,D]=s.useState([]),[p,E]=s.useState({plate:"",model:"",color:""}),_=async()=>{const{data:n}=await w.from("customer_vehicles").select("id,plate,model,color,is_primary,confirmed").eq("user_id",t).order("created_at");D(n||[]),A()};s.useEffect(()=>{(async()=>{await w.rpc("profile_prefill_from_booking");const{data:n}=await w.from("profiles").select("full_name,phone,cpf,birth_date,city").eq("id",t).maybeSingle();n&&C({full_name:n.full_name||"",phone:n.phone||"",cpf:n.cpf||"",birth_date:n.birth_date||"",city:n.city||""}),await _(),v(!1)})()},[t]);const f=async()=>
30{if(m.full_name.trim().split(/\s+/).length<2)return S.error("Informe nome e sobrenome.");if(m.phone.replace(/\D/g,"").length<10)return S.error("Informe um telefone válido.");u(!0);const{error:n}=await w.from("profiles").update({full_name:m.full_name.trim()||null,phone:m.phone.replace(/\D/g,"")||null,cpf:m.cpf.replace(/\D/g,"")||null,birth_date:m.birth_date||null,city:m.city.trim()||null}).eq("id",t);if(u(!1),n)return S.error(n.code==="23505"?"Este telefone já está em outro cadastro. Fale com a gente pelo WhatsApp para unificar.":"Não foi possÃvel salvar. Tente de novo.");S.success("Dados salvos."),A(),j(!1)},R=async()=>{if(p.plate.replace(/\W/g,"").length<7)return S.error("Confira a placa.");const{error:n}=await w.from("customer_vehicles").insert({user_id:t,plate:p.plate,model:p.model.trim()||null,color:p.color.trim()||null,is_primary:x.length===0});if(n)return S.error("Não foi possÃvel adicionar o veÃculo.");E({plate:"",model:"",color:""}),_()},V=async n=>{var W;if(!((W=n.model)!=null&&W.trim()))return S.error("Informe o modelo antes de confirmar.");await w.from("customer_vehicles").update({confirmed:!0}).eq("id",n.id),S.success("VeÃculo confirmado."),_()},Q=async(n,W)=>{await w.from("customer_vehicles").update({model:W.trim()||null}).eq("id",n.id)},J=async n=>{await w.from("customer_vehicles").delete().eq("id",n),_()},le=async n=>{await w.from("customer_vehicles").update({is_primary:!1}).eq("user_id",t),await w.from("customer_vehicles").update({is_primary:!0}).eq("id",n),_()};return i?e.jsx("div",{className:"flex justify-center py-10",children:e.jsx(ne,{className:"h-6 w-6 animate-spin"})}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs(Z,{children:[e.jsxs(ge,{children:[e.jsx(ve,{className:"text-base",children:"Meus dados"}),e.jsx(je,{children:"Trazidos da sua reserva. Para mudar algo, use Editar perfil."})]}),e.jsxs(K,{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1 sm:col-span-2",children:[e.jsx(X,{children:"Nome completo"}),e.jsx($,{disabled:!N,value:m.full_name,maxLength:120,onChange:n=>C({...m,full_name:n.target.value})})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(X,{children:"E-mail"}),e.jsx($,{value:a||"",disabled:!0})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(X,{children:"Telefone (WhatsApp)"}),e.jsx($,{disabled:!N,value:zt(m.phone),inputMode:"tel",maxLength:20,placeholder:"(11) 99999-9999",onChange:n=>C({...m,phone:n.target.value})})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(X,{children:"CPF"}),e.jsx($,{disabled:!N,value:Ht(m.cpf),inputMode:"numeric",onChange:n=>C({...m,cpf:n.target.value})})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(X,{children:"Data de nascimento (opcional)"}),e.jsx($,{disabled:!N,type:"date",value:m.birth_date,onChange:n=>C({...m,birth_date:n.target.value})})]}),e.jsxs("div",{className:"space-y-1 sm:col-span-2",children:[e.jsx(X,{children:"Cidade"}),e.jsx($,{disabled:!N,value:m.city,maxLength:80,onChange:n=>C({...m,city:n.target.value})})]}),e.jsx("div",{className:"flex gap-2 sm:col-span-2",children:N?e.jsxs(e.Fragment,{children:[e.jsx(k,{onClick:f,disabled:c,children:c?"Salvando...":"Salvar dados"}),e.jsx(k,{variant:"outline",onClick:()=>j(!1),disabled:c,children:"Cancelar"})]}):e.jsx(k,{variant:"outline",onClick:()=>j(!0),children:"Editar perfil"})})]})]}),e.jsxs(Z,{children:[e.jsxs(ge,{children:[e.jsx(ve,{className:"text-base",children:"Meus veÃculos"}),e.jsx(je,{children:"Cadastre seus carros e escolha o principal."})]}),e.jsxs(K,{className:"space-y-3",children:[x.map(n=>e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border p-3 text-sm",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"font-semibold",children:[n.plate," ",n.is_primary&&e.jsx(be,{variant:"outline",className:"ml-2",children:"Principal"})," ",!n.confirmed&&e.jsx(be,{className:"ml-1",children:"Confirme seu veÃculo"})]}),n.confirmed?e.jsx("div",{className:"text-muted-foreground",children:[n.model,n.color].filter(
30Boolean).join(" · ")||"Sem modelo"}):e.jsxs("div",{className:"mt-1 flex gap-2",children:[e.jsx($,{className:"h-8",placeholder:"Modelo",defaultValue:n.model||"",maxLength:60,onBlur:W=>{n.model=W.target.value,Q(n,W.target.value)}}),e.jsx(k,{size:"sm",onClick:()=>V(n),children:"Confirmar"})]})]}),e.jsxs("div",{className:"flex gap-1",children:[!n.is_primary&&e.jsx(k,{size:"icon",variant:"ghost","aria-label":"Tornar principal",onClick:()=>le(n.id),children:e.jsx(st,{className:"h-4 w-4"})}),e.jsx(k,{size:"icon",variant:"ghost","aria-label":"Remover",onClick:()=>J(n.id),children:e.jsx(rt,{className:"h-4 w-4"})})]})]},n.id)),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-[1fr_1.5fr_1fr_auto]",children:[e.jsx($,{placeholder:"Placa",value:p.plate,onChange:n=>E({...p,plate:qt(n.target.value)})}),e.jsx($,{placeholder:"Modelo",maxLength:60,value:p.model,onChange:n=>E({...p,model:n.target.value})}),e.jsx($,{placeholder:"Cor",maxLength:30,value:p.color,onChange:n=>E({...p,color:n.target.value})}),e.jsxs(k,{onClick:R,children:[e.jsx(nt,{className:"mr-1 h-4 w-4"})," Adicionar"]})]})]})]})]})}function Ut(){const[t,a]=s.useState({status:"loading"});return s.useEffect(()=>{w.functions.invoke("traveler-me",{body:{}}).then(({data:l,error:i})=>{const v=l;if(i||!(v!=null&&v.status))return a({status:"error"});a({status:v.status,token:v.token})})},[]),t.status==="loading"?e.jsx("div",{className:"flex justify-center py-10",children:e.jsx(ne,{className:"h-6 w-6 animate-spin"})}):t.status==="ok"&&t.token?e.jsx(lt,{token:t.token,embedded:!0}):e.jsx(Z,{children:e.jsx(K,{className:"py-10 text-center text-sm text-muted-foreground",children:t.status==="no_booking"?"O Programa de Viajantes libera depois da sua primeira reserva confirmada no xpark. Assim que ela for aprovada, a pesquisa aparece aqui.":"Não foi possÃvel carregar agora. Tente de novo em instantes."})})}function Xt({onComplete:t}){const[a,l]=s.useState(null),i=s.useCallback(async()=>{var A,m,C,x;const{data:c}=await w.auth.getUser();if(!c.user)return;const[{data:u},{data:N}]=await Promise.all([w.from("profiles").select("full_name,phone,cpf,birth_date,city").eq("id",c.user.id).maybeSingle(),w.from("customer_vehicles").select("confirmed").eq("user_id",c.user.id)]),j=N??[];l([{label:"Nome",done:!!((A=u==null?void 0:u.full_name)!=null&&A.trim())},{label:"Telefone",done:!!((m=u==null?void 0:u.phone)!=null&&m.trim())},{label:j.length?"Confirmar veÃculo":"Cadastrar veÃculo",done:j.some(D=>D.confirmed)},{label:"CPF",done:!!((C=u==null?void 0:u.cpf)!=null&&C.trim())},{label:"Data de nascimento",done:!!(u!=null&&u.birth_date)},{label:"Cidade",done:!!((x=u==null?void 0:u.city)!=null&&x.trim())}])},[]);if(s.useEffect(()=>{i();const c=()=>i();return window.addEventListener("perfil-updated",c),()=>window.removeEventListener("perfil-updated",c)},[i]),!a)return null;const v=Math.round(a.filter(c=>c.done).length/a.length*100);return v===100?e.jsxs("p",{className:"mb-4 flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(Ae,{className:"h-4 w-4 text-primary"})," Cadastro completo"]}):e.jsx(Z,{className:"mb-4",children:e.jsxs(K,{className:"space-y-3 p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("p",{className:"font-semibold",children:["Seu cadastro está ",v,"% completo"]}),e.jsx(k,{size:"sm",onClick:t,children:"Completar cadastro"})]}),e.jsx("div",{className:"h-2 w-full rounded-full bg-muted",children:e.jsx("div",{className:"h-2 rounded-full bg-primary transition-all",style:{width:`${v}%`}})}),e.jsx("div",{className:"flex flex-wrap gap-x-4 gap-y-1 text-xs",children:a.map(c=>e.jsxs("span",{className:c.done?"flex items-center gap-1 text-muted-foreground":"flex items-center gap-1",children:[c.done?e.jsx(Ae,{className:"h-3.5 w-3.5 text-primary"}):e.jsx(kt,{className:"h-3.5 w-3.5"}),c.label]},c.label))})]})})}const Zt=t=>new Intl.NumberFormat("pt-BR",{style:"currency",currency:"BRL"}).format(t||0),Kt={confirmed:{label:"Confirmada",cls:"bg-green-500/10 text-green-700 border-green-500/30"},pending:{label:"Pendente",cls:"bg-yellow-500/10 text-yellow-700 border-yellow-500/30"},cancelled:{label:"Cancelada",cls:"bg-red-500/10 text-red-700 border-red-500/30"}};function oa(){it();const[t,a]=ot(),l=ct();s.useEffect(()=>{t.get("tab")==="comunidade"&&Te(Le("/wanderlust"))},[t,l]);const{user:i,loading:v,signOut:c}=dt(),{hasAccess:u,loading:N}=ut(),[j,A]=s.useState("email"),[m,C]=s.useState("input"),[x,D]=s.useState(""),[p,E]=s.useState(""),[_,f]=s.useState(""),[R,V]=s.useState(!1),[Q,J]=s.useState([]),[le,n]=s.useState(!1),[W,y]=s.useState(null),q=async r=>{y(r.id);const{data:h,error:B}=await w.functions.invoke("mp-refund-payment",{body:{bookingId:r.id}});if(y(null),B||h!=null&&h.error){const T=h==null?void 0:h.error,z=T==="too_late"?"A reserva já iniciou. Fale com o suporte.":T==="already_cancelled"?"Esta reserva já está cancelada.":T==="mp_refund_failed"?"O adquirente recusou o estorno. Tente novamente em alguns minutos.":"Não foi possÃvel cancelar. Tente novamente.";return S.error(z)}const g=h==null?void 0:h.refund;(g==null?void 0:g.percent)>0?S.success(`Reserva cancelada. Estorno de ${g.percent}% (R$ ${Number(g.amount).toFixed(2)}) enviado ao Mercado Pago.`,{description:"Pix cai em minutos. Cartão pode levar até 2 faturas, conforme o banco."}):S.success("Reserva cancelada. Sem reembolso conforme polÃtica."),J(T=>T.map(z=>z.id===r.id?{...z,status:"cancelled",refund_amount:(g==null?void 0:g.amount)??0,refund_percent:(g==null?void 0:g.percent)??0,refunded_at:(g==null?void 0:g.percent)>0?new Date().toISOString():null}:z))};s.useEffect(()=>
30{i&&(u||(n(!0),w.rpc("profile_prefill_from_booking").then(()=>w.from("bookings").select("id,customer_name,customer_email,total_amount,status,start_date,end_date,start_at,end_at,has_insurance,refund_amount,refund_percent,refunded_at,locations(airport_code,category)").order("created_at",{ascending:!1}).then(({data:r,error:h})=>{h&&S.error(h.message),J(r||[]),n(!1)}))))},[i,u]);const Y=async r=>{r.preventDefault(),V(!0);const h=j==="email"?"send-otp-reservas":"send-otp-whatsapp",B=j==="email"?{email:x}:{phone:p},{error:g}=await w.functions.invoke(h,{body:B});if(V(!1),g)return S.error("Não foi possÃvel enviar o código. Tente novamente.");S.success(j==="email"?"Se houver uma reserva com esse e-mail, enviaremos o código.":"Se houver uma reserva com esse WhatsApp, enviaremos o código."),C("otp")},O=async r=>{if(r.preventDefault(),_.length<6)return;if(V(!0),j==="email"){let{error:T}=await w.auth.verifyOtp({email:x,token:_,type:"email"});if(T&&({error:T}=await w.auth.verifyOtp({email:x,token:_,type:"recovery"})),V(!1),T)return S.error(T.message);S.success("Acesso confirmado!");return}const{data:h,error:B}=await w.functions.invoke("verify-otp-whatsapp",{body:{phone:p,code:_}});if(V(!1),B||!(h!=null&&h.access_token))return S.error("Código inválido ou expirado.");const{error:g}=await w.auth.setSession({access_token:h.access_token,refresh_token:h.refresh_token});if(g)return S.error(g.message);S.success("Acesso confirmado!")};return v||i&&N?e.jsx("div",{className:"min-h-screen flex items-center justify-center",children:e.jsx(ne,{className:"h-6 w-6 animate-spin"})}):i&&u?e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center p-4",children:e.jsxs("div",{className:"w-full max-w-md
30space-y-6",children:[e.jsx(re,{to:"/","aria-label":"xpark, voltar para a home",className:"block",children:e.jsx(Me,{})}),e.jsxs(Z,{children:[e.jsxs(ge,{className:"text-center",children:[e.jsx("div",{className:"mx-auto h-12 w-12 rounded-full bg-primary/10 flex items-center justify-center mb-2",children:e.jsx(Re,{className:"h-6 w-6 text-primary"})}),e.jsx(ve,{children:"Ãrea exclusiva de clientes"}),e.jsx(je,{children:"Você está logado como administrador. Use o Painel Admin para consultar reservas."})]}),e.jsxs(K,{className:"space-y-3",children:[e.jsx(k,{asChild:!0,className:"w-full",children:e.jsx(re,{to:"/admin/reservas",children:"Ir para o Painel Admin"})}),e.jsxs(k,{variant:"outline",className:"w-full",onClick:()=>c(),children:[e.jsx(Oe,{className:"mr-2 h-4 w-4"})," Sair"]})]})]})]})}):i?e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx("header",{className:"border-b",children:e.jsxs("div",{className:"max-w-4xl mx-auto px-4 py-4 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-bold",children:"Minhas reservas"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i.email})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(k,{variant:"outline",size:"sm",asChild:!0,children:e.jsxs(re,{to:"/",children:[e.jsx(mt,{className:"h-4 w-4 mr-2"})," InÃcio"]})}),e.jsxs(k,{variant:"outline",size:"sm",onClick:c,children:[e.jsx(Oe,{className:"h-4 w-4 mr-2"})," Sair"]})]})]})}),e.jsxs("main",{className:"max-w-4xl mx-auto p-4",children:[e.jsx(Xt,{onComplete:()=>a({tab:"perfil",edit:"1"},{replace:!0})}),e.jsxs(Ie,{value:t.get("tab")||"reservas",onValueChange:r=>r==="comunidade"?Te(Le("/wanderlust")):a({tab:r},{replace:!0}),children:[e.jsxs($e,{className:"mb-4 grid w-full grid-cols-4",children:[e.jsx(ce,{value:"reservas",children:"Reservas"}),e.jsx(ce,{value:"perfil",children:"Meu perfil"}),e.jsx(ce,{value:"viajante",children:"Diária grátis"}),e.jsx(ce,{value:"comunidade",children:"Wanderlust"})]}),e.jsx(pe,{value:"perfil",children:e.jsx(Gt,{userId:i.id,email:i.email??null,startEditing:t.get("edit")==="1"},t.get("edit")||"v")}),e.jsx(pe,{value:"viajante",children:e.jsx(Ut,{})}),e.jsx(pe,{value:"reservas",className:"space-y-3",children:le?e.jsx("div",{className:"flex justify-center py-10",children:e.jsx(ne,{className:"h-6 w-6 animate-spin"})}):Q.length===0?e.jsx(Z,{children:e.jsx(K,{className:"py-10 text-center text-muted-foreground",children:"Nenhuma reserva encontrada para este e-mail."})}):Q.map(r=>{var B;const h=Kt[r.status]||{label:r.status,cls:""};return e.jsx(Z,{children:e.jsxs(K,{className:"p-4 flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"font-semibold",children:[r.start_date," â ",r.end_date]}),e.jsx(be,{variant:"outline",className:h.cls,children:h.label}),r.has_insurance&&e.jsxs(be,{variant:"outline",className:"bg-emerald-500/10 text-emerald-700 border-emerald-500/30",children:[e.jsx(Re,{className:"mr-1 h-3 w-3"}),"Seguro"]})]}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:[r.start_at?`Entrada ${new Date(r.start_at).toLocaleString("pt-BR")}`:"",r.end_at?` ⢠SaÃda ${new Date(r.end_at).toLocaleString("pt-BR")}`:""]}),e.jsx("div",{className:"text-xs font-mono text-muted-foreground",children:pt(r.id,((B=r.locations)==null?void 0:B.airport_code)??"XX")})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:"font-bold",children:Zt(Number(r.total_amount))}),e.jsx(re,{to:`/confirmacao?bookingId=${r.id}`,className:"text-xs text-primary hover:underline",children:"Ver detalhes"}),e.jsxs("div",{className:"mt-1 flex items-center justify-end gap-1",children:[Qt(r)&&e.jsx(k,{asChild:!0,variant:"ghost",size:"sm",className:"h-7 px-2 text-xs",children:e.jsxs(re,{to:`/minhas-reservas/${r.id}/alterar`,children:[e.jsx(St,{className:"mr-1 h-3.5 w-3.5"})," Alterar"]})}),Jt(r,W,q)]})]})]})},r.id)})})]})]})]}):e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center p-4",children:e.jsxs("div",{className:"w-full max-w-md
30space-y-6",children:[e.jsx(re,{to:"/","aria-label":"xpark, voltar para a home",className:"block",children:e.jsx(Me,{})}),e.jsxs(Z,{children:[e.jsxs(ge,{className:"text-center",children:[e.jsx("div",{className:"mx-auto h-12 w-12 rounded-full bg-primary/10 flex items-center justify-center mb-2",children:e.jsx(Be,{className:"h-6 w-6 text-primary"})}),e.jsx(ve,{children:"Minhas reservas"}),e.jsx(je,{children:m==="input"?j==="email"?"Digite seu e-mail para receber um código de acesso.":"Digite seu WhatsApp para receber um código de acesso.":`Código enviado ${j==="email"?`para ${x}`:`no WhatsApp ${p}`}.`})]}),e.jsx(K,{children:m==="input"?e.jsxs(Ie,{value:j,onValueChange:r=>A(r),children:[e.jsxs($e,{className:"grid grid-cols-2 w-full mb-3",children:[e.jsxs(ce,{value:"email",children:[e.jsx(Be,{className:"h-4 w-4 mr-1"})," E-mail"]}),e.jsxs(ce,{value:"whatsapp",children:[e.jsx(_t,{className:"h-4 w-4 mr-1"})," WhatsApp"]})]}),e.jsxs("form",{onSubmit:Y,className:"space-y-3",children:[e.jsxs(pe,{value:"email",className:"mt-0 space-y-1",children:[e.jsx(X,{htmlFor:"email",children:"E-mail"}),e.jsx($,{id:"email",type:"email",required:j==="email",value:x,onChange:r=>D(r.target.value)})]}),e.jsxs(pe,{value:"whatsapp",className:"mt-0 space-y-1",children:[e.jsx(X,{htmlFor:"phone",children:"WhatsApp (com DDD)"}),e.jsx($,{id:"phone",type:"tel",inputMode:"tel",placeholder:"(11) 99999-9999",required:j==="whatsapp",value:p,onChange:r=>E(r.target.value)})]}),e.jsxs(k,{type:"submit",className:"w-full",disabled:R,children:[R&&e.jsx(ne,{className:"mr-2 h-4 w-4 animate-spin"}),"Enviar código"]})]})]}):e.jsxs("form",{onSubmit:O,className:"space-y-4",children:[e.jsx("div",{className:"flex justify-center",children:e.jsx(Ue,{maxLength:6,value:_,onChange:f,children:e.jsx(Xe,{children:[0,1,2,3,4,5].map(r=>e.jsx(Ze,{index:r},r))})})}),e.jsxs(k,{type:"submit",className:"w-full",disabled:R||_.length<6,children:[R&&e.jsx(ne,{className:"mr-2 h-4 w-4 animate-spin"}),"Entrar"]}),e.jsx(k,{type:"button",variant:"ghost",className:"w-full",onClick:()=>{C("input"),f("")},children:"Voltar"})]})})]})]})})}function Qt(t){return t.status!=="confirmed"||!t.end_at?!1:new Date(t.end_at).getTime()>Date.now()}function Jt(t,a,l){const i=t.start_at?new Date(t.start_at).getTime()<=Date.now():!1;return t.status==="cancelled"||t.status!=="confirmed"?null:i?e.jsx("div",{className:"mt-1 text-[11px] text-muted-foreground",children:"Reserva em andamento"}):e.jsx(Yt,{booking:t,busy:a===t.id,onConfirm:()=>l(t)})}function Yt({booking:t,busy:a,onConfirm:l}){const i=ht(t.start_at,Number(t.total_amount),{hasInsurance:!!t.has_insurance});return e.jsxs(xt,{children:[e.jsx(gt,{asChild:!0,children:e.jsxs(k,{variant:"ghost",size:"sm",className:"mt-1 h-7 px-2 text-xs text-red-600 hover:text-red-700",children:[e.jsx(ft,{className:"mr-1 h-3.5 w-3.5"})," Cancelar"]})}),e.jsxs(vt,{children:[e.jsxs(jt,{children:[e.jsx(bt,{children:"Cancelar esta reserva?"}),e.jsx(yt,{asChild:!0,children:e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("p",{children:["Conforme a"," ",e.jsx(re,{to:"/politica-cancelamento",className:"underline",target:"_blank",children:"polÃtica de cancelamento"}),", você tem direito a ",e.jsxs("strong",{children:[i.percent,"%"]})," de reembolso sobre o valor da estadia (",i.label,")."]}),e.jsxs("p",{children:["Valor a ser estornado no seu método de pagamento:"," ",e.jsxs("strong",{children:["R$ ",i.amount.toFixed(2)]}),"."]}),t.has_insurance&&e.jsxs("p",{className:"rounded-md border border-amber-500/30 bg-amber-500/10 p-2 text-xs text-amber-900",children:["O prêmio do ",e.jsxs("strong",{children:["Seguro Cancelamento (R$ ",i.insuranceRetained.toFixed(2),")"]})," não é reembolsado neste cancelamento voluntário. Se o motivo foi ",e.jsx("em",{children:"atraso ou cancelamento de voo"}),", fale com o suporte com o comprovante para acionar a cobertura de 100%."]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"O estorno é enviado ao adquirente na hora. O crédito na fatura ou conta pode levar alguns dias úteis, conforme o banco."})]})})]}),e.jsxs(wt,{children:[e.jsx(Nt,{children:"Voltar"}),e.jsxs(Ct,{disabled:a,onClick:l,children:[a&&e.jsx(ne,{className:"mr-2 h-4 w-4 animate-spin"}),"Confirmar cancelamento"]})]})]})]})}export{oa 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.