1import{j as e}from"./data-DN-eP4ae.js";import{e as re,r as o}from"./react-BUOzgyp0.js";import{u as oe}from"./ModuleIntelligence-CujC5CDF.js";import{F as ae,L as ne}from"./lucide-react-DNZOCB6v.js";import{r as me}from"./page-primary-BUiSypsU.js";import{K as le,ce,n as p,ax as pe,bm as de,F as B,$ as d,_ as ue,c2 as xe,c3 as he,B as T,c4 as ge,c5 as c,ct as fe,dB as je,aA as ve,aB as be,aC as we,aD as Ne,av as O,dC as ye,bu as U,aT as Ce,bD as ke,aG as Fe}from"./index-6GUxm5Tl.js";import{T as Te,a as Se,b as q,c as x,d as Pe,e as h}from"./table-CeZUCHxF.js";import{b as De,c as Ae,d as Le,e as Ee,g as $e,f as Ie}from"./useForms-BIrUR2bK.js";import{E as Me}from"./EmptyState-ChyoO585.js";import{F as Re,a as _e}from"./form-templates-BNIRFACO.js";import{u as Be,P as Oe}from"./usePagination-ClGMIx77.js";import{b as Ue}from"./module-insights-DIdF2rv9.js";import{A as qe}from"./AdvancedModulePanel-CQIOs9aA.js";import{P as He}from"./PageHeader-CsFfXur0.js";import{u as ze}from"./useRecoveryMenu-BcK-UPo4.js";import{R as Ge}from"./RecordRecoveryActions-BIbDI7JH.js";import{a as Ke}from"./SignalLine-3Mz7VdKg.js";import{u as Qe}from"./useRecordIntelligence-CoyGM-Ve.js";import{p as We}from"./page-language-DGjnPgNe.js";import{g as Ve}from"./url-BxF7c6Us.js";import{u as Je}from"./useProductiveLoading-BO0IaMGS.js";import{I as H}from"./inbox-IpoGX3gq.js";import{E as Xe}from"./ellipsis-CAutlZKC.js";import{P as z}from"./pencil-DC8kxVxB.js";import{E as Ye}from"./eye-BMa0xke4.js";import{C as Ze}from"./link-65tYANWF.js";import{P as es}from"./pause-Bxon9t5i.js";import{P as ss}from"./play-I9FKzQDa.js";import"./AttentionStrip-DreKh8i4.js";import"./useDisclosurePreference-CSD3NNSj.js";import"./useDismissable-BvpILM0V.js";import"./useSmartGuide-DB5xQ_Gx.js";import"./useIntelligencePlacement-CbLnAc_a.js";import"./module-intro-N0cKHpsA.js";import"./ActionChoiceSheet-Bej1gA4Q.js";import"./ContextualInsights-Gpukgl55.js";import"./SimpleDisclosure-VZmRaKZG.js";import"./thumbs-up-C_QXljbQ.js";import"./EvidenceBlock-D_VAY3Vh.js";import"./underline-mwsmAvFy.js";import"./tablet-OD3jgAhR.js";import"./maximize-2-B3P4cQNS.js";import"./square-D7bNRzj-.js";import"./arrow-down-BMPlnjnx.js";import"./arrow-right-left-D96rAsAg.js";import"./arrow-up-down-DYIY2caZ.js";import"./arrow-up-right-DbUg8U10.js";import"./arrow-up-uYleynt9.js";import"./bookmark-plus-_Gy-vFYb.js";import"./badge-dollar-sign-DDsaUsAf.js";import"./ban-KAmLRETc.js";import"./bell-ring-6dq54sgf.js";import"./book-open-check-Srw4nRrZ.js";import"./book-open-C5m3GX53.js";import"./crown-hws5r3dX.js";import"./boxes-CdymS7UW.js";import"./toggle-left-BKxphWgL.js";import"./cake-B9CwKepl.js";import"./calculator-793hz_om.js";import"./contact-round-DkH2kPb5.js";import"./calendar-clock-BrAgRcD7.js";import"./calendar-heart-Bpd6k3fS.js";import"./calendar-plus-Y9ZLRDRx.js";import"./calendar-range-DYekGqLn.js";import"./wheat-oebZg5ML.js";import"./chevron-left-BO8s0r98.js";import"./chevrons-up-down-DW0jw1Xd.js";import"./circle-check-big-CqaXP6K1.js";import"./rotate-cw-BBLCLn01.js";import"./circle-pause-rKOqJ_54.js";import"./circle-play-DeNcn8Lt.js";import"./circle-plus-uaqPnHpv.js";import"./variable-CNxCo4jt.js";import"./clock-3-BBoowy6K.js";import"./unplug-BQP60_uU.js";import"./code-xml-C75pwXzA.js";import"./mouse-pointer-click-DELbrTN2.js";import"./table-2-c8NUfrp9.js";import"./library-BK4QEfZd.js";import"./database-dY3RtVXf.js";import"./download-D8rVLK2a.js";import"./ellipsis-vertical-CEb_a4k-.js";import"./eye-off-DP6aatND.js";import"./facebook-BOZYrg5x.js";import"./factory-CrfF_Yvt.js";import"./file-check-DwDvwaHw.js";import"./timer-reset-DADX0uiF.js";import"./file-spreadsheet-C0YUyC8u.js";import"./filter-CXt2ShtC.js";import"./flag-MJRNLl_Q.js";import"./pencil-line-BGZi5QhH.js";import"./folder-plus-CPx5b8d_.js";import"./gauge-D09rc50z.js";import"./youtube-DVQWXfeh.js";import"./globe-C22yugrV.js";import"./grip-vertical-CiuWx_Va.js";import"./heart-handshake-B49sNsgu.js";import"./hourglass-B3vMOC_T.js";import"./wifi-DFC_pcmF.js";import"./image-off-m_279FpP.js";import"./image-plus-DpxDknDd.js";import"./image-CyeYP78T.js";import"./package-plus-ChqUExSU.js";import"./instagram-B8Ezlogz.js";import"./key-Be7ol9Ms.js";import"./layers-3zKAEbPs.js";import"./linkedin-BKsvXJLa.js";import"./list-ordered-D8gwkM9h.js";import"./list-DGGkzBbs.js";import"./map-pin-D8yKoJwU.js";import"./message-circle-BaAVvJru.js";import"./message-square-heart-Cc5eMeJ1.js";import"./message-square-quote-Cv7HAfjA.js";import"./minus-DzNOUrXP.js";import"./monitor-C87s7gf_.js";import"./moon-star-oYgVqnQx.js";import"./package-check-CPxUIq6W.js";import"./package-search-CIOI0ItJ.js";import"./paperclip-D1wmnOro.js";import"./party-popper-CCyO5Xb5.js";import"./pen-line-9jiWvZNl.js";import"./phone-outgoing-C15DWOUB.js";import"./power-acJGjCtP.js";import"./printer-BesHXDy7.js";import"./qr-code-BBUT7F9m.js";import"./radar-DWNcndFS.js";import"./radio-BSNd35KV.js";import"./receipt-text-WjBuYb9n.js";import"./repeat-DtLx7W2-.js";import"./rocket-DDgcO4_x.js";import"./save-Bg7aMJuF.js";import"./scale-Ch_1J_wC.js";import"./settings-2-1mx35hli.js";import"./shapes-B1mJF17W.js";import"./share-2-CZ4zcaRo.js";import"./share-Tvc9jl_G.js";import"./shield-x-mEeezeFX.js";import"./smartphone-Bv32NG3H.js";import"./square-check-big-CBgkfjtW.js";import"./square-pen-Cu7eZch0.js";import"./star-BwrGBDd5.js";import"./stethoscope-BOmDDZVC.js";import"./sticky-note-BKRB5oMJ.js";import"./tags-Ed58BM6Q.js";import"./ticket-plus-BX3-SNsK.js";import"./timer-PGzFq-_7.js";
1import"./trash-2-DEbXoeSC.js";import"./utensils-crossed-BnBX42KK.js";import"./twitter-DqZOoxBv.js";import"./undo-2-BA1ZMI54.js";import"./upload-ByQVSpnZ.js";import"./user-x-OYN6jHXm.js";import"./user-DBlTe-K_.js";import"./users-round-fT51-aI3.js";import"./video-DDAfHAiu.js";import"./wallet-hX8y-nkf.js";import"./wand-sparkles-5e-vVx-4.js";import"./webhook-U5pXFWc_.js";import"./workflow-BQhqW2ze.js";import"./documents-Bju1cS7G.js";import"./charts-BjVT6r80.js";import"./app-primitives-C7oGnmBt.js";import"./select-C1j_15i9.js";import"./AdvancedSection-CBPqO4JF.js";import"./settings-return-GcuqJJ7v.js";import"./RecoveryList-BZUm54dS.js";import"./card-Bpoa90g8.js";import"./intents-B7QdDHP4.js";import"./HelpTip-Dhp2bChC.js";import"./events-C6DDl7qZ.js";import"./language-BHifK4iQ.js";const G={draft:{variant:"secondary",label:"Draft"},active:{variant:"success",label:"Active"},paused:{variant:"warning",label:"Paused"},archived:{variant:"inactive",label:"Archived"}},pr=()=>{const r=re(),g=le(),u=ce().canWork("forms"),K=Je("forms"),{data:m=[],isLoading:S}=De(g),P=Ae(),Q=Le(),W=Ee(),[V,f]=o.useState(!1),[y,D]=o.useState(null),J=o.useMemo(()=>Ue({publishedForms:m.filter(s=>s.status==="active").length,submissions:m.reduce((s,t)=>s+(t.submission_count||0),0)}),[m]),C=o.useMemo(()=>{const s=[];for(const t of m)t.status==="draft"?s.push({id:`draft-${t.id}`,title:t.name||"Untitled form",reason:"Not published yet - nobody can fill it in",actionLabel:"Finish it",onAction:()=>r(`/forms/${t.id}/edit`),onOpen:()=>r(`/forms/${t.id}/edit`),tone:"warning"}):t.status==="paused"&&s.push({id:`paused-${t.id}`,title:t.name||"Untitled form",reason:"Paused - responses are not coming in",actionLabel:"Resume",onAction:()=>R(t.id,t.status),onOpen:()=>r(`/forms/${t.id}/edit`),tone:"warning"});return s},[m,r]),[l,j]=o.useState(""),[A,v]=o.useState(""),[n,L]=o.useState(null),[b,k]=o.useState("templates"),[F,X]=o.useState(""),[w,Y]=o.useState("All"),E=o.useMemo(()=>{const s=F.trim().toLowerCase();return Re.filter(t=>{const i=w==="All"||t.category===w,a=!s||t.name.toLowerCase().includes(s)||t.description.toLowerCase().includes(s)||t.category.toLowerCase().includes(s);return i&&a})},[F,w]),{paginatedItems:$,...Z}=Be(m,25,{persistKey:"forms"}),ee=Qe($.map(s=>s.id)),I=()=>{k("templates"),L(null),j(""),v(""),f(!0)},M=s=>
1{L(s),s?(j(s.name),v(s.description)):(j(""),v("")),k("details")},se=async()=>{if(l.trim()){if(!g){p.error("Setup required",{description:"Please complete onboarding first."});return}try{const s=await Ie(l,g),t={org_id:g,name:l.trim(),slug:s,description:A||null,status:"draft"};n&&(t.fields=n.fields,t.settings={success_message:n.successMessage,automations:n.automations||{},sections:n.sections||[]});const i=await P.mutateAsync(t);p.success("Form created"),f(!1),r(`/forms/${i.id}/edit`)}catch(s){p.error("That did not save",{cause:s})}}},R=async(s,t)=>{const i=t==="active"?"paused":"active";await Q.mutateAsync({id:s,status:i}),p.success(`Form ${i}`)},te=async()=>{y&&(await W.mutateAsync(y),D(null),p.success("Form deleted"))},ie=s=>{const t=ne[s];return t?e.jsx(t,{className:"h-5 w-5"}):e.jsx(B,{className:"h-5 w-5"})},_=ze("forms"),N=oe("forms",{attention:{items:C,summary:`${C.length} ${C.length===1?"form is":"forms are"} not collecting responses`},insights:S?void 0:{summary:"How your forms are performing",...J}});return e.jsxs("div",{className:"space-y-4",children:[e.jsx(He,{title:"Forms",description:We("forms"),primaryLabel:u?"Create form":void 0,primaryIcon:e.jsx(pe,{className:"h-4 w-4"}),onPrimary:u?I:void 0,module:"forms",secondaryActions:_.actions.map(s=>({label:s.label,icon:s.icon,onClick:s.onClick}))}),N.attentionTop,N.insightsTop,S?e.jsxs("div",{className:"space-y-4 py-12",children:[e.jsx("p",{className:"text-center text-muted-foreground",children:"Loading forms..."}),e.jsx(de,{...K})]}):m.length===0?e.jsx(Me,{icon:B,heading:"Start collecting customer information",subtext:"Create a form and share it with your customers. Every response becomes a contact.",actionLabel:u?"Create form":void 0,onAction:u?I:void 0}):e.jsxs("div",{className:"rounded-lg border bg-card overflow-x-auto",children:[e.jsxs(Te,{children:[e.jsx(Se,{children:e.jsxs(q,{children:[e.jsx(x,{children:"Form Name"}),e.jsx(x,{children:"Status"}),e.jsx(x,{className:"hidden md:table-cell",children:"Submissions"}),e.jsx(x,{className:"hidden lg:table-cell",children:"Created"}),e.jsx(x,{className:"w-10"})]})}),e.jsx(Pe,{children:$.map(s=>{const t=G[s.status]||G.draft,i=me(s.status,u);return e.jsxs(q,{className:"cursor-pointer",onClick:()=>r(`/forms/${s.id}/edit`),children:[e.jsx(h,{children:e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:s.name}),s.description&&e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-2 mt-0.5",children:s.description}),e.jsxs("p",{className:"text-xs text-muted-foreground font-mono",children:["/",s.slug]}),e.jsx(Ke,{facts:ee[s.id],className:"mt-0.5"}),e.jsxs(d,{variant:"secondary",className:"mt-1 md:hidden cursor-pointer hover:bg-secondary/80 gap-1 inline-flex items-center text-[10px]",onClick:a=>{a.stopPropagation(),r(`/forms/${s.id}/analytics`)},children:[e.jsx(H,{className:"h-3 w-3"}),s.submission_count||0," responses"]})]})}),e.jsx(h,{children:e.jsx(d,{variant:t.variant,children:t.label})}),e.jsx(h,{className:"hidden md:table-cell",children:e.jsxs(d,{variant:"secondary",className:"cursor-pointer hover:bg-secondary/80 gap-1 inline-flex items-center",onClick:a=>{a.stopPropagation(),r(`/forms/${s.id}/analytics`)},children:[e.jsx(H,{className:"h-3 w-3"}),s.submission_count||0]})}),e.jsx(h,{className:"hidden lg:table-cell text-caption",children:ue(new Date(s.created_at),{addSuffix:!0})}),e.jsx(h,{onClick:a=>a.stopPropagation(),children:e.jsxs(xe,{children:[e.jsx(he,{asChild:!0,children:e.jsx(T,{variant:"ghost",size:"icon",className:"h-7 w-7","aria-label":"Form actions",children:e.jsx(Xe,{className:"h-4 w-4"})})}),e.jsxs(ge,{align:"end",children:[i.includes("continue-editing")&&e.jsxs(c,{onClick:()=>r(`/forms/${s.id}/edit`),children:[e.jsx(z,{className:"h-3 w-3 mr-2"})," Continue editing"]}),i.includes("view-responses")&&e.jsxs(c,{onClick:()=>r(`/forms/${s.id}/analytics`),children:[e.jsx(Ye,{className:"h-3 w-3 mr-2"})," View responses"]}),i.includes("copy-link")&&e.jsxs(e.Fragment,{children:[e.jsxs(c,{onClick:()=>{const a=Ve({kind:"form",reference:s.slug,params:{org:s.org_id}}).url;navigator.clipboard.writeText(a),p.success("Link copied")},children:[e.jsx(fe,{className:"h-3 w-3 mr-2"})," Copy link"]}),e.jsxs(c,{onClick:()=>r(`/forms/${s.id}/edit?view=embed`),children:[e.jsx(Ze,{className:"h-3 w-3 mr-2"})," Embed code & QR"]}),e.jsxs(c,{onClick:()=>r(`/forms/${s.id}/edit?view=build&tab=appearance`),children:[e.jsx(je,{className:"h-3 w-3 mr-2"})," Appearance"]})]}),i.includes("edit")&&e.jsxs(c,{onClick:()=>r(`/forms/${s.id}/edit`),children:[e.jsx(z,{className:"h-3 w-3 mr-2"})," Edit"]}),(i.includes("pause")||i.includes("resume"))&&e.jsxs(c,{onClick:()=>R(s.id,s.status),children:[s.status==="active"?e.jsx(es,{className:"h-3 w-3 mr-2"}):e.jsx(ss,{className:"h-3 w-3 mr-2"}),s.status==="active"?"Pause":"Resume"]}),e.jsx(Ge,{entity:"forms",id:s.id,label:s.name})]})]})})]},s.id)})})]}),e.jsx(Oe,{pagination:Z})]}),N.attentionBottom,N.insightsBottom,e.jsx(qe,{module:"forms"}),e.jsx(ve,{open:V,onOpenChange:f,children:e.jsxs(be,{size:"lg",className:"w-[calc(100vw-2rem)] sm:w-full max-h-[90dvh] flex flex-col overflow-hidden ",children:[e.jsx(we,{className:"shrink-0",children:e.jsx(Ne,{children:b==="templates"?"Choose a Template":"Form Details"})}),b==="templates"?e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col gap-3",children:[e.jsxs("button",{onClick:()=>M(null),className:"shrink-0 w-full flex items-center gap-3 rounded-lg border p-2.5 sm:p-3 text-left hover:border-primary/40 hover:bg-muted/50 transition-all",children:[e.jsx("div",{className:"flex h-8 w-8 sm:h-9 sm:w-9 shrink-0 items-center justify-center rounded-lg bg-muted",children:e.jsx(ae,{className:"h-4 w-4 text-muted-foreground"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-medium text-sm break-words",children:"Blank Form"}),e.jsx("p",{className:"text-caption text-xs break-words",children:"Start from scratch with an empty form"})]})]}),e.jsx(O,{value:F,onChange:s=>X(s.target.value),placeholder:"Search templates...",className:"h-9 shrink-0"}),e.jsx(ye,{label:"Template categories",size:"compact",className:"shrink-0",options:["All",..._e].map(s=>({value:s,label:s})),value:w,onChange:Y}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2 flex-1 min-h-0 overflow-y-auto pr-1 content-start",children:[E.map(s=>{var t;return e.jsxs("button",{onClick:()=>M(s),className:"flex items-start gap-3 rounded-lg border p-2.5 sm:p-3 text-left hover:border-primary/40 hover:bg-muted/50 transition-all",children:[e.jsx("div",{className:"flex h-8 w-8 sm:h-9 sm:w-9 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary",children:ie(s.icon)}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-medium text-sm break-words",children:s.name}),e.jsx("p",{className:"text-caption text-xs line-clamp-2",children:s.description}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1",children:[e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[s.fields.length," fields"]}),(((t=s.sections)==null?void 0:t.length)||0)>1&&e.jsxs(d,{variant:"secondary",className:"text-[10px]",children:[s.sections.length," pages"]}),s.fields.some(i=>i.condition)&&e.jsx(d,{variant:"secondary",className:"text-[10px]",children:"Smart logic"})]})]})]},s.key)}),E.length===0&&e.jsx("p",{className:"col-span-full py-6 text-center text-caption text-xs",children:"No templates match your search."})]})]}):e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto space-y-4 pr-1",children:[n&&e.jsx("button",{onClick:()=>k("templates"),className:"text-xs text-primary hover:underline",children:"â Change template"}),e.jsxs("div",{children:[e.jsx(U,{children:"Form Name *"}
1),e.jsx(O,{value:l,onChange:s=>j(s.target.value),placeholder:"e.g. Property Enquiry"}),l&&e.jsxs("p",{className:"text-caption mt-1",children:["Form URL: ",$e(l)]})]}),e.jsxs("div",{children:[e.jsx(U,{children:"Description"}),e.jsx(Ce,{value:A,onChange:s=>v(s.target.value),placeholder:"Optional description",rows:2})]}),n&&e.jsxs("div",{className:"rounded-lg border bg-muted/30 p-3",children:[e.jsx("p",{className:"text-xs font-medium mb-1",children:"Template fields:"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:n.fields.map(s=>e.jsxs(d,{variant:"secondary",className:"text-[10px]",children:[s.label,s.required?" *":""]},s.id))})]})]}),b==="details"&&e.jsxs(ke,{className:"shrink-0 flex-col-reverse gap-2 sm:flex-row sm:gap-2",children:[e.jsx(T,{variant:"outline",onClick:()=>f(!1),children:"Cancel"}),e.jsx(T,{onClick:se,disabled:!l.trim()||P.isPending,children:"Create & Edit"})]})]})}),e.jsx(Fe,{open:!!y,onOpenChange:s=>!s&&D(null),title:"Delete Form",message:"This moves the form and its responses to the Recycle bin, where you can restore them.",confirmLabel:"Delete",onConfirm:te}),_.surfaces]})};export{pr 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.