import{a as Z,r as y,j as e,S as I,B as S,f as w}from"./index-BvScfu38.js";import{P as L}from"./PDFButton-DqnibbZE.js";import{L as n}from"./label-cl6SqZ88.js";import{I as h}from"./input-D6WWL6Uo.js";import{C as O}from"./checkbox-Dd8UrG6n.js";import{S as U,a as z,b as B,c as $,d as M}from"./select-DiVJ41hb.js";import{C as _}from"./calendar-CdrtdVRl.js";import{P as q,a as Y,b as G}from"./popover-BWg-HYGO.js";import{i as R}from"./invoke-edge-function-ChoasWOl.js";import{F as P}from"./file-text-D-WAVvKX.js";import{D as F}from"./download-DR7IY-sB.js";import{C as X}from"./calendar-Cg3JMX-_.js";import{L as V}from"./loader-circle-BsLEe2LX.js";import"./index-DrZ9l3B6.js";import"./check-r6UxZW48.js";import"./index-BdQq_4o_.js";import"./index-vYIIW9nq.js";import"./Combination-Bd5dM9qe.js";import"./chevron-up-C1jEjITK.js";import"./chevron-right-D6Dy8xzN.js";import"./chevron-left-Cc9uyIjm.js";import"./supabase-edge-DhGEu5kl.js";const T=new Date().toLocaleDateString("en-US",{month:"2-digit",day:"2-digit",year:"numeric"}),H="people-to-people-515-565-b",K="People-to-People Travel (515.565) — b). General License for People-to-People Travel",W="Educational Activities 2",J=["Cuba: A Cultural Odyssey"],d={firstName:"First Name",lastName:"Last Name",streetAddress:"Street Address",city:"City",state:"State",zip:"Zip",phone:"Phone Number",email:"Email",travelDate:"Travel Date",todayDate:"Today Date"};async function Q(r){const a=await fetch("/documents/affidavit-template.pdf"),x=a.headers.get("content-type")??"";if(!a.ok||!x.includes("pdf")&&!x.includes("octet-stream"))throw new Error("The affidavit PDF template is missing. Please contact support.");const i=await a.arrayBuffer();let l;try{l=await L.load(i)}catch{throw new Error("The affidavit PDF template could not be read. Please contact support.")}const f=l.getForm(),o=(s,C)=>{try{f.getTextField(s).setText(C)}catch{console.warn(`[AffidavitPDF] Text field not found: "${s}"`)}},v=s=>{try{f.getCheckBox(s).check()}catch{console.warn(`[AffidavitPDF] Checkbox not found: "${s}"`)}};o(d.firstName,r.firstName),o(d.lastName,r.lastName),o(d.streetAddress,r.streetAddress),o(d.phone,r.phone),o(d.email,r.email),o(d.travelDate,r.travelDate?w(new Date(r.travelDate+"T00:00:00"),"MM/dd/yyyy"):""),o(d.todayDate,T);const m=r.cityStateZip.match(/^(.+),\s*([A-Za-z]{2})\s+(\S+)$/);m?(o(d.city,m[1].trim()),o(d.state,m[2].trim()),o(d.zip,m[3].trim())):o(d.city,r.cityStateZip),v("Certify"),v(W),f.flatten();const g=await l.save();let N="";for(let s=0;s<g.byteLength;s++)N+=String.fromCharCode(g[s]);return btoa(N)}const D=r=>r.replace(/\b\w/g,a=>a.toUpperCase()),E={tourName:"",firstName:"",lastName:"",streetAddress:"",cityStateZip:"",phone:"",email:"",travelDate:"",certified:!1};function be(){const{toast:r}=Z(),[a,x]=y.useState(E),[i,l]=y.useState({}),[f,o]=y.useState(!1),[v,m]=y.useState(null),[g,N]=y.useState(!1),s=t=>x(u=>({...u,...t})),C=()=>{const t={};return a.tourName||(t.tourName="Please select a tour name."),a.firstName.trim()||(t.firstName="First name is required."),a.lastName.trim()||(t.lastName="Last name is required."),a.streetAddress.trim()||(t.streetAddress="Street address is required."),a.cityStateZip.trim()||(t.cityStateZip="City, State, Zip is required."),a.phone.trim()?/^[\d\s\-+().]{7,20}$/.test(a.phone.trim())||(t.phone="Enter a valid phone number."):t.phone="Phone number is required.",a.email.trim()?/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(a.email.trim())||(t.email="Enter a valid email address."):t.email="Email address is required.",a.travelDate||(t.travelDate="Travel date is required."),a.certified||(t.certified="You must certify the information is true and correct."),t},k=async t=>{t.preventDefault();const u=C();if(l(u),!(Object.keys(u).length>0)){o(!0);try{const j=await Q(a),{data:b,errorMessage:A}=await R("submit-travel-affidavit",{formData:{source:"tauck",category:H,tourName:a.tourName,firstName:a.firstName,lastName:a.lastName,streetAddress:a.streetAddress,cityStateZip:a.cityStateZip,phone:a.phone,email:a.email,travelDate:a.travelDate,todayDate:T},pdfBase64:j});if(A||!(b!=null&&b.downloadUrl)){r({title:"Submission failed",description:A??"Unable to process your affidavit. Please try again.",variant:"destructive"});return}m(b.downloadUrl),r({title:"Affidavit submitted",description:"Check your email for a copy."})}catch(j){r({title:"Error generating affidavit",description:j instanceof Error?j.message:"An unexpected error occurred. Please try again.",variant:"destructive"})}finally{o(!1)}}},c=t=>i[t]?e.jsx("p",{id:`${t}-error`,className:"text-xs text-destructive mt-1",role:"alert",children:i[t]}):null,p=t=>({"aria-invalid":!!i[t],"aria-describedby":i[t]?`${t}-error`:void 0,className:"mt-1.5"});return e.jsxs("div",{"data-name":"TauckTravelAffidavitPage",className:"section-padding bg-background",children:[e.jsx(I,{title:"Tauck Travel Affidavit",description:"Complete your Tauck Travel Affidavit for Cuba travel. Select your tour, enter your OFAC travel category and trip details, and download your signed PDF.",path:"/tauck-travel-affidavit"}),e.jsxs("div",{className:"container-luxury max-w-2xl mx-auto",children:[e.jsxs("div",{className:"mb-8",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx(P,{className:"w-7 h-7 text-primary"}),e.jsx("h1",{className:"heading-section text-foreground",children:"Tauck Travel Affidavit"})]}),e.jsx("p",{className:"font-sans text-sm text-muted-foreground",children:"I understand that travel transactions related to Cuba must be directly incident to one of the self-authorizing general license purposeful travel categories or travel authorized under the auspice of a specific license granted on a case-by-case basis. Under current US travel restrictions with respect to Cuba, travel-related transactions are prohibited except for the 12 authorized categories below."}),e.jsx("p",{className:"font-sans text-sm text-muted-foreground mt-2",children:"I declare that I fall under the category I have selected below and that I meet the criteria of the selected travel category under U.S. regulations."})]}),v?e.jsxs("div",{className:"rounded-lg border border-border bg-secondary/30 p-8 text-center space-y-4",children:[e.jsx("div",{className:"flex justify-center",children:e.jsx("div",{className:"flex h-16 w-16 items-center justify-center rounded-full bg-primary/10",children:e.jsx(F,{className:"h-8 w-8 text-primary"})})}),e.jsx("h2",{className:"font-serif text-xl text-foreground",children:"Your affidavit is ready"}),e.jsxs("p",{className:"font-sans text-sm text-muted-foreground",children:["A copy has been sent to ",e.jsx("strong",{children:a.email}),". Use the button below to download your signed affidavit. This link is valid for 24 hours."]}),e.jsx("a",{href:v,target:"_blank",rel:"noopener noreferrer",download:!0,children:e.jsxs(S,{variant:"accent",size:"lg",className:"gap-2 px-10 my-4 text-base",children:[e.jsx(F,{className:"h-4 w-4"}),"Download Affidavit PDF"]})}),e.jsxs("p",{className:"font-sans text-xs text-muted-foreground",children:["Need to submit another?"," ",e.jsx("button",{type:"button",onClick:()=>{x(E),l({}),m(null)},className:"text-primary underline underline-offset-2",children:"Start over"})]})]}):e.jsxs("form",{onSubmit:k,noValidate:!0,className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx(n,{className:"font-sans text-sm font-medium",children:"I have selected the applicable authorized category of travel below."}),e.jsx("p",{className:"mt-1.5 font-sans text-sm text-foreground bg-muted rounded-md border border-input px-3 py-2",children:K})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(n,{className:"font-sans text-sm font-medium",children:"Today's Date"}),e.jsx("p",{className:"mt-1.5 font-sans text-sm text-foreground bg-muted rounded-md border border-input px-3 py-2",children:T})]}),e.jsxs("div",{children:[e.jsxs(n,{className:"font-sans text-sm font-medium",children:["Travel Date ",e.jsx("span",{className:"text-destructive","aria-hidden":"true",children:"*"})]}),e.jsxs(q,{open:g,onOpenChange:N,children:[e.jsx(Y,{asChild:!0,children:e.jsxs(S,{type:"button",variant:"outline",className:`mt-1.5 w-full justify-start text-left font-normal bg-white${i.travelDate?" border-destructive":""}`,"aria-invalid":!!i.travelDate,"aria-describedby":i.travelDate?"travelDate-error":void 0,children:[e.jsx(X,{className:"mr-2 h-4 w-4"}),a.travelDate?w(new Date(a.travelDate+"T00:00:00"),"PPP"):"Select travel date"]})}),e.jsx(G,{className:"w-auto p-0",align:"start",children:e.jsx(_,{mode:"single",selected:a.travelDate?new Date(a.travelDate+"T00:00:00"):void 0,onSelect:t=>{t&&s({travelDate:w(t,"yyyy-MM-dd")}),N(!1)},disabled:t=>{const u=new Date;return u.setHours(0,0,0,0),t<u},initialFocus:!0})})]}),c("travelDate")]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs(n,{htmlFor:"firstName",className:"font-sans text-sm font-medium",children:["First Name ",e.jsx("span",{className:"text-destructive","aria-hidden":"true",children:"*"})]}),e.jsx(h,{id:"firstName",type:"text",autoComplete:"given-name",value:a.firstName,onChange:t=>s({firstName:D(t.target.value)}),...p("firstName")}),c("firstName")]}),e.jsxs("div",{children:[e.jsxs(n,{htmlFor:"lastName",className:"font-sans text-sm font-medium",children:["Last Name ",e.jsx("span",{className:"text-destructive","aria-hidden":"true",children:"*"})]}),e.jsx(h,{id:"lastName",type:"text",autoComplete:"family-name",value:a.lastName,onChange:t=>s({lastName:D(t.target.value)}),...p("lastName")}),c("lastName")]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs(n,{htmlFor:"phone",className:"font-sans text-sm font-medium",children:["Phone Number ",e.jsx("span",{className:"text-destructive","aria-hidden":"true",children:"*"})]}),e.jsx(h,{id:"phone",type:"tel",autoComplete:"tel",value:a.phone,onChange:t=>s({phone:t.target.value.replace(/[^\d\s\-+().]/g,"")}),...p("phone")}),c("phone")]}),e.jsxs("div",{children:[e.jsxs(n,{htmlFor:"email",className:"font-sans text-sm font-medium",children:["Email ",e.jsx("span",{className:"text-destructive","aria-hidden":"true",children:"*"})]}),e.jsx(h,{id:"email",type:"email",autoComplete:"email",value:a.email,onChange:t=>s({email:t.target.value}),onBlur:()=>{a.email.trim()&&(/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(a.email.trim())?l(t=>({...t,email:void 0})):l(t=>({...t,email:"Enter a valid email address."})))},...p("email")}),c("email")]})]}),e.jsxs("div",{children:[e.jsxs(n,{htmlFor:"streetAddress",className:"font-sans text-sm font-medium",children:["Street Address ",e.jsx("span",{className:"text-destructive","aria-hidden":"true",children:"*"})]}),e.jsx(h,{id:"streetAddress",type:"text",autoComplete:"street-address",value:a.streetAddress,onChange:t=>s({streetAddress:D(t.target.value)}),...p("streetAddress")}),c("streetAddress")]}),e.jsxs("div",{children:[e.jsxs(n,{htmlFor:"cityStateZip",className:"font-sans text-sm font-medium",children:["City, State, Zip ",e.jsx("span",{className:"text-destructive","aria-hidden":"true",children:"*"})]}),e.jsx(h,{id:"cityStateZip",type:"text",autoComplete:"address-level2",value:a.cityStateZip,onChange:t=>s({cityStateZip:D(t.target.value)}),placeholder:"e.g. Miami, FL 33101",...p("cityStateZip")}),c("cityStateZip")]}),e.jsxs("div",{children:[e.jsxs(n,{htmlFor:"tourName",className:"font-sans text-sm font-medium",children:["Tour Name ",e.jsx("span",{className:"text-destructive","aria-hidden":"true",children:"*"})]}),e.jsxs(U,{value:a.tourName,onValueChange:t=>s({tourName:t}),children:[e.jsx(z,{id:"tourName",className:"mt-1.5","aria-invalid":!!i.tourName,"aria-describedby":i.tourName?"tourName-error":void 0,children:e.jsx(B,{placeholder:"Select a tour"})}),e.jsx($,{className:"bg-popover border border-border z-50",children:J.map(t=>e.jsx(M,{value:t,className:"cursor-pointer",children:t},t))})]}),c("tourName")]}),e.jsxs("div",{className:"rounded-sm border border-border bg-secondary/40 p-5",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(O,{id:"certified",checked:a.certified,onCheckedChange:t=>s({certified:t===!0}),"aria-invalid":!!i.certified,"aria-describedby":i.certified?"certified-error":void 0,className:"mt-0.5"}),e.jsx("div",{children:e.jsxs(n,{htmlFor:"certified",className:"font-sans text-sm font-medium cursor-pointer",children:["I certify that the above information is true and correct"," ",e.jsx("span",{className:"text-destructive","aria-hidden":"true",children:"*"})]})})]}),i.certified&&e.jsx("p",{id:"certified-error",className:"text-xs text-destructive mt-2 ml-7",role:"alert",children:i.certified})]}),e.jsx(S,{type:"submit",variant:"accent",size:"lg",className:"w-full gap-2",disabled:f,children:f?e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"h-4 w-4 animate-spin"}),"Generating affidavit…"]}):e.jsxs(e.Fragment,{children:[e.jsx(P,{className:"h-4 w-4"}),"Submit & Download Affidavit"]})}),e.jsx("p",{className:"text-xs text-muted-foreground text-center font-sans",children:"Your affidavit will be emailed to you as a PDF attachment. Please retain a copy for your travel records."})]})]})]})}export{be as default};