1import{j as e}from"./vendor-Dw1-o7kh.js";import{r as s}from"./react-BpC26T6t.js";import{m as t,s as a,B as r,F as i,R as l,S as d,C as n,E as c,X as o,M as m,k as x,r as h,t as u,K as f,g as p,i as g}from"./index-BTs3I-_Y.js";import{p as j}from"./backOfficeApi-DOgQ5CqD.js";import{D as y}from"./download-C9as-u-O.js";import{C as v}from"./check-Bt2EMCMp.js";import{S as b}from"./send-vOChcdFa.js";import{T as N}from"./trash-Ni2Fzrxd.js";import{A as w}from"./arrow-up-down-Du4nE51-.js";import{A as _,a as k}from"./arrow-up-CvieMSNg.js";import"./supabase-H1x_w4VC.js"; 2/** 3 * @license lucide-react v0.344.0 - ISC 4 * 5 * This source code is licensed under the ISC license. 6 * See the LICENSE file in the root directory of this source tree. 7 */const S=t("Building",[["rect",{width:"16",height:"20",x:"4",y:"2",rx:"2",ry:"2",key:"76otgf"}],["path",{d:"M9 22v-4h6v4",key:"r93iot"}],["path",{d:"M8 6h.01",key:"1dz90k"}],["path",{d:"M16 6h.01",key:"1x0f13"}],["path",{d:"M12 6h.01",key:"1vi96p"}],["path",{d:"M12 10h.01",key:"1nrarc"}],["path",{d:"M12 14h.01",key:"1etili"}],["path",{d:"M16 10h.01",key:"1m94wz"}],["path",{d:"M16 14h.01",key:"1gbofw"}],["path",{d:"M8 10h.01",key:"19clt8"}],["path",{d:"M8 14h.01",key:"6423bh"}]]),C=t("User",[["path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2",key:"975kel"}],["circle",{cx:"12",cy:"7",r:"4",key:"17ys0d"}]]); 8/** 9 * @license lucide-react v0.344.0 - ISC 10 * 11 * This source code is licensed under the ISC license. 12 * See the LICENSE file in the root directory of this source tree. 13 */function z(e={}){const[t,r]=s.useState([]),[i,l]=s.useState(!0),[d,n]=s.useState(null),[c,o]=s.useState(0),[m,x]=s.useState([]),{limit:h=10,page:u=0,formName:f,dateFrom:p,dateTo:g,searchTerm:j,sortBy:y="submitted_at",sortDirection:v="desc"}=e;async function b(){try{l(!0);const e=u*h,s=e+h-1;let t=a.from("form_submissions").select("*",{count:"exact"});if(f&&(t=t.eq("form_name",f)),p&&(t=t.gte("submitted_at",p)),g){const e=new Date(g);e.setDate(e.getDate()+1),t=t.lt("submitted_at",e.toISOString())}j&&(t=t.or(`form_data->name.ilike.%${j}%,form_data->email.ilike.%${j}%,form_data->message.ilike.%${j}%`)),t=t.order(y,{ascending:"asc"===v}),t=t.range(e,s);const{data:i,error:d,count:n}=await t;
13if(d)throw d;r(i||[]),o(n||0)}catch(e){n(e instanceof Error?e:new Error("An error occurred"))}finally{l(!1)}}return s.useEffect(()=>{b(),async function(){try{const{data:e,error:s}=await a.from("form_submissions").select("form_name").order("form_name").limit(100);if(s)throw s;const t=[...new Set(null==e?void 0:e.map(e=>e.form_name))];x(t)}catch(e){}}()},[h,u,f,p,g,j,y,v]),{submissions:t,loading:i,error:d,totalCount:c,formNames:m,updateSubmission:async function(e,s){try{const{data:t,error:i}=await a.from("form_submissions").update(s).eq("id",e).select().single();if(i)throw i;return r(s=>s.map(s=>s.id===e?{...s,...t}:s)),t}catch(t){throw t}},deleteSubmission:async function(e){try{const{error:s}=await a.from("form_submissions").delete().eq("id",e);if(s)throw s;r(s=>s.filter(s=>s.id!==e)),o(e=>e-1)}catch(s){throw s}},exportSubmissions:async function(e={}){try{l(!0);let s=a.from("form_submissions").select("*");if(e.formName&&(s=s.eq("form_name",e.formName)),e.dateFrom&&(s=s.gte("submitted_at",e.dateFrom)),e.dateTo){const t=new Date(e.dateTo);t.setDate(t.getDate()+1),s=s.lt("submitted_at",t.toISOString())}e.searchTerm&&(s=s.or(`form_data->name.ilike.%${e.searchTerm}%,form_data->email.ilike.%${e.searchTerm}%,form_data->message.ilike.%${e.searchTerm}%`));const t=e.sortBy||"submitted_at",r=e.sortDirection||"desc";s=s.order(t,{ascending:"asc"===r});const{data:i,error:d}=await s;if(d)throw d;return i||[]}catch(s){throw s}finally{l(!1)}},refresh:b}}function A(){var t;const[A,D]=s.useState(!1),[F,M]=s.useState(""),[T,L]=s.useState(""),[R,E]=s.useState(""),[q,U]=s.useState(""),[I,P]=s.useState(""),[$,Z]=s.useState(0),[B,O]=s.useState(10),[H,K]=s.useState("submitted_at"),[V,W]=s.useState("desc"),[Y,G]=s.useState(!1),[J,Q]=s.useState(!1),[X,ee]=s.useState(null),[se,te]=s.useState(!1);s.useEffect(()=>{M("")},[null==X?void 0:X.id]);const[ae,re]=s.useState(!1),[ie,le]=s.useState(""),[de,ne]=s.useState({}),[ce,oe]=s.useState({open:!1,submission:null,duplicateLeads:[]}),{submissions:me,loading:xe,error:he,totalCount:ue,formNames:fe,updateSubmission:pe,deleteSubmission:ge,exportSubmissions:je,refresh:ye}=z({limit:B,page:$,formName:T||void 0,dateFrom:R||void 0,dateTo:q||void 0,searchTerm:I||void 0,sortBy:H,sortDirection:V}),ve=Math.ceil(ue/B),be=e=>{H===e?W("asc"===V?"desc":"asc"):(K(e),W("desc"))},Ne=s=>H!==s?e.jsx(w,{className:"h-4 w-4 ml-1"}):"asc"===V?e.jsx(_,{className:"h-4 w-4 ml-1"}):e.jsx(k,{className:"h-4 w-4 ml-1"}),we=e=>new Date(e).toLocaleString(),_e=async(e,s)=>{re(!0);try{await pe(e,{status:s}),(null==X?void 0:X.id)===e&&ee(e=>e?{...e,status:s}:null)}catch(t){alert("Failed to update status")}finally{re(!1)}},ke=async e=>{if(confirm("Are you sure you want to delete this submission?"))try{await ge(e),(null==X?void 0:X.id)===e&&(ee(null),te(!1))}catch(s){alert("Failed to delete submission")}},Se=async e=>{var s,t;if(!(null==(s=e.form_data)?void 0:s.email)||!(null==(t=e.form_data)?void 0:t.name))return void alert("Submission must have email and name to push to Zoho");const r=e.id;ne(e=>({...e,[r]:"pushing"}));try{const s=await(async e=>{var s;if(!(null==(s=e.form_data)?void 0:s.email))return[];try{const{data:s,error:t}=await a.from("zoho_integrations").select("*").eq("form_data->>email",e.form_data.email).eq("action","create_lead").eq("status","success").order("created_at",{ascending:!1});if(t)throw t;return(s||[]).filter(e=>{var s,t,a,r,i;return null==(i=null==(r=null==(a=null==(t=null==(s=e.results)?void 0:s.lead)?void 0:t.data)?void 0:a[0])?void 0:r.details)?void 0:i.id}).map(e=>{var s,t,a,r,i;return{leadId:null==(i=null==(r=null==(a=null==(t=null==(s=e.results)?void 0:s.lead)?void 0:t.data)?void 0:a[0])?void 0:r.details)?void 0:i.id,createdAt:e.created_at,formType:e.form_type,formData:e.form_data}})}catch(t){return[]}})(e);if(s.length>0)return oe({open:!0,submission:e,duplicateLeads:s}),void ne(e=>({...e,[r]:"not_in_zoho"}));await Ce(e)}catch(i){alert("Failed to push to Zoho: "+(i instanceof Error?i.message:"Unknown error")),ne(e=>({...e,[r]:"not_in_zoho"}))}},Ce=async(e,s=!1)=>{const t=e.id;try{const s={name:e.form_data.name||"",email:e.form_data.email||"",company:e.form_data.company||"",phone:e.form_data.phone||"",message:e.form_data.message||e.form_data.description||"",...e.form_data},a=Fe(e.form_name);await g(s,a,{createLead:!0,subscribeNewsletter:!1,onSuccess:e=>{ne(e=>({...e,[t]:"in_zoho"})),alert("Lead successfully pushed to Zoho CRM")},onError:e=>{throw ne(e=>({...e,[t]:"not_in_zoho"})),e}})}catch(a){throw ne(e=>({...e,[t]:"not_in_zoho"})),a}},ze=async e=>{if(ce.submission)if("cancel"!==e)try{await Ce(ce.submission,!0),oe({open:!1,submission:null,duplicateLeads:[]})}catch(s){alert("Failed to create lead: "+(s instanceof Error?s.message:"Unknown error"))}else oe({open:!1,submission:null,duplicateLeads:[]})};s.useEffect(()=>{me.length>
130&&me.forEach(e=>{var s;(null==(s=e.form_data)?void 0:s.email)&&!de[e.id]&&(async e=>{var s,t,r,i,l;if(!(null==(s=e.form_data)?void 0:s.email))return;const d=e.id;ne(e=>({...e,[d]:"checking"}));try{const{data:s,error:n}=await a.from("zoho_integrations").select("*").eq("form_data->>email",e.form_data.email).eq("action","create_lead").eq("status","success").order("created_at",{ascending:!1}).limit(1);if(n)throw n;if(s&&s.length>0){const e=s[0].results,a=null==(l=null==(i=null==(r=null==(t=null==e?void 0:e.lead)?void 0:t.data)?void 0:r[0])?void 0:i.details)?void 0:l.id;ne(a?e=>({...e,[d]:"in_zoho"}):e=>({...e,[d]:"not_in_zoho"}))}else ne(e=>({...e,[d]:"not_in_zoho"}))}catch(n){ne(e=>({...e,[d]:"not_in_zoho"}))}})(e)})},[me]);const Ae=e=>{switch(e){case"submitted":return"bg-blue-100 text-blue-800";case"processed":return"bg-green-100 text-green-800";default:return"bg-gray-100 text-gray-800"}},De=s=>{switch(s.toLowerCase()){case"contact":return e.jsx(m,{className:"h-5 w-5 text-blue-500"});case"f360":return e.jsx(p,{className:"h-5 w-5 text-purple-500"});case"event_registration":return e.jsx(n,{className:"h-5 w-5 text-green-500"});case"meeting_request":return e.jsx(n,{className:"h-5 w-5 text-orange-500"});default:return e.jsx(h,{className:"h-5 w-5 text-gray-500"})}},Fe=e=>{switch(e.toLowerCase()){case"contact":return"Contact Form";case"f360":return"F360 Product Inquiry";case"event_registration":return"Event Registration";case"meeting_request":return"Meeting Request";default:return e.replace(/_/g," ").replace(/\b\w/g,e=>e.toUpperCase())}};return xe&&!J&&0===me.length?e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx("div",{className:"text-gray-600",children:"Loading form submissions..."})}):he&&0===me.length?e.jsxs("div",{className:"bg-red-50 border border-red-200 text-red-700 p-4 rounded-md",children:["Error: ",he.message]}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h1",{className:"text-2xl font-bold text-secondary",children:"Form Submissions"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(r,{variant:"outline",onClick:()=>G(!Y),children:[e.jsx(i,{className:"h-4 w-4 mr-2"}),"Filters"]}),e.jsxs(r,{variant:"outline",onClick:async()=>{Q(!0);try{await ye()}catch(e){}finally{Q(!1)}},disabled:J,children:[e.jsx(l,{className:"h-4 w-4 mr-2 "+(J?"animate-spin":"")}),J?"Refreshing...":"Refresh"]}),e.jsxs(r,{variant:"outline",onClick:async()=>{try{const e=await je({formName:T||void 0,dateFrom:R||void 0,dateTo:q||void 0,searchTerm:I||void 0,sortBy:H,sortDirection:V}),s=f(e),t=new Blob([s],{type:"text/csv"}),a=URL.createObjectURL(t),r=document.createElement("a");r.href=a,r.download=`form-submissions-${(new Date).toISOString().split("T")[0]}.csv`,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(a)}catch(e){alert("Failed to export submissions")}},disabled:0===me.length,children:[e.jsx(y,{className:"h-4 w-4 mr-2"}),"Export"]})]})]}),Y&&e.jsxs("div",{className:"bg-white rounded-lg shadow-sm p-6 mb-6",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Form Type"}),e.jsxs("select",{value:T,onChange:e=>L(e.target.value),className:"w-full px-3 py-2 border border-gray-300 rounded-md",children:[e.jsx("option",{value:"",children:"All Forms"}),fe.map(s=>e.jsx("option",{value:s,children:Fe(s)},s))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Status"}),e.jsxs("select",{value:ie,onChange:e=>le(e.target.value),className:"w-full px-3 py-2 border border-gray-300 rounded-md",children:[e.jsx("option",{value:"",children:"All Statuses"}),e.jsx("option",{value:"submitted",children:"Submitted"}),e.jsx("option",{value:"processed",children:"Processed"}),e.jsx("option",{value:"archived",children:"Archived"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Date From"}),e.jsx("input",{type:"date",value:R,onChange:e=>E(e.target.value),className:"w-full px-3 py-2 border border-gray-300 rounded-md"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Date To"}),e.jsx("input",{type:"date",value:q,onChange:e=>U(e.target.value),className:"w-full px-3 py-2 border border-gray-300 rounded-md"})]})]}),e.jsx("div",{className:"mt-4",children:e.jsxs("div",{className:"relative",children:[e.jsx(d,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400 h-5 w-5"}),e.jsx("input",{type:"text",placeholder:"Search by name, email, or message content...",value:I,onChange:e=>P(e.target.value),className:"w-full pl-10 pr-4 py-2 border border-gray-300 rounded-md"})]})}),e.jsxs("div",{className:"mt-4 flex justify-end",children:[e.jsx(r,{variant:"outline",onClick:()=>{L(""),E(""),U(""),P(""),le(""),Z(0),K("submitted_at"),W("desc")},className:"mr-2",children:"Reset"}),e.jsx(r,{onClick:()=>{Z(0)},children:"Apply Filters"})]})]}),e.jsxs("div",{className:"bg-white rounded-lg shadow",children:[0===me.length?e.jsx("div",{className:"p-8 text-center",children:e.jsx("p",{className:"text-gray-600 mb-4",children:"No form submissions foun
13d"})}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full divide-y divide-gray-200",children:[e.jsx("thead",{className:"bg-gray-50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider cursor-pointer",onClick:()=>be("form_name"),children:e.jsxs("div",{className:"flex items-center",children:["Form",Ne("form_name")]})}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Submitter"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider cursor-pointer",onClick:()=>be("submitted_at"),children:e.jsxs("div",{className:"flex items-center",children:["Submitted At",Ne("submitted_at")]})}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider cursor-pointer",onClick:()=>be("status"),children:e.jsxs("div",{className:"flex items-center",children:["Status",Ne("status")]})}),e.jsx("th",{className:"px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Actions"})]})}),e.jsx("tbody",{className:"bg-white divide-y divide-gray-200",children:me.map(s=>{var t,a;return e.jsxs("tr",{className:"hover:bg-gray-50",children:[e.jsx("td",{className:"px-6 py-4 whitespace-nowrap",children:e.jsxs("div",{className:"flex items-center",children:[De(s.form_name),e.jsxs("div",{className:"ml-3",children:[e.jsx("div",{className:"text-sm font-medium text-gray-900",children:Fe(s.form_name)}),e.jsxs("div",{className:"text-xs text-gray-500",children:["ID: ",s.id.substring(0,8),"..."]})]})]})}),e.jsxs("td",{className:"px-6 py-4",children:[e.jsx("div",{className:"text-sm text-gray-900",children:s.form_data.name||"N/A"}),e.jsx("div",{className:"text-xs text-gray-500",children:s.form_data.email||"No email provided"})]}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap",children:e.jsxs("div",{className:"text-sm text-gray-500 flex items-center",children:[e.jsx(n,{className:"h-3.5 w-3.5 mr-1 text-gray-400"}),we(s.submitted_at)]})}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap",children:e.jsx("span",{className:`px-2 inline-flex text-xs leading-5 font-semibold rounded-full ${Ae(s.status)}`,children:s.status.charAt(0).toUpperCase()+s.status.slice(1)})}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-right text-sm font-medium",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(r,{variant:"outline",size:"sm",onClick:()=>(e=>{ee(e),te(!0)})(s),title:"View Details",children:e.jsx(c,{className:"h-4 w-4"})}),(null==(t=s.form_data)?void 0:t.email)&&(null==(a=s.form_data)?void 0:a.name)&&e.jsx(r,{variant:"in_zoho"===de[s.id]?"primary":"outline",size:"sm",onClick:()=>Se(s),disabled:"checking"===de[s.id]||"pushing"===de[s.id]||"in_zoho"===de[s.id],className:"in_zoho"===de[s.id]?"bg-green-600 hover:bg-green-700 text-white border-green-600":"not_in_zoho"===de[s.id]?"bg-gray-100 hover:bg-gray-200 text-gray-600 border-gray-300":"",title:"in_zoho"===de[s.id]?"Already in Zoho CRM":"checking"===de[s.id]?"Checking status...":"pushing"===de[s.id]?"Pushing to Zoho...":"Push to Zoho CRM",children:"checking"===de[s.id]||"pushing"===de[s.id]?e.jsx(l,{className:"h-4 w-4 animate-spin"}):"in_zoho"===de[s.id]?e.jsx(v,{className:"h-4 w-4"}):e.jsx(b,{className:"h-4 w-4"})}),e.jsx(r,{variant:"outline",size:"sm",className:"text-red-600 hover:text-red-700",onClick:()=>ke(s.id),title:"Delete Submission",children:e.jsx(N,{className:"h-4 w-4"})})]})})]},s.id)})})]})}),me.length>0&&e.jsxs("div",{className:"px-6 py-4 bg-gray-50 border-t border-gray-200 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx("span",{className:"text-sm text-gray-700 mr-2",children:"Rows per page:"}),e.jsxs("select",{value:B,onChange:e=>{O(Number(e.target.value)),Z(0)},className:"border border-gray-300 rounded-md text-sm px-2 py-1",children:[e.jsx("option",{value:"10",children:"10"}),e.jsx("option",{value:"25",children:"25"}),e.jsx("option",{value:"50",children:"50"}),e.jsx("option",{value:"100",children:"100"})]}),e.jsxs("span",{className:"ml-4 text-sm text-gray-700",children:["Showing ",me.length>0?$*B+1:0," to ",Math.min(($+1)*B,ue)," of ",ue," entries"]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(r,{variant:"outline",size:"sm",onClick:()=>{$>0&&Z($-1)},disabled:0===$,className:"flex items-center",children:"Previous"}),e.jsxs("div",{className:"text-sm text-gray-700",children:["Page ",$+1," of ",ve||1]}),e.jsx(r,{variant:"outline",size:"sm",onClick:()=>{$<ve-1&&Z($+1)},disabled:$>=ve-1,className:"flex items-center",children:"Next"})]})]})]}),se&&X&&e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:e.jsxs("div",{className:"bg-white rounded-lg shadow-xl w-full max-w-4xl mx-auto",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b",children:[e.jsxs("h3",{className:"text-lg font-semibold text-gray-900 flex items-center",children:[De(X.form_name),e.jsxs("span",{className:"ml-2",children:[Fe(X.form_name)," Submission"]})]}),e.jsx(r,{variant:"outline",size:"sm",onClick:()=>te(!1),className:"text-gray-500",children:e.jsx(o,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"p-6 max-h-[calc(100vh-200px)] overflow-y-auto",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6 mb-6",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-gray-700 mb-2",children:"Submission Details"}),e.jsx("div",{className:"bg-gray-50 p-4 rounded-md",children:e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("div",{className:"text-xs font-medium text-gray-500",children:"ID:"}),e.jsx("div",{className:"text-xs text-gray-900",children:X.id}),e.jsx("div",{className:"text-xs font-medium text-gray-500",children:"Form:"}),e.jsx("div",{className:"text-xs text-gray-900",children:Fe(X.form_name)}),e.jsx("div",{className:"text-xs font-medium text-gray-500",children:"Submitted:"}),e.jsx("div",{className:"text-xs text-gray-900",children:we(X.submitted_at)}),e.jsx("div",{className:"text-xs font-medium text-gray-500",children:"Status:"}),e.jsx("div",{className:"text-xs",children:e.jsx("span",{className:`px-2 py-0.5 inline-flex text-xs leading-5 font-semibold rounded-full ${Ae(X.status)}`,children:X.status.charAt(0).toUpperCase()+X.status.slice(1)})}),e.jsx("div",{className:"text-xs font-medium text-gray-500",children:"Referrer:"}),e.jsx("div",{className:"text-xs text-gray-900 truncate",children:X.referrer||"N/A"})]})})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-gray-700 mb-2",children:"Update Status"}),e.jsx("div",{className:"bg-gray-50 p-4 rounded-md",children:e.jsxs("div",{className:"flex flex-col space-y-2",children:[e.jsxs(r,{variant:"submitted"===X.status?"primary":"outline",size:"sm",onClick:()=>_e(X.id,"submitted"),disabled:ae||"submitted"===X.status,className:"justify-start",children:[e.jsx("div",{className:"w-5 h-5 mr-2 flex items-center justify-center",children:"submitted"===X.status?e.jsx(v,{className:"h-4 w-4"}):null}),"Submitted"]}),e.jsxs(r,{variant:"processed"===X.status?"primary":"outline",size:"sm",onClick:()=>_e(X.id,"processed"),disabled:ae||"processed"===X.status,className:"justify-start",children:[e.jsx("div",{className:"w-5 h-5 mr-2 flex items-center justify-center",children:"processed"===X.status?e.jsx(v,{className:"h-4 w-4"}):null}),"Processed"]}),e.jsxs(r,{variant:"archived"===X.status?"primary":"outline",size:"sm",onClick:()=>_e(X.id,"archived"),disabled:ae||"archived"===X.status,className:"justify-start",children:[e.jsx("div",{className:"w-5 h-5 mr-2 flex items-center justify-center",children:"archived"===X.status?e.jsx(v,{className:"h-4 w-4"}):null}),"Archived"]})]})})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-gray-700 mb-2",children:"Form Data"}),e.jsx("div",{className:"bg-gray-50 p-4 rounded-md",children:e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:Object.entries(X.form_data||{}).map(([s,t])=>e.jsxs("div",{className:"border-b border-gray-200 pb-2",children:[e.jsxs("div",{className:"text-xs font-medium text-gray-500 mb-1 flex items-center",children:["name"===s&&e.jsx(C,{className:"h-3 w-3 mr-1"}),"email"===s&&e.jsx(m,{className:"h-3 w-3 mr-1"}),"company"===s&&e.jsx(S,{className:"h-3 w-3 mr-1"}),"phone"===s&&e.jsx(x,{className:"h-3 w-3 mr-1"}),"message"===s&&e.jsx(h,{className:"h-3 w-3 mr-1"}),s.charAt(0).toUpperCase()+s.slice(1),":"]}),e.jsx("div",{className:"text-sm text-gray-900 break-words",children:"string"==typeof t&&t.length>100?e.jsx("div",{className:"max-h-32 overflow-y-auto",children:t}):String(t)||"N/A"})]},s))})})]}),X.notes&&e.jsxs("div",{className:"mt-4",children:[e.jsx("h4",{className:"text-sm font-medium text-gray-700 mb-2",children:"Notes"}),e.jsx("div",{className:"bg-gray-50 p-4 rounded-md",children:e.jsx("p",{className:"text-sm text-gray-900",children:X.notes})})]}),e.jsxs("div",{className:"mt-4",children:[e.jsx("h4",{className:"text-sm font-medium text-gray-700 mb-2",children:"Technical Information"}),e.jsx("div",{className:"bg-gray-50 p-4 rounded-md",children:e.jsxs("div",{className:"grid grid-cols-1 gap-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-gray-500",children:"User Agent:"}),e.jsx("div",{className:"text-xs text-gray-900 break-words",children:X.user_agent||"N/A"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-gray-500",children:"IP Address:"}),e.jsx("div",{className:"text-xs text-gray-900",children:X.ip_address||"N/A"})]})]})})]})]}),e.jsxs("div",{className:"px-6 py-3 border-t",children:[e.jsx(r,{variant:"outline",disabled:A,onClick:async()=>{D(!0),M("");try{const e=await j(X.id);M(1===e.delivered?"CRM capture delivered.":0===e.claimed?"No eligible capture job; it may already be delivered or leased.":"Capture held for retry; CRM delivery did not complete.")}catch(e){M(e instanceof Error?e.message:"Capture unavailable")}finally{D(!1)}},children:"Process this CRM capture"}),F&&e.jsx("p",{role:"status",className:"text-sm mt-2",children:F})]}),e.jsxs("div",{className:"p-6 border-t bg-gray-50 flex justify-between",children:[e.jsxs(r,{variant:"outline",className:"text-red-600 hover:text-red-700",onClick:()=>{confirm("Are you sure you want to delete this submission?")&&ke(X.id)},children:[e.jsx(N,{className:"h-4 w-4 mr-2"}),"Delete Submission"]}),e.jsx(r,{variant:"outline",onClick:()=>te(!1),children:"Close"})]})]})}),ce.open&&ce.submission&&e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:e.jsxs("div",{className:"bg-white rounded-lg shadow-xl w-full max-w-2xl mx-auto",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b",children:[e.jsxs("h3",{className:"text-lg font-semibold text-gray-900 flex items-center",children:[e.jsx(u,{className:"h-5 w-5 mr-2 text-yellow-500"}),"Duplicate Lead Detected"]}),e.jsx(r,{variant:"outline",size:"sm",onClick:()=>ze("cancel"),className:"text-gray-500",children:e.jsx(o,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"p-6",children:e.jsxs("div",{className:"mb-4",children:[e.jsxs("p",{className:"text-sm text-gray-700 mb-4",children:["A lead with the email ",e.jsx("strong",{children:null==(t=ce.submission.form_data)?void 0:t.email})," already exists in Zoho CRM."]}),e.jsxs("div",{className:"bg-yellow-50 border border-yellow-200 rounded-md p-4 mb-4",children:[e.jsx("h4",{className:"text-sm font-medium text-yellow-800 mb
13-2",children:"Existing Leads:"}),e.jsx("div",{className:"space-y-2",children:ce.duplicateLeads.map((s,t)=>e.jsxs("div",{className:"text-sm text-yellow-700 bg-white p-3 rounded border border-yellow-200",children:[e.jsxs("div",{className:"font-medium",children:["Lead ID: ",s.leadId]}),e.jsxs("div",{className:"text-xs text-yellow-600 mt-1",children:["Created: ",new Date(s.createdAt).toLocaleString()]}),e.jsxs("div",{className:"text-xs text-yellow-600",children:["Form Type: ",s.formType]})]},t))})]}),e.jsxs("div",{className:"bg-blue-50 border border-blue-200 rounded-md p-4",children:[e.jsx("h4",{className:"text-sm font-medium text-blue-800 mb-2",children:"What would you like to do?"}),e.jsxs("ul",{className:"text-sm text-blue-700 space-y-1 list-disc list-inside",children:[e.jsxs("li",{children:[e.jsx("strong",{children:"Create Anyway:"})," Creates a new lead in Zoho (may result in duplicate leads)"]}),e.jsxs("li",{children:[e.jsx("strong",{children:"Cancel:"})," Does not create a new lead"]})]})]})]})}),e.jsxs("div",{className:"p-6 border-t bg-gray-50 flex justify-end gap-2",children:[e.jsx(r,{variant:"outline",onClick:()=>ze("cancel"),children:"Cancel"}),e.jsx(r,{variant:"primary",onClick:()=>ze("create_anyway"),className:"bg-yellow-600 hover:bg-yellow-700 text-white",children:"Create Anyway"})]})]})})]})}export{A as FormSubmissions};
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.