import{r as i,j as e,L as h}from"./index-DlcHsm52.js";import{F as t,C as c,B as r,P as v,A as F,a as T,T as j,E as C,h as O,I as l,S as d,f as A,r as y,p as M,s as f,i as k}from"./IdurarOs-j0IoqkpA.js";import{W as B}from"./shared-N8zi2N1N.js";import{M as L}from"./index-Clbw7Jrz.js";import{R as N}from"./ReloadOutlined-C37-gl6w.js";import"./ErpApp-7VdZNpBd.js";const{Paragraph:U,Text:g}=A,q=[{value:"lead",label:"Lead"},{value:"contact",label:"Contact"},{value:"client",label:"Customer"}],D=[{value:"draft",label:"Draft"},{value:"published",label:"Published"},{value:"archived",label:"Archived"}];function $(){const[R,m]=i.useState([]),[w,o]=i.useState(!1),[S,p]=i.useState(!1),[b,x]=i.useState(""),[n]=t.useForm(),I=i.useMemo(()=>window.location.origin,[]),u=async()=>{p(!0),x("");const s=await y.list({entity:"publicform",options:{page:1,items:100}});s!=null&&s.success?m(s.result||[]):(x((s==null?void 0:s.message)||"Unable to load public forms."),m([])),p(!1)};i.useEffect(()=>{u()},[]);const E=async()=>{const s=await n.validateFields(),a=await y.create({entity:"publicform",jsonData:{name:s.name,slug:s.slug,description:s.description,targetEntity:s.targetEntity,fields:M(s.fields),autoReplyEnabled:s.autoReplyEnabled==="yes",autoReplySubject:s.autoReplySubject,autoReplyBody:s.autoReplyBody,successMessage:s.successMessage,status:s.status}});a!=null&&a.success&&(f.success("Public form created"),o(!1),n.resetFields(),u())},P=async s=>{const a=k(I,s);await navigator.clipboard.writeText(a),f.success("Public form URL copied")};return e.jsxs(B,{title:"Public Forms",description:"Create, publish, and test public CRM capture forms with hosted links and optional auto-replies.",permission:"platform.publicform.read",extra:e.jsxs(c,{children:[e.jsx(r,{icon:e.jsx(N,{}),onClick:u,children:"Refresh"}),e.jsx(r,{children:e.jsx(h,{to:"/forms/builder",children:"Open Form Builder"})}),e.jsx(r,{type:"primary",icon:e.jsx(v,{}),onClick:()=>o(!0),children:"New Public Form"})]}),children:[e.jsxs(c,{direction:"vertical",size:16,style:{width:"100%"},children:[b&&e.jsx(F,{type:"warning",showIcon:!0,message:b}),e.jsx(U,{type:"secondary",style:{marginBottom:0},children:"Published forms are available without auth at their hosted URL and submit into the tenant-scoped CRM workflow."}),e.jsx(T,{rowKey:"_id",loading:S,dataSource:R,pagination:!1,columns:[{title:"Name",dataIndex:"name"},{title:"Slug",dataIndex:"slug",render:s=>e.jsx(g,{code:!0,children:s})},{title:"Target",dataIndex:"targetEntity",render:s=>e.jsx(j,{children:s})},{title:"Status",dataIndex:"status",render:s=>e.jsx(j,{color:s==="published"?"green":"default",children:s})},{title:"Fields",dataIndex:"fields",render:(s=[])=>s.join(", ")||"-"},{title:"Public URL",render:(s,a)=>a.status==="published"?e.jsxs(c,{children:[e.jsx(r,{size:"small",icon:e.jsx(C,{}),children:e.jsx(h,{to:`/forms/public/${a.slug}`,children:"Open"})}),e.jsx(r,{size:"small",icon:e.jsx(O,{}),onClick:()=>P(a.slug),children:"Copy"})]}):e.jsx(g,{type:"secondary",children:"Publish to enable"})}]})]}),e.jsx(L,{title:"New Public Form",open:w,onCancel:()=>o(!1),onOk:E,width:720,children:e.jsxs(t,{form:n,layout:"vertical",initialValues:{targetEntity:"lead",status:"draft",autoReplyEnabled:"no",fields:"firstName,email,phone,message"},children:[e.jsx(t.Item,{name:"name",label:"Name",rules:[{required:!0}],children:e.jsx(l,{})}),e.jsx(t.Item,{name:"slug",label:"Slug",rules:[{required:!0}],children:e.jsx(l,{})}),e.jsx(t.Item,{name:"description",label:"Description",children:e.jsx(l.TextArea,{rows:2})}),e.jsx(t.Item,{name:"targetEntity",label:"Target Entity",rules:[{required:!0}],children:e.jsx(d,{options:q})}),e.jsx(t.Item,{name:"status",label:"Status",rules:[{required:!0}],children:e.jsx(d,{options:D})}),e.jsx(t.Item,{name:"fields",label:"Fields (comma separated)",rules:[{required:!0}],children:e.jsx(l,{})}),e.jsx(t.Item,{name:"successMessage",label:"Success Message",children:e.jsx(l,{})}),e.jsx(t.Item,{name:"autoReplyEnabled",label:"Auto Reply",children:e.jsx(d,{options:[{value:"no",label:"Disabled"},{value:"yes",label:"Enabled"}]})}),e.jsx(t.Item,{name:"autoReplySubject",label:"Auto Reply Subject",children:e.jsx(l,{})}),e.jsx(t.Item,{name:"autoReplyBody",label:"Auto Reply Body",children:e.jsx(l.TextArea,{rows:3})})]})})]})}export{$ as default};
