import{a as L,r as y,j as e,S as k,B as A,f as D}from"./index-C46kOBpe.js";import{P as O}from"./PDFButton-keVK483j.js";import{L as c}from"./label-D4ZlDvwA.js";import{I as h}from"./input-CCh-sQpH.js";import{C as Z}from"./checkbox-CilzIk67.js";import{S as z,a as U,b as G,c as B,d as M}from"./select-DlM-h14j.js";import{C as R}from"./calendar-DGj-U-RB.js";import{P as $,a as q,b as V}from"./popover-CLahGHb3.js";import{i as _}from"./invoke-edge-function-DPT5cB0t.js";import{F as T}from"./file-text-B15bEwFP.js";import{D as E}from"./download-BjYtnUE1.js";import{C as H}from"./calendar-DoTvn_03.js";import{L as J}from"./loader-circle-D7HCV8OP.js";import"./index-KmGUDj83.js";import"./check-1ulS23lx.js";import"./index-BdQq_4o_.js";import"./index-IM00Yku_.js";import"./Combination-B-QjAX7a.js";import"./chevron-up-DSDJpk1L.js";import"./chevron-right-Dw8heQeD.js";import"./chevron-left-Bj_0FVu4.js";import"./supabase-edge-DhGEu5kl.js";const F=new Date().toLocaleDateString("en-US",{month:"2-digit",day:"2-digit",year:"numeric"}),Y=[{value:"family-visits-515-561",label:"1. Family Visits (515.561) — General License Family Visit"},{value:"us-government-official-515-562",label:"2. Official Business of the U.S. Government, Foreign Governments & Certain Intergovernmental Organizations (515.562)"},{value:"journalistic-515-563",label:"3. Journalistic Activities (515.563) — General License Journalistic Activities in Cuba"},{value:"professional-research-515-564-1",label:"4(1). Professional Research (515.564) — General License for Professional Research"},{value:"professional-meetings-515-564-2",label:"4(2). Professional Meetings (515.564) — General License for Professional Meetings"},{value:"educational-activities-515-565-a",label:"5(a). Educational Activities (515.565) — General License for Educational Activities"},{value:"people-to-people-515-565-b",label:"5(b). People-to-People Travel (515.565) — General License for People-to-People Travel"},{value:"religious-515-566",label:"6. Religious Activities (515.566) — General License Religious Activities in Cuba"},{value:"sports-competitions-515-567-a",label:"7(a). Amateur & Semi-Professional International Sports Federation Competitions (515.567)"},{value:"public-performances-515-567-b",label:"7(b). Public Performances, Clinics, Workshops, Athletic & Non-Athletic Competitions, and Exhibitions (515.567)"},{value:"support-cuban-people-515-574",label:"8. Support for the Cuban People (515.574) — General License Support for the Cuban People"},{value:"humanitarian-515-575",label:"9. Humanitarian Projects (515.575) — General License Humanitarian Projects"},{value:"private-foundations-515-576",label:"10. Activities of Private Foundations or Research or Educational Institutes (515.576)"},{value:"informational-materials-515-545",label:"11. Exportation, Importation, or Transmission of Information or Informational Materials (515.545)"},{value:"export-transactions-515-533-1",label:"12a. Exportations from the United States to Cuba; Re-exportations to Cuba (515.533 & 515.559)"},{value:"export-transactions-515-533-2",label:"12b. Certain Export and Import Transactions by U.S. Owned or Controlled Foreign Firms (515.533 & 515.559)"},{value:"specific-license",label:"13. Specific License from OFAC"}],W={"family-visits-515-561":"Family Visits","us-government-official-515-562":"Official Business","journalistic-515-563":"Journalist Activities","professional-research-515-564-1":"Professional Research 1","professional-meetings-515-564-2":"Professional Research 2","educational-activities-515-565-a":"Educational Activities 1","people-to-people-515-565-b":"Educational Activities 2","religious-515-566":"Religious Activities","sports-competitions-515-567-a":"Public Performance 1","public-performances-515-567-b":"Public Performance 2","support-cuban-people-515-574":"Support Cuban People","humanitarian-515-575":"Humanitarian Projects","private-foundations-515-576":"Private Foundation","informational-materials-515-545":"Transmision of Information","export-transactions-515-533-1":"Exports Imports 1","export-transactions-515-533-2":"Exports Imports 2","specific-license":"Specific License"},o={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",licenseNumber:"license"};async function X(s){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 r=await a.arrayBuffer();let m;try{m=await O.load(r)}catch{throw new Error("The affidavit PDF template could not be read. Please contact support.")}const v=m.getForm(),i=(l,j)=>{try{v.getTextField(l).setText(j)}catch{console.warn(`[AffidavitPDF] Text field not found: "${l}"`)}},b=l=>{try{v.getCheckBox(l).check()}catch{console.warn(`[AffidavitPDF] Checkbox not found: "${l}"`)}};i(o.firstName,s.firstName),i(o.lastName,s.lastName),i(o.streetAddress,s.streetAddress),i(o.phone,s.phone),i(o.email,s.email),i(o.travelDate,s.travelDate?D(new Date(s.travelDate+"T00:00:00"),"MM/dd/yyyy"):""),i(o.todayDate,F);const u=s.cityStateZip.match(/^(.+),\s*([A-Za-z]{2})\s+(\S+)$/);u?(i(o.city,u[1].trim()),i(o.state,u[2].trim()),i(o.zip,u[3].trim())):i(o.city,s.cityStateZip),s.category==="specific-license"&&s.licenseNumber&&i(o.licenseNumber,s.licenseNumber),b("Certify");const N=W[s.category];N&&b(N),v.flatten();const g=await m.save();let n="";for(let l=0;l<g.byteLength;l++)n+=String.fromCharCode(g[l]);return btoa(n)}const P=s=>s.replace(/\b\w/g,a=>a.toUpperCase()),I={category:"",licenseNumber:"",firstName:"",lastName:"",streetAddress:"",cityStateZip:"",phone:"",email:"",travelDate:"",certified:!1};function ye(){const{toast:s}=L(),[a,x]=y.useState(I),[r,m]=y.useState({}),[v,i]=y.useState(!1),[b,u]=y.useState(null),[N,g]=y.useState(!1),n=t=>x(p=>({...p,...t})),l=()=>{const t={};return a.category||(t.category="Please select an authorized travel category."),a.category==="specific-license"&&!a.licenseNumber.trim()&&(t.licenseNumber="OFAC license number is required."),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},j=async t=>{t.preventDefault();const p=l();if(m(p),!(Object.keys(p).length>0)){i(!0);try{const C=await X(a),{data:S,errorMessage:w}=await _("submit-travel-affidavit",{formData:{category:a.category,licenseNumber:a.licenseNumber,firstName:a.firstName,lastName:a.lastName,streetAddress:a.streetAddress,cityStateZip:a.cityStateZip,phone:a.phone,email:a.email,travelDate:a.travelDate,todayDate:F},pdfBase64:C});if(w||!(S!=null&&S.downloadUrl)){s({title:"Submission failed",description:w??"Unable to process your affidavit. Please try again.",variant:"destructive"});return}u(S.downloadUrl),s({title:"Affidavit submitted",description:"Check your email for a copy."})}catch(C){s({title:"Error generating affidavit",description:C instanceof Error?C.message:"An unexpected error occurred. Please try again.",variant:"destructive"})}finally{i(!1)}}},d=t=>r[t]?e.jsx("p",{id:`${t}-error`,className:"text-xs text-destructive mt-1",role:"alert",children:r[t]}):null,f=t=>({"aria-invalid":!!r[t],"aria-describedby":r[t]?`${t}-error`:void 0,className:"mt-1.5"});return e.jsxs("div",{"data-name":"CTSTravelAffidavitPage",className:"section-padding bg-background",children:[e.jsx(k,{title:"CTS Travel Affidavit",description:"Complete your OFAC Travel Affidavit online. Select your authorized travel category, fill in your details, and download your signed affidavit PDF.",path:"/cts-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(T,{className:"w-7 h-7 text-primary"}),e.jsx("h1",{className:"heading-section text-foreground",children:"CTS 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.jsxs("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."," ",e.jsx("a",{href:"https://www.ecfr.gov/current/title-31/subtitle-B/chapter-V/part-515/subpart-E/section-515.560",target:"_blank",rel:"noopener noreferrer",className:"text-primary underline underline-offset-2",children:"Full description of OFAC Categories"})]})]}),b?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(E,{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:b,target:"_blank",rel:"noopener noreferrer",download:!0,children:e.jsxs(A,{variant:"accent",size:"lg",className:"gap-2 px-10 my-4 text-base",children:[e.jsx(E,{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(I),m({}),u(null)},className:"text-primary underline underline-offset-2",children:"Start over"})]})]}):e.jsxs("form",{onSubmit:j,noValidate:!0,className:"space-y-6",children:[e.jsxs("div",{children:[e.jsxs(c,{htmlFor:"category",className:"font-sans text-sm font-medium",children:["I have selected the applicable authorized category of travel below."," ",e.jsx("span",{className:"text-destructive","aria-hidden":"true",children:"*"})]}),e.jsxs(z,{value:a.category,onValueChange:t=>n({category:t,licenseNumber:""}),children:[e.jsx(U,{id:"category",className:"mt-1.5","aria-invalid":!!r.category,"aria-describedby":r.category?"category-error":void 0,children:e.jsx(G,{placeholder:"Select an authorized travel category"})}),e.jsx(B,{className:"bg-popover border border-border z-50 max-h-[320px]",children:Y.map(t=>e.jsx(M,{value:t.value,className:"cursor-pointer",children:t.label},t.value))})]}),d("category")]}),a.category==="specific-license"&&e.jsxs("div",{children:[e.jsxs(c,{htmlFor:"licenseNumber",className:"font-sans text-sm font-medium",children:["OFAC License Number ",e.jsx("span",{className:"text-destructive","aria-hidden":"true",children:"*"})]}),e.jsx(h,{id:"licenseNumber",type:"text",value:a.licenseNumber,onChange:t=>n({licenseNumber:t.target.value}),placeholder:"Enter your OFAC license number",...f("licenseNumber")}),d("licenseNumber")]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(c,{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:F})]}),e.jsxs("div",{children:[e.jsxs(c,{className:"font-sans text-sm font-medium",children:["Travel Date ",e.jsx("span",{className:"text-destructive","aria-hidden":"true",children:"*"})]}),e.jsxs($,{open:N,onOpenChange:g,children:[e.jsx(q,{asChild:!0,children:e.jsxs(A,{type:"button",variant:"outline",className:`mt-1.5 w-full justify-start text-left font-normal bg-white${r.travelDate?" border-destructive":""}`,"aria-invalid":!!r.travelDate,"aria-describedby":r.travelDate?"travelDate-error":void 0,children:[e.jsx(H,{className:"mr-2 h-4 w-4"}),a.travelDate?D(new Date(a.travelDate+"T00:00:00"),"PPP"):"Select travel date"]})}),e.jsx(V,{className:"w-auto p-0",align:"start",children:e.jsx(R,{mode:"single",selected:a.travelDate?new Date(a.travelDate+"T00:00:00"):void 0,onSelect:t=>{t&&n({travelDate:D(t,"yyyy-MM-dd")}),g(!1)},disabled:t=>{const p=new Date;return p.setHours(0,0,0,0),t<p},initialFocus:!0})})]}),d("travelDate")]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs(c,{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=>n({firstName:P(t.target.value)}),...f("firstName")}),d("firstName")]}),e.jsxs("div",{children:[e.jsxs(c,{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=>n({lastName:P(t.target.value)}),...f("lastName")}),d("lastName")]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs(c,{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=>n({phone:t.target.value.replace(/[^\d\s\-+().]/g,"")}),...f("phone")}),d("phone")]}),e.jsxs("div",{children:[e.jsxs(c,{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=>n({email:t.target.value}),onBlur:()=>{a.email.trim()&&(/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(a.email.trim())?m(t=>({...t,email:void 0})):m(t=>({...t,email:"Enter a valid email address."})))},...f("email")}),d("email")]})]}),e.jsxs("div",{children:[e.jsxs(c,{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=>n({streetAddress:P(t.target.value)}),...f("streetAddress")}),d("streetAddress")]}),e.jsxs("div",{children:[e.jsxs(c,{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=>n({cityStateZip:P(t.target.value)}),placeholder:"e.g. Miami, FL 33101",...f("cityStateZip")}),d("cityStateZip")]}),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(Z,{id:"certified",checked:a.certified,onCheckedChange:t=>n({certified:t===!0}),"aria-invalid":!!r.certified,"aria-describedby":r.certified?"certified-error":void 0,className:"mt-0.5"}),e.jsx("div",{children:e.jsxs(c,{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:"*"})]})})]}),r.certified&&e.jsx("p",{id:"certified-error",className:"text-xs text-destructive mt-2 ml-7",role:"alert",children:r.certified})]}),e.jsx(A,{type:"submit",variant:"accent",size:"lg",className:"w-full gap-2",disabled:v,children:v?e.jsxs(e.Fragment,{children:[e.jsx(J,{className:"h-4 w-4 animate-spin"}),"Generating affidavit…"]}):e.jsxs(e.Fragment,{children:[e.jsx(T,{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{ye as default};