PageSourceSearch

https://www.trybased.com/static/js/150.e5f00124.chunk.js

js trybased.com collected 2026-10-02 01:48:03 UTC 59,724 bytes, 3 lines download raw bytes

1/*! For license information please see 150.e5f00124.chunk.js.LICENSE.txt */
2"use strict";(self.webpackChunkknowledge_base_saas=self.webpackChunkknowledge_base_saas||[]).push([[150],{60150(e,t,s){s.r(t),s.d(t,{default:()=>me});var a=s(89379),r=s(5544),n=s(65043),l=s(55472),i=s(96822),o=s(52395),c=s(42574),d=s(75088),m=s(14459),x=s(77784);const u=(0,x.A)("file-question",[["path",{d:"M12 17h.01",key:"p32p05"}],["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7z",key:"1mlx9k"}],["path",{d:"M9.1 9a3 3 0 0 1 5.82 1c0 2-3 3-3 3",key:"mhlwft"}]]);var h=s(63557),g=s(5244),p=s(35327),f=s(91286),v=s(82054),b=s(76245),y=s(37719),j=s(26405),w=s(35087),N=s(47874),A=s(67898),k=s(1862),S=s(7104),C=s(41680),I=s(40643),U=s(10655),D=s(70579);const R=e=>{let t=e.workspaceId;const s=(0,N.ok)(),l=(0,r.A)(s,1)[0],c=l.get("formDocumentId"),x=l.get("formResponseId"),u=(0,n.useState)([]),h=(0,r.A)(u,2),g=h[0],v=h[1],b=(0,n.useState)(!0),y=(0,r.A)(b,2),w=y[0],k=y[1],R=(0,n.useState)(null),L=(0,r.A)(R,2),T=L[0],M=L[1],F=(0,n.useState)(!1),P=(0,r.A)(F,2),E=P[0],_=P[1];(0,n.useEffect)(()=>{const e=(0,A.hg)(i.j2,e=>{_(!0),e||(v([]),k(!1))});return()=>e()},[]);const V=(0,n.useCallback)(async()=>{if(t&&E&&i.j2.currentUser){k(!0);try{var e;const s=(0,o.getFunctions)(),a=(0,o.httpsCallable)(s,"getWorkspaceFormResponses"),r=await a({workspaceId:t});null!==(e=r.data)&&void 0!==e&&e.success&&v(r.data.responses||[])}catch(s){console.error("Failed to load workspace form responses:",s)}finally{k(!1)}}},[t,E]);(0,n.useEffect)(()=>{V()},[V]);const q=(0,n.useRef)(new Set),z=(0,n.useRef)(""),O=(0,n.useCallback)(async e=>{if(M(e),e.unread&&!q.current.has(e.id)){q.current.add(e.id);try{const t=(0,o.getFunctions)(),s=(0,o.httpsCallable)(t,"markFormResponseRead");await s({documentId:e.documentId,responseId:e.id}),v(t=>t.map(t=>t.id===e.id?(0,a.A)((0,a.A)({},t),{},{unread:!1}):t))}catch(t){console.error("Failed to mark form response as read:",t)}}},[]);(0,n.useEffect)(()=>{if(!c||!x||!g.length)return;const e="".concat(c,":").concat(x);if(z.current===e)return;const t=g.find(e=>e.documentId===c&&e.id===x);t&&(z.current=e,O(t))},[g,c,x,O]);const B=e=>{if(!e)return"Unknown";return new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"})},Q=e=>null===e||void 0===e?"\u2014":(0,I.nM)(e)?e.fileName||"Uploaded file":Array.isArray(e)?e.join(", "):"boolean"===typeof e?e?"Yes":"No":"object"===typeof e?"\u2014":String(e),H=(e,t)=>{const s=((null===e||void 0===e?void 0:e.formFields)||[]).find(e=>e.id===t);return(null===s||void 0===s?void 0:s.label)&&String(s.label).trim()||(null===s||void 0===s?void 0:s.type)||t},W=e=>{const t=e.responses||{},s=e.formFields||[],a=s.find(e=>"text"===e.type&&/name/i.test(e.label||""));if(a&&"string"===typeof t[a.id]&&t[a.id].trim())return{text:t[a.id].trim(),type:"name"};const r=s.find(e=>"email"===e.type);if(r&&"string"===typeof t[r.id]&&t[r.id].trim())return{text:t[r.id].trim(),type:"email"};const n=s.find(e=>"phone"===e.type);return n&&"string"===typeof t[n.id]&&t[n.id].trim()?{text:t[n.id].trim(),type:"phone"}:e.submitterEmail?{text:e.submitterEmail,type:"email"}:null},$=(0,n.useCallback)(()=>{if(0===g.length)return;const e=[...new Set(g.flatMap(e=>Object.keys(e.responses||{})))],t=[["Document","Form","Submitted At","Submitter Email",...e.map(e=>{for(const t of g){const s=(t.formFields||[]).find(t=>t.id===e),a=(null===s||void 0===s?void 0:s.label)&&String(s.label).trim()||(null===s||void 0===s?void 0:s.type);if(a)return a}return e})],...g.map(t=>[t.documentTitle||"",t.formTitle||"",B(t.submittedAt),t.submitterEmail||"",...e.map(e=>{var s;const a=null===(s=t.responses)||void 0===s?void 0:s[e];return(0,I.nM)(a)?a.fileName||"Uploaded file":Array.isArray(a)?a.join("; "):String(null!==a&&void 0!==a?a:"")})])].map(e=>e.map(e=>'"'.concat(String(e).replace(/"/g,'""'),'"')).join(",")).join("\n"),s=new Blob([t],{type:"text/csv;charset=utf-8;"}),a=URL.createObjectURL(s),r=document.createElement("a");r.href=a,r.download="form_responses.csv",r.click(),URL.revokeObjectURL(a)},[g]);return w?(0,D.jsx)("div",{className:"flex h-full bg-gray-50 items-center justify-center",children:(0,D.jsx)("div",{className:"animate-spin rounded-full h-6 w-6 border-b-2 border-indigo-500"})}):(0,D.jsxs)("div",{className:"flex h-full bg-gray-50",children:[(0,D.jsxs)("div",{className:"w-[25%] bg-white border-r border-gray-200 overflow-y-auto",children:[(0,D.jsxs)("div",{className:"p-4 border-b border-gray-200 bg-gray-50",children:[(0,D.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,D.jsx)("h2",{className:"text-lg font-semibold text-gray-900",children:"Form Responses"}),g.length>0&&(0,D.jsxs)("button",{onClick:$,className:"text-xs px-2 py-1 rounded bg-gray-200 hover:bg-gray-300 transition-colors flex items-center gap-1",title:"Export all as CSV",children:[(0,D.jsx)(S.A,{className:"w-3 h-3"}),"Export"]})]}),(0,D.jsxs)("p",{className:"text-sm text-gray-500",children:[g.length," response",1!==g.length?"s":""]})]}),(0,D.jsxs)("div",{className:"divide-y divide-gray-200",children:[g.map(e=>(0,D.jsx)("div",{className:"group relative ".concat((null===T||void 0===T?void 0:T.id)===e.id?"bg-blue-50 border-l-4 border-blue-500":""),children:(0,D.jsx)("button",{onClick:()=>O(e),className:"w-full text-left p-4 hover:bg-gray-50 transition-colors",children:(0,D.jsxs)("div",{className:"flex items-start gap-2",children:[(0,D.jsx)(j.A,{className:"w-4 h-4 text-indigo-400 mt-1 flex-shrink-0"}),(0,D.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,D.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,D.jsx)("p",{className:"text-sm font-medium text-gray-900 truncate",children:e.formTitle||"Untitled Form"}),e.unread&&(0,D.jsx)("span",{className:"w-2 h-2 rounded-full bg-indigo-500 flex-shrink-0"})]}),(0,D.jsxs)("div",{className:"flex items-center gap-1 mt-0.5",children:[(0,D.jsx)(C.A,{className:"w-3 h-3 text-gray-400"}),(0,D.jsx)("p",{className:"text-xs text-gray-500 truncate",children:e.documentTitle||"Untitled Document"})]}),(0,D.jsxs)("div",{className:"flex items-center gap-1 mt-0.5",children:[(0,D.jsx)(d.A,{className:"w-3 h-3 text-gray-400"}),(0,D.jsx)("p",{className:"text-xs text-gray-500",children:B(e.submittedAt)})]}),(()=>{const t=W(e);
2if(!t)return(0,D.jsxs)("div",{className:"flex items-center gap-1 mt-0.5",children:[(0,D.jsx)(m.A,{className:"w-3 h-3 text-gray-400"}),(0,D.jsx)("p",{className:"text-xs text-gray-400 italic",children:"Anonymous"})]});const s="email"===t.type?p.A:"phone"===t.type?f.A:m.A;return(0,D.jsxs)("div",{className:"flex items-center gap-1 mt-0.5",children:[(0,D.jsx)(s,{className:"w-3 h-3 text-gray-400"}),(0,D.jsx)("p",{className:"text-xs text-gray-500 truncate",children:t.text})]})})()]})]})})},e.id)),0===g.length&&(0,D.jsxs)("div",{className:"p-8 text-center text-gray-500",children:[(0,D.jsx)(j.A,{className:"w-12 h-12 mx-auto mb-2 text-gray-300"}),(0,D.jsx)("p",{className:"text-sm",children:"No form responses yet"}),(0,D.jsx)("p",{className:"text-xs text-gray-400 mt-1",children:"Responses will appear here when visitors submit forms"})]})]})]}),(0,D.jsx)("div",{className:"flex-1 flex flex-col",children:T?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)("div",{className:"p-4 bg-white border-b border-gray-200",children:[(0,D.jsx)("h3",{className:"text-lg font-semibold text-gray-900",children:T.formTitle||"Form Response"}),(0,D.jsx)("p",{className:"text-sm text-gray-500 mt-0.5",children:T.documentTitle||"Untitled Document"}),(0,D.jsxs)("div",{className:"flex items-center gap-3 mt-1.5 text-xs text-gray-400",children:[(0,D.jsxs)("span",{className:"flex items-center gap-1",children:[(0,D.jsx)(d.A,{className:"w-3 h-3"}),B(T.submittedAt)]}),(()=>{const e=W(T);if(!e)return(0,D.jsxs)("span",{className:"flex items-center gap-1 italic",children:[(0,D.jsx)(m.A,{className:"w-3 h-3"}),"Anonymous"]});const t="email"===e.type?p.A:"phone"===e.type?f.A:m.A;return(0,D.jsxs)("span",{className:"flex items-center gap-1",children:[(0,D.jsx)(t,{className:"w-3 h-3"}),e.text]})})()]})]}),(0,D.jsx)("div",{className:"flex-1 overflow-y-auto p-6",children:(0,D.jsx)("div",{className:"max-w-2xl space-y-3",children:T.wizardBatch&&Array.isArray(T.steps)?T.steps.map((e,t)=>(0,D.jsxs)("details",{className:"bg-white border border-gray-200 rounded-lg shadow-sm",open:0===t,children:[(0,D.jsx)("summary",{className:"cursor-pointer px-4 py-3 text-sm font-semibold text-gray-900",children:e.formTitle||"Section ".concat(t+1)}),(0,D.jsx)("div",{className:"px-4 pb-4 space-y-3 border-t border-gray-100",children:Object.entries(e.responses||{}).map(t=>{let s=(0,r.A)(t,2),a=s[0],n=s[1];const l=(e.formFields||[]).find(e=>e.id===a);return(0,D.jsxs)("div",{children:[(0,D.jsx)("div",{className:"text-xs font-semibold text-gray-600 mb-1",children:(null===l||void 0===l?void 0:l.label)&&String(l.label).trim()||(null===l||void 0===l?void 0:l.type)||a}),(0,D.jsx)("div",{className:"text-sm text-gray-900",children:(0,I.nM)(n)?(0,D.jsx)(U.A,{documentId:T.documentId,value:n,fieldType:null===l||void 0===l?void 0:l.type}):Q(n)})]},a)})})]},"".concat(e.formId,"-").concat(t))):Object.entries(T.responses||{}).map(e=>{let t=(0,r.A)(e,2),s=t[0],a=t[1];const n=((e,t)=>((null===e||void 0===e?void 0:e.formFields)||[]).find(e=>e.id===t)||null)(T,s);return(0,D.jsxs)("div",{className:"bg-white border border-gray-200 rounded-lg p-4 shadow-sm",children:[(0,D.jsx)("div",{className:"text-xs font-semibold text-gray-600 mb-1",children:H(T,s)}),(0,D.jsx)("div",{className:"text-sm text-gray-900",children:(0,I.nM)(a)?(0,D.jsx)(U.A,{documentId:T.documentId,value:a,fieldType:null===n||void 0===n?void 0:n.type}):Q(a)})]},s)})})})]}):(0,D.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center text-gray-500",children:[(0,D.jsx)(j.A,{className:"w-16 h-16 mb-4 text-gray-300"}),(0,D.jsx)("p",{className:"text-lg font-medium",children:"Select a response to view details"}),(0,D.jsx)("p",{className:"text-sm mt-1",children:"Choose from the list on the left"})]})})]})};var L=s(46963);const T=(0,x.A)("tablet",[["rect",{width:"16",height:"20",x:"4",y:"2",rx:"2",ry:"2",key:"76otgf"}],["line",{x1:"12",x2:"12.01",y1:"18",y2:"18",key:"1dp563"}]]),M=(0,x.A)("monitor",[["rect",{width:"20",height:"14",x:"2",y:"3",rx:"2",key:"48i651"}],["line",{x1:"8",x2:"16",y1:"21",y2:"21",key:"1svkeh"}],["line",{x1:"12",x2:"12",y1:"17",y2:"21",key:"vw1qmm"}]]);var F=s(10629),P=s(27033),E=s(58487),_=s(70764),V=s(92382),q=s(38326),z=s(55731),O=s(84669),B=s(97666),Q=s(39292);const H=(0,x.A)("arrow-down-to-line",[["path",{d:"M12 17V3",key:"1cwfxf"}],["path",{d:"m6 11 6 6 6-6",key:"12ii2o"}],["path",{d:"M19 21H5",key:"150jfl"}]]);function W(e){if(!e||e<=0)return"0s";const t=Math.round(e/1e3);if(t<60)return"".concat(t,"s");const s=Math.floor(t/60),a=t%60;
2if(s<60)return a>0?"".concat(s,"m ").concat(a,"s"):"".concat(s,"m");const r=Math.floor(s/60),n=s%60;return n>0?"".concat(r,"h ").concat(n,"m"):"".concat(r,"h")}function $(e){if(!e)return"";const t=new Date(e),s=new Date-t,a=Math.floor(s/1e3);if(a<60)return"just now";const r=Math.floor(a/60);if(r<60)return"".concat(r,"m ago");const n=Math.floor(r/60);if(n<24)return"".concat(n,"h ago");const l=Math.floor(n/24);return l<30?"".concat(l,"d ago"):t.toLocaleDateString()}function J(e){let t=e.type,s=e.className,a=void 0===s?"w-3.5 h-3.5":s;return"mobile"===t?(0,D.jsx)(L.A,{className:a}):"tablet"===t?(0,D.jsx)(T,{className:a}):(0,D.jsx)(M,{className:a})}function Z(e){let t=e.linkData;return t.mascotMode?(0,D.jsxs)("span",{className:"inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-amber-50 text-amber-800",children:[(0,D.jsx)(F.A,{className:"w-3 h-3"}),"Mascot"]}):t.documentId?(0,D.jsxs)("span",{className:"inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-purple-50 text-purple-600",children:[(0,D.jsx)(C.A,{className:"w-3 h-3"}),"Single doc"]}):t.shareAsReport?(0,D.jsxs)("span",{className:"inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-amber-50 text-amber-600",children:[(0,D.jsx)(P.A,{className:"w-3 h-3"}),"Report"]}):(0,D.jsxs)("span",{className:"inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-blue-50 text-blue-600",children:[(0,D.jsx)(E.A,{className:"w-3 h-3"}),"Workspace"]})}function G(e){let t=e.label,s=e.value,a=e.sub;return(0,D.jsxs)("div",{className:"bg-white border border-gray-200 rounded-lg p-3 flex-1 min-w-0",children:[(0,D.jsx)("p",{className:"text-xs text-gray-500 truncate",children:t}),(0,D.jsx)("p",{className:"text-lg font-semibold text-gray-900 mt-0.5",children:s}),a&&(0,D.jsx)("p",{className:"text-xs text-gray-400 mt-0.5 truncate",children:a})]})}const X=e=>{var t;let s=e.workspaceId;
2const c=(0,N.ok)(),d=(0,r.A)(c,2),x=d[0],u=d[1],p=(0,n.useState)([]),f=(0,r.A)(p,2),v=f[0],b=f[1],y=(0,n.useState)(!0),j=(0,r.A)(y,2),S=j[0],I=j[1],U=(0,n.useState)(null),R=(0,r.A)(U,2),L=R[0],T=R[1],M=(0,n.useState)([]),P=(0,r.A)(M,2),E=P[0],X=P[1],Y=(0,n.useState)(!1),K=(0,r.A)(Y,2),ee=K[0],te=K[1],se=(0,n.useState)(null),ae=(0,r.A)(se,2),re=ae[0],ne=ae[1],le=(0,n.useState)(!1),ie=(0,r.A)(le,2),oe=ie[0],ce=ie[1],de=(0,n.useState)(""),me=(0,r.A)(de,2),xe=me[0],ue=me[1],he=(0,n.useState)(!1),ge=(0,r.A)(he,2),pe=ge[0],fe=ge[1],ve=(0,n.useState)(!1),be=(0,r.A)(ve,2),ye=be[0],je=be[1],we=(0,n.useState)(new Set),Ne=(0,r.A)(we,2),Ae=Ne[0],ke=Ne[1],Se=(0,n.useRef)(new Set),Ce=(0,n.useCallback)(e=>{if(!e||"string"!==typeof e)return;const t=e.trim();if(!t)return;const s=new URLSearchParams(x);s.set("tab","chats"),s.set("selected",t),u(s,{replace:!1})},[x,u]);(0,n.useEffect)(()=>{const e=(0,A.hg)(i.j2,e=>{ce(!0),e||(b([]),I(!1))});return()=>e()},[]),(0,n.useEffect)(()=>{s&&oe&&i.j2.currentUser&&(0,l.getDoc)((0,l.doc)(i.db,"workspaces",s)).then(e=>{e.exists()&&ue(e.data().name||"")}).catch(()=>{})},[s,oe]),(0,n.useEffect)(()=>{if(!s||!oe||!i.j2.currentUser)return;const e=(0,l.P)((0,l.rJ)(i.db,"shareableLinks"),(0,l._M)("workspaceId","==",s)),t=(0,l.aQ)(e,async e=>{const t=e.docs.map(e=>(0,a.A)({id:e.id},e.data())).filter(e=>{var t;return((null===(t=e.analytics)||void 0===t?void 0:t.totalSessions)||0)>0||(e.viewCount||0)>0}).sort((e,t)=>{var s,a,r,n,l,i,o,c;const d=(null===(s=e.analytics)||void 0===s||null===(a=s.lastSessionAt)||void 0===a||null===(r=a.toDate)||void 0===r?void 0:r.call(a))||new Date((null===(n=e.analytics)||void 0===n?void 0:n.lastSessionAt)||0);return((null===(l=t.analytics)||void 0===l||null===(i=l.lastSessionAt)||void 0===i||null===(o=i.toDate)||void 0===o?void 0:o.call(i))||new Date((null===(c=t.analytics)||void 0===c?void 0:c.lastSessionAt)||0))-d}),s=[...new Set(t.filter(e=>e.documentId).map(e=>e.documentId))],r={};for(const a of s)try{const e=await(0,l.getDoc)((0,l.doc)(i.db,"knowledgeBaseDocuments",a));if(e.exists()){const t=e.data();r[a]=t.title||t.fileName||"Untitled"}}catch(n){}t.forEach(e=>{e.documentId&&r[e.documentId]&&(e._resolvedDocTitle=r[e.documentId])}),b(t),I(!1),T(e=>{if(!e)return e;return t.find(t=>t.id===e.id)||e})},e=>{(0,k.gg)("ShareViews links listener error:",e.message),I(!1)});return()=>t()},[s,oe]);const Ie=(0,n.useRef)(null),Ue=(0,n.useCallback)(e=>{Ie.current&&Ie.current(),te(!0);const t=(0,l.P)((0,l.rJ)(i.db,"shareableLinks",e,"viewSessions"),(0,l.My)("startedAt","desc"),(0,l.AB)(50));Ie.current=(0,l.aQ)(t,e=>{const t=e.docs.map(e=>{var t,s,r,n,l,i,o,c,d;const m=e.data();return(0,a.A)((0,a.A)({id:e.id},m),{},{startedAt:(null===(t=m.startedAt)||void 0===t||null===(s=t.toDate)||void 0===s||null===(r=s.call(t))||void 0===r?void 0:r.toISOString())||null,lastHeartbeatAt:(null===(n=m.lastHeartbeatAt)||void 0===n||null===(l=n.toDate)||void 0===l||null===(i=l.call(n))||void 0===i?void 0:i.toISOString())||null,endedAt:(null===(o=m.endedAt)||void 0===o||null===(c=o.toDate)||void 0===c||null===(d=c.call(o))||void 0===d?void 0:d.toISOString())||null})});X(t),te(!1)},e=>{(0,k.gg)("Sessions listener error:",e.message),X([]),te(!1)})},[]);(0,n.useEffect)(()=>()=>{Ie.current&&Ie.current()},[]);const De=(0,n.useCallback)(async e=>{var t;if(T(e),ne(null),Ue(e.id),(null===(t=e.analytics)||void 0===t?void 0:t.unreadSessions)>0&&!Se.current.has(e.id)){Se.current.add(e.id);try{const t=(0,o.getFunctions)(void 0,"us-central1"),s=(0,o.httpsCallable)(t,"markShareViewsRead");await s({linkDocId:e.id})}catch(s){(0,k.gg)("markShareViewsRead error:",s.message)}}},[Ue]),Re=e=>e.linkLabel?e.linkLabel:e.documentId?e._resolvedDocTitle||"Shared Document":xe||(e.slugId||"Share Link"),Le=(0,n.useCallback)(async(e,t,s)=>{if(e.stopPropagation(),L){ke(e=>new Set(e).add(t));try{const e=(0,o.getFunctions)(void 0,"us-central1"),a=(0,o.httpsCallable)(e,"archiveViewSession");await a({linkDocId:L.id,sessionId:t,archived:s})}catch(a){(0,k.gg)("archiveViewSession error:",a.message)}finally{ke(e=>{const s=new Set(e);return s.delete(t),s})}}},[L]),Te=(0,n.useCallback)(async(e,t,s)=>{e.stopPropagation();
2try{const e=(0,l.doc)(i.db,"shareableLinks",t),a=!s,r={archived:a,archivedAt:a?new Date:null};a&&(r["analytics.unreadSessions"]=0),await(0,l.mZ)(e,r),(null===L||void 0===L?void 0:L.id)===t&&a&&T(null)}catch(a){(0,k.gg)("toggleLinkArchive error:",a.message)}},[L]),Me=v.filter(e=>pe?!0===e.archived:!0!==e.archived),Fe=ye?E:E.filter(e=>!e.archived),Pe=(E.filter(e=>e.archived).length,L&&(L.linkId||L.slugId)?"/shared/".concat(encodeURIComponent(L.linkId||L.slugId)):null);if(S)return(0,D.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,D.jsx)("div",{className:"text-gray-500",children:"Loading view analytics..."})});if(0===v.length)return(0,D.jsxs)("div",{className:"flex flex-col items-center justify-center h-full text-gray-500",children:[(0,D.jsx)(w.A,{className:"w-16 h-16 mb-4 text-gray-300"}),(0,D.jsx)("p",{className:"text-lg font-medium",children:"No views yet"}),(0,D.jsx)("p",{className:"text-sm mt-1",children:"View analytics will appear here when someone opens your shared links"})]});const Ee=(null===L||void 0===L?void 0:L.analytics)||{},_e=(Ee.distinctAnonIds||0)+(Ee.distinctViewerUids||0);return(0,D.jsxs)("div",{className:"flex h-full min-h-0",children:[(0,D.jsxs)("div",{className:"w-[30%] min-w-[240px] max-w-[340px] bg-white border-r border-gray-200 flex flex-col",children:[(0,D.jsxs)("div",{className:"px-4 py-3 border-b border-gray-200 flex items-center justify-between shrink-0",children:[(0,D.jsxs)("h3",{className:"text-sm font-medium text-gray-700",children:[Me.length," ",pe?"archived":"active"]}),(0,D.jsx)("button",{onClick:()=>fe(e=>!e),className:"text-xs px-2 py-1 rounded bg-gray-200 hover:bg-gray-300 transition-colors",title:pe?"Show active links":"Show archived links",children:pe?"Active":"Archived"})]}),(0,D.jsx)("div",{className:"overflow-y-auto flex-1",children:0===Me.length?(0,D.jsxs)("div",{className:"py-8 text-center text-gray-500",children:[(0,D.jsx)(g.A,{className:"w-12 h-12 mx-auto mb-2 text-gray-300"}),(0,D.jsxs)("p",{className:"text-sm",children:["No ",pe?"archived":"active"," links"]})]}):Me.map(e=>{var t,s,a,r;const n=e.analytics||{},l=(null===L||void 0===L?void 0:L.id)===e.id,i=(n.unreadSessions||0)>0,o=(null===(t=n.lastSessionAt)||void 0===t||null===(s=t.toDate)||void 0===s||null===(a=s.call(t))||void 0===a||null===(r=a.toISOString)||void 0===r?void 0:r.call(a))||n.lastSessionAt;return(0,D.jsxs)("div",{className:"relative group",children:[(0,D.jsx)("button",{onClick:()=>De(e),className:"w-full text-left px-4 py-3 pr-10 border-b border-gray-100 transition-colors ".concat(l?"bg-blue-50":"hover:bg-gray-50"),children:(0,D.jsxs)("div",{className:"flex items-start gap-2",children:[i&&(0,D.jsx)("span",{className:"mt-1.5 w-2 h-2 rounded-full bg-blue-500 shrink-0"}),(0,D.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,D.jsx)("p",{className:"text-sm truncate ".concat(i?"font-semibold text-gray-900":"font-medium text-gray-700"),children:Re(e)}),(0,D.jsxs)("div",{className:"flex items-center gap-2 mt-1",children:[(0,D.jsx)(Z,{linkData:e}),(0,D.jsxs)("span",{className:"text-xs text-gray-400",children:[n.totalSessions||e.viewCount||0," views"]})]}),o&&(0,D.jsx)("p",{className:"text-xs text-gray-400 mt-1",children:$(o)})]})]})}),(0,D.jsx)("button",{onClick:t=>Te(t,e.id,e.archived),className:"absolute top-3 right-3 p-1.5 rounded opacity-0 group-hover:opacity-100 hover:bg-gray-200 transition-all",title:e.archived?"Unarchive":"Archive",children:e.archived?(0,D.jsx)(h.A,{className:"w-4 h-4 text-gray-600"}):(0,D.jsx)(g.A,{className:"w-4 h-4 text-gray-600"})})]},e.id)})})]}),(0,D.jsx)("div",{className:"flex-1 overflow-y-auto bg-gray-50",children:L?(0,D.jsxs)("div",{className:"p-6 max-w-4xl",children:[(0,D.jsx)("h2",{className:"text-lg font-semibold text-gray-900 mb-1",children:Re(L)}),(0,D.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3 mb-5",children:[(0,D.jsxs)("div",{className:"flex items-center gap-2 min-w-0 flex-wrap",children:[(0,D.jsx)(Z,{linkData:L}),(L.linkId||L.slugId)&&(0,D.jsxs)("span",{className:"text-xs text-gray-400 font-mono",children:["/",L.slugId||(null===(t=L.linkId)||void 0===t?void 0:t.slice(0,12))||"\u2026"]})]}),(0,D.jsx)("div",{className:"flex items-center gap-3 flex-wrap shrink-0",children:Pe&&(0,D.jsxs)(N.N_,{to:Pe,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1.5 text-sm text-blue-600 hover:text-blue-800 font-medium",children:[(0,D.jsx)(_.A,{className:"w-4 h-4 shrink-0"}),"View shared page"]})})]}),(0,D.jsxs)("div",{className:"flex gap-3 mb-6 flex-wrap",children:[(0,D.jsx)(G,{label:"Total Sessions",value:Ee.totalSessions||0}),(0,D.jsx)(G,{label:"Distinct Viewers",value:_e,sub:Ee.totalAuthenticatedSessions?"".concat(Ee.totalAuthenticatedSessions," signed in"):void 0}),(0,D.jsx)(G,{label:"Total Active Time",value:W(Ee.totalActiveMs)}),(0,D.jsx)(G,{label:"Avg Active Time",value:Ee.totalSessions?W(Math.round((Ee.totalActiveMs||0)/Ee.totalSessions)):"\u2014"})]}),(0,D.jsxs)("div",{className:"bg-white border border-gray-200 rounded-lg overflow-hidden",children:[(0,D.jsxs)("div",{className:"px-4 py-3 border-b border-gray-200 bg-gray-50/50 flex items-center justify-between",children:[(0,D.jsx)("h3",{className:"text-sm font-medium text-gray-700",children:"Recent Sessions"}),(0,D.jsx)("button",{onClick:()=>je(e=>!e),className:"text-xs px-2 py-1 rounded bg-gray-200 hover:bg-gray-300 transition-colors",title:ye?"Show active sessions":"Show archived sessions",children:ye?"Active":"Archived"})]}),ee?(0,D.jsx)("div",{className:"flex items-center justify-center py-12 text-gray-400",children:"Loading sessions..."}):0===Fe.length?(0,D.jsxs)("div",{className:"py-8 text-center text-gray-500",children:[(0,D.jsx)(g.A,{className:"w-12 h-12 mx-auto mb-2 text-gray-300"}),(0,D.jsxs)("p",{className:"text-sm",children:["No ",ye?"archived":"active"," sessions"]})]}):(0,D.jsxs)("div",{children:[(0,D.jsxs)("div",{className:"hidden sm:grid grid-cols-[1fr_100px_70px_70px_90px_40px] gap-2 px-4 py-2 bg-gray-50 border-b border-gray-100 text-xs font-medium text-gray-500 uppercase tracking-wider",children:[(0,D.jsx)("span",{children:"Viewer"}),(0,D.jsx)("span",{children:"When"}),(0,D.jsx)("span",{children:"Active"}),(0,D.jsx)("span",{children:"Scroll"}),(0,D.jsx)("span",{children:"Device"}),(0,D.jsx)("span",{})]}),Fe.map(e=>{var t,s;const a=re===e.id,r="authenticated"===e.viewerType?e.viewerName||e.viewerEmail||"Signed-in user":"Anonymous",n=e.device||{};return(0,D.jsxs)("div",{className:"group/row ".concat(e.archived?"opacity-60":""),children:[(0,D.jsxs)("div",{onClick:()=>ne(a?null:e.id),className:"w-full text-left grid grid-cols-1 sm:grid-cols-[1fr_100px_70px_70px_90px_40px] gap-1 sm:gap-2 px-4 py-3 border-b border-gray-100 hover:bg-gray-50 transition-colors items-center cursor-pointer",children:[(0,D.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[a?(0,D.jsx)(V.A,{className:"w-3.5 h-3.5 text-gray-400 shrink-0"}):(0,D.jsx)(q.A,{className:"w-3.5 h-3.5 text-gray-400 shrink-0"}),"authenticated"===e.viewerType?(0,D.jsx)(m.A,{className:"w-4 h-4 text-blue-500 shrink-0"}):(0,D.jsx)(z.A,{className:"w-4 h-4 text-gray-400 shrink-0"}),(0,D.jsx)("span",{className:"text-sm text-gray-800 truncate",title:r,children:r})]}),(0,D.jsxs)("span",{className:"text-xs text-gray-500 flex items-center gap-1.5",children:[$(e.startedAt),Array.isArray(e.events)&&e.events.length>0&&(0,D.jsxs)("span",{className:"inline-flex items-center gap-0.5 text-[10px] font-medium text-blue-600 bg-blue-50 rounded px-1 py-0.5",title:"".concat(e.events.length," question").concat(1===e.events.length?"":"s"," / FAQ click").concat(1===e.events.length?"":"s"),children:[(0,D.jsx)(O.A,{className:"w-2.5 h-2.5"}),e.events.length]})]}),(0,D.jsx)("span",{className:"text-xs text-gray-700 font-medium",children:W(e.activeMs)}),(0,D.jsxs)("span",{className:"text-xs text-gray-700 font-medium",children:[null!==(t=e.maxScrollPct)&&void 0!==t?t:0,"%"]}),(0,D.jsxs)("div",{className:"flex items-center gap-1 text-xs text-gray-500",children:[(0,D.jsx)(J,{type:n.deviceType}),(0,D.jsx)("span",{className:"truncate",children:n.browser||""})]}),(0,D.jsx)("div",{className:"flex justify-center",children:(0,D.jsx)("button",{onClick:t=>Le(t,e.id,!e.archived),disabled:Ae.has(e.id),className:"p-1 rounded opacity-0 group-hover/row:opacity-100 hover:bg-gray-200 transition-all disabled:opacity-50",title:e.archived?"Unarchive":"Archive",children:e.archived?(0,D.jsx)(h.A,{className:"w-4 h-4 text-gray-600"}):(0,D.jsx)(g.A,{className:"w-4 h-4 text-gray-600"})})})]}),a&&(0,D.jsxs)("div",{className:"bg-gray-50 px-8 py-3 border-b border-gray-100",children:[(0,D.jsxs)("div",{className:"grid grid-cols-2 gap-x-6 gap-y-2 text-xs mb-3",children:[(0,D.jsxs)("div",{children:[(0,D.jsx)("span",{className:"text-gray-500",children:"OS:"})," ",(0,D.jsx)("span",{className:"text-gray-700",children:n.os||"Unknown"})]}),(0,D.jsxs)("div",{children:[(0,D.jsx)("span",{className:"text-gray-500",children:"Browser:"})," ",(0,D.jsx)("span",{className:"text-gray-700",children:n.browser||"Unknown"})]}),e.referrer&&(0,D.jsxs)("div",{className:"col-span-2",children:[(0,D.jsx)("span",{className:"text-gray-500",children:"Referrer:"})," ",(0,D.jsx)("span",{className:"text-gray-700 break-all",children:e.referrer})]}),(0,D.jsxs)("div",{children:[(0,D.jsx)("span",{className:"text-gray-500",children:"Started:"})," ",(0,D.jsx)("span",{className:"text-gray-700",children:e.startedAt?new Date(e.startedAt).toLocaleStr
2ing():"\u2014"})]}),(0,D.jsxs)("div",{children:[(0,D.jsx)("span",{className:"text-gray-500",children:"Ended:"})," ",(0,D.jsx)("span",{className:"text-gray-700",children:e.endedAt?new Date(e.endedAt).toLocaleString():"In progress"})]})]}),Array.isArray(e.events)&&e.events.length>0&&(0,D.jsxs)("div",{className:"mb-3",children:[(0,D.jsxs)("p",{className:"text-xs font-medium text-gray-600 mb-1.5 flex items-center gap-1",children:[(0,D.jsx)(O.A,{className:"w-3 h-3"}),"Questions & FAQs (",e.events.length,")"]}),(0,D.jsx)("div",{className:"space-y-1",children:[...e.events].sort((e,t)=>(null!==e&&void 0!==e&&e.at?new Date(e.at).getTime():0)-(null!==t&&void 0!==t&&t.at?new Date(t.at).getTime():0)).map((e,t)=>{const s="faqClick"===(null===e||void 0===e?void 0:e.type),a="mascotAsk"===(null===e||void 0===e?void 0:e.type),r="mascotPhrase"===(null===e||void 0===e?void 0:e.type),n="mascotReplay"===(null===e||void 0===e?void 0:e.type),l=s?B.A:a||r||n?F.A:Q.A,i=s?"FAQ click":a?"Mascot question":r?"Mascot phrase":n?"Mascot replay":"Search",o=a||r||n,c="string"===typeof(null===e||void 0===e?void 0:e.chatId)&&e.chatId.trim(),d="flex items-start gap-2 text-xs bg-white rounded px-3 py-1.5 border border-gray-100",m=(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(l,{className:"w-3 h-3 mt-0.5 shrink-0 ".concat(s?"text-purple-500":o?"text-amber-600":"text-blue-500")}),(0,D.jsx)("span",{className:"shrink-0 text-[10px] font-medium uppercase tracking-wide ".concat(s?"text-purple-600":o?"text-amber-700":"text-blue-600"),title:i,children:s?"FAQ":a?"Ask":r?"Say":n?"Replay":"Q"}),(0,D.jsx)("span",{className:"flex-1 text-gray-700 break-words",children:(null===e||void 0===e?void 0:e.text)||""}),(null===e||void 0===e?void 0:e.at)&&(0,D.jsx)("span",{className:"text-gray-400 shrink-0",title:new Date(e.at).toLocaleString(),children:$(e.at)})]});return c?(0,D.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation(),Ce(e.chatId)},className:"".concat(d," w-full text-left cursor-pointer hover:bg-blue-50/80 hover:border-blue-100 transition-colors"),title:"Open in Chats",children:m},"".concat((null===e||void 0===e?void 0:e.at)||t,"-").concat(t)):(0,D.jsx)("div",{className:d,children:m},"".concat((null===e||void 0===e?void 0:e.at)||t,"-").concat(t))})})]}),(null===(s=e.documentsViewed)||void 0===s?void 0:s.length)>0&&(0,D.jsxs)("div",{children:[(0,D.jsxs)("p",{className:"text-xs font-medium text-gray-600 mb-1.5 flex items-center gap-1",children:[(0,D.jsx)(C.A,{className:"w-3 h-3"}),"Documents Viewed (",e.documentsViewed.length,")"]}),(0,D.jsx)("div",{className:"space-y-1",children:e.documentsViewed.map((e,t)=>{var s,a;return(0,D.jsxs)("div",{className:"flex items-center gap-3 text-xs bg-white rounded px-3 py-1.5 border border-gray-100",children:[(0,D.jsx)("span",{className:"flex-1 text-gray-700 truncate",children:e.title||(null===(s=e.documentId)||void 0===s?void 0:s.slice(0,12))||"Document"}),(0,D.jsx)("span",{className:"text-gray-500 shrink-0",children:W(e.activeMs)}),(0,D.jsxs)("span",{className:"text-gray-500 shrink-0 flex items-center gap-0.5",children:[(0,D.jsx)(H,{className:"w-3 h-3"}),null!==(a=e.maxScrollPct)&&void 0!==a?a:0,"%"]})]},t)})})]})]})]},e.id)})]})]})]}):(0,D.jsxs)("div",{className:"flex flex-col items-center justify-center h-full text-gray-500",children:[(0,D.jsx)(w.A,{className:"w-16 h-16 mb-4 text-gray-300"}),(0,D.jsx)("p",{className:"text-lg font-medium",children:"Select a share link to view analytics"}),(0,D.jsx)("p",{className:"text-sm mt-1",children:"Choose from the list on the left"})]})})]})};var Y=s(45580),K=s(67126);const ee=(0,o.httpsCallable)(i.Cn,"sendStaffChatReply"),te=(0,o.httpsCallable)(i.Cn,"publishMissingAnswerDraft"),se=(0,o.httpsCallable)(i.Cn,"discardMissingAnswerDraft"),ae="missing_answer_review",re="missing_answer_discarded",ne="completed";function le(e){return"permission-denied"===(null===e||void 0===e?void 0:e.code)?{title:"Could not open this chat",message:"You're signed in, but this account does not have access to this workspace. Switch accounts or ask a workspace admin for access.",actionLabel:"Switch account"}:"unavailable"===(null===e||void 0===e?void 0:e.code)?{title:"Connection interrupted",message:"Based could not reach chat history. Check your connection and try again.",actionLabel:"Try again"}:{title:"Could not load chat history",message:"Something went wrong while loading this workspace chat inbox. Try again in a moment.",actionLabel:"Try again"}}function ie(e){return{title:"Chat not found",message:"The linked chat (".concat(e,") is not available in this workspace. It may have been deleted, archived by rules, or opened from an account without access.")}}function oe(e){let t=e.title,s=e.message,a=e.actionLabel,r=e.onAction;return(0,D.jsx)("div",{className:"flex-1 flex items-center justify-center px-6 py-10",children:(0,D.jsxs)("div",{role:"alert",className:"max-w-md w-full rounded-lg border border-gray-200 bg-white p-6 text-center shadow-sm",children:[(0,D.jsx)(y.A,{className:"w-10 h-10 mx-auto text-amber-500 mb-3"}),(0,D.jsx)("h2",{className:"text-lg font-semibold text-gray-900",children:t}),(0,D.jsx)("p",{className:"mt-2 text-sm text-gray-600",children:s}),a&&r&&(0,D.jsx)("button",{type:"button",onClick:r,className:"mt-5 inline-flex items-center justify-center rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2",children:a})]})})}function ce(e){let t=e.status;return t===ae?(0,D.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full bg-amber-100 text-amber-800 px-2 py-1 text-xs font-medium",children:[(0,D.jsx)(y.A,{className:"w-3 h-3"}),"Review needed"]}):t===ne?(0,D.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full bg-green-100 text-green-800 px-2 py-1 text-xs font-medium",children:[(0,D.jsx)(v.A,{className:"w-3 h-3"}),"Published"]}):t===re?(0,D.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full bg-gray-100 text-gray-700 px-2 py-1 text-xs font-medium",children:[(0,D.jsx)(b.A,{className:"w-3 h-3"}),"Discarded"]}):(0,D.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full bg-blue-100 text-blue-800 px-2 py-1 text-xs font-medium",children:[(0,D.jsx)(u,{className:"w-3 h-3"}),t||"Tracked"]})}function de(e){let t=e.activeTab,s=e.onTabChange,a=e.hasUnreadChats,r=e.hasUnreadViews,n=e.hasUnreadForms;return(0,D.jsx)("div",{className:"bg-white border-b border-gray-200 px-4 flex-shrink-0",children:(0,D.jsxs)("div",{className:"flex gap-1",children:[(0,D.jsxs)("button",{onClick:()=>s("chats"),className:"relative flex items-center gap-2 px-4 py-2.5 text-sm font-medium border-b-2 transition-colors ".concat("chats"===t?"border-blue-500 text-blue-600":"border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300"),children:[(0,D.jsx)(c.A,{className:"w-4 h-4"}),"Chats",a&&"chats"!==t&&(0,D.jsx)("span",{className:"w-2 h-2 rounded-full bg-red-500"})]}),(0,D.jsxs)("button",{onClick:()=>s("formResponses"),className:"relative flex items-center gap-2 px-4 py-2.5 text-sm font-medium border-b-2 transition-colors ".concat("formResponses"===t?"border-blue-500 text-blue-600":"border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300"),children:[(0,D.jsx)(j.A,{className:"w-4 h-4"}),"Form Responses",n&&"formResponses"!==t&&(0,D.jsx)("span",{className:"w-2 h-2 rounded-full bg-red-500"})]}),(0,D.jsxs)("button",{onClick:()=>s("views"),className:"relative flex items-center gap-2 px-4 py-2.5 text-sm font-medium border-b-2 transition-colors ".concat("views"===t?"border-blue-500 text-blue-600":"border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300"),children:[(0,D.jsx)(w.A,{className:"w-4 h-4"}),"Views",r&&"views"!==t&&(0,D.jsx)("span",{className:"w-2 h-2 rounded-full bg-red-500"})]})]})})}const me=e=>{var t,s,o,x,y,j,w,S,C;let I=e.workspaceId,U=e.initialTab,L=e.showUnreadIndicators,T=void 0===L||L,M=e.unreadFormCount,F=void 0===M?0:M;
2const P=(0,n.useState)([]),E=(0,r.A)(P,2),_=E[0],V=E[1],q=(0,n.useState)(!0),z=(0,r.A)(q,2),O=z[0],B=z[1],Q=(0,n.useState)(0),H=(0,r.A)(Q,2),W=H[0],$=H[1],J=(0,n.useState)(null),Z=(0,r.A)(J,2),G=Z[0],me=Z[1],xe=(0,n.useState)(null),ue=(0,r.A)(xe,2),he=ue[0],ge=ue[1],pe=(0,n.useState)(null),fe=(0,r.A)(pe,2),ve=fe[0],be=fe[1],ye=(0,n.useState)(""),je=(0,r.A)(ye,2),we=je[0],Ne=je[1],Ae=(0,n.useState)(!1),ke=(0,r.A)(Ae,2),Se=ke[0],Ce=ke[1],Ie=(0,n.useState)(null),Ue=(0,r.A)(Ie,2),De=Ue[0],Re=Ue[1],Le=(0,n.useState)(!1),Te=(0,r.A)(Le,2),Me=Te[0],Fe=Te[1],Pe=(0,n.useState)(!1),Ee=(0,r.A)(Pe,2),_e=Ee[0],Ve=Ee[1],qe=(0,n.useState)(!1),ze=(0,r.A)(qe,2),Oe=ze[0],Be=ze[1],Qe=(0,n.useState)(null),He=(0,r.A)(Qe,2),We=He[0],$e=He[1],Je=(0,N.ok)(),Ze=(0,r.A)(Je,1)[0],Ge=(0,n.useState)(!1),Xe=(0,r.A)(Ge,2),Ye=Xe[0],Ke=Xe[1],et=(0,n.useState)(U||"chats"),tt=(0,r.A)(et,2),st=tt[0],at=tt[1],rt=(0,N.Zp)(),nt=(0,N.zy)(),lt=(0,n.useRef)(!1),it=(0,n.useRef)(null);(0,n.useEffect)(()=>{const e=Ze.get("tab");"chats"!==e&&"formResponses"!==e&&"views"!==e||at(e)},[Ze]);const ot=T&&_.some(e=>!0===e.unread&&!0!==e.archived),ct=T&&(F||0)>0,dt=_.filter(e=>{var t;return(null===(t=e.missingAnswer)||void 0===t?void 0:t.status)===ae}).length,mt=(0,n.useState)(!1),xt=(0,r.A)(mt,2),ut=xt[0],ht=xt[1];(0,n.useEffect)(()=>{if(!T)return void ht(!1);if(!I||!Ye||!i.j2.currentUser)return;const e=(0,l.P)((0,l.rJ)(i.db,"shareableLinks"),(0,l._M)("workspaceId","==",I)),t=(0,l.aQ)(e,e=>{const t=e.docs.some(e=>{var t;const s=e.data()||{};return!0!==s.archived&&((null===(t=s.analytics)||void 0===t?void 0:t.unreadSessions)||0)>0});ht(t)},e=>{(0,k.gg)("Unread views listener error:",e.message)});return()=>t()},[I,Ye,T]),(0,n.useEffect)(()=>{let e=!1;return(async()=>{var t;if(await(t=i.j2,new Promise(e=>{const s=(0,A.hg)(t,()=>{s(),e()})})),!e)if(i.j2.currentUser)lt.current=!0,(0,k.gg)("\u2705 Logged in as:",i.j2.currentUser.uid),Ke(!0);else{(0,k.gg)("\u274c Not logged in after initial auth state, redirecting to auth with returnUrl");const e=nt.pathname+nt.search;rt("/authpage?returnUrl=".concat(encodeURIComponent(e)),{replace:!0})}})(),()=>{e=!0}},[rt,nt.pathname,nt.search]),(0,n.useEffect)(()=>{const e=(0,A.hg)(i.j2,e=>{if(e)lt.current=!0,Ke(!0),(0,k.gg)("\u2705 Logged in as:",e.uid);else if(lt.current){(0,k.gg)("\u274c Session ended, redirecting to auth with returnUrl"),Ke(!1);const e=nt.pathname+nt.search;rt("/authpage?returnUrl=".concat(encodeURIComponent(e)),{replace:!0})}});return()=>e()},[rt,nt.pathname,nt.search]),(0,n.useEffect)(()=>{if(!I||!Ye)return;B(!0),me(null),ge(null);const e=(0,l.rJ)(i.db,"workspaces",I,"chatLogs"),t=(0,l.P)(e,(0,l.My)("lastUpdated","desc")),s=(0,l.aQ)(t,e=>{const t=e.docs.map(e=>(0,a.A)({id:e.id},e.data()));V(t),me(null),B(!1)},e=>{console.error("Error loading chat history:",e),V([]),be(null),ge(null),me(le(e)),B(!1)});return()=>s()},[I,Ye,W]),(0,n.useEffect)(()=>{B(!0),V([]),be(null),me(null),ge(null)},[I]),(0,n.useEffect)(()=>{be(e=>{if(null===e||void 0===e||!e.id)return e;const t=_.find(t=>t.id===e.id);return null!==t&&void 0!==t?t:e})},[_]);const gt=null!==(t=null===ve||void 0===ve||null===(s=ve.messages)||void 0===s?void 0:s.length)&&void 0!==t?t:0;(0,n.useLayoutEffect)(()=>{const e=it.current;e&&requestAnimationFrame(()=>{e.scrollTop=e.scrollHeight})},[null===ve||void 0===ve?void 0:ve.id,gt,null===ve||void 0===ve?void 0:ve.contactSubmitted]);const pt=(e,t)=>{if(!e)return e;let s=e;const a=null===t||void 0===t?void 0:t.viewerDocuments;Array.isArray(a)&&a.length>0&&(s=(0,K.M4)(s,a,{}));let r=s;return r=r.replace(/\[([^\]]+)\]\((https?:\/\/[^\s)]+|\/?\?doc=[^)\s]+|\/shared\/[^)\s]+)\)/g,'<a href="$2" target="_blank" rel="noopener noreferrer" class="text-blue-600 hover:underline">$1</a>'),r=r.replace(/(https?:\/\/[^\s<>"]+?)(?=[.,!?;:]?\s|[.,!?;:]?$|[)}\]])/g,'<a href="$1" target="_blank" rel="noopener noreferrer" class="text-blue-600 hover:underline">$1</a>'),r=r.replace(/\*\*(.*?)\*\*/g,'<strong class="font-bold">$1</strong>'),r=r.replace(/\*(.*?)\*/g,'<em class="italic">$1</em>'),r=r.replace(/\n/g,"<br>"),r},ft=(0,n.useCallback)(async e=>{try{const t=(0,l.doc)(i.db,"workspaces",I,"chatLogs",e);await(0,l.mZ)(t,{unread:!1,readAt:new Date}),(0,k.gg)("\u2705 Chat ".concat(e," marked as read"))}catch(t){console.error("Error marking chat as read:",t);try{const t=(0,l.doc)(i.db,"workspaces",I,"chatLogs",e);await(0,l.BN)(t,{unread:!1,readAt:new Date},{merge:!0}),(0,k.gg)("\u2705 Chat ".concat(e," marked as read (via setDoc)"))}catch(s){console.error("Error marking chat as read (setDoc fallback):",s)}}},[I]),vt=(0,n.useCallback)(e=>{be(e),ge(null),Ne(""),Re(null),!0===e.unread&&ft(e.id)},[ft]);(0,n.useEffect)(()=>{const e=Ze.get("selected");if(!e||O||G)return;const t=_.find(t=>
2t.id===e);if(t)return(0,k.gg)("\ud83d\udce7 Auto-selecting chat from email link:",e),ge(null),vt(t),void window.scrollTo({top:0,behavior:"smooth"});let s=!1;return(async()=>{try{const t=(0,l.doc)(i.db,"workspaces",I,"chatLogs",e),r=await(0,l.getDoc)(t);if(s)return;if(r.exists()){const e=(0,a.A)({id:r.id},r.data());ge(null),vt(e),window.scrollTo({top:0,behavior:"smooth"})}else console.warn("\u26a0\ufe0f Chat not found in logs:",e),be(null),ge(ie(e))}catch(t){if(s)return;console.error("Error loading selected chat:",t),be(null),ge("permission-denied"===(null===t||void 0===t?void 0:t.code)?le(t):ie(e))}})(),()=>{s=!0}},[Ze,_,O,G,I,vt]);const bt=async()=>{if("Switch account"===(null===G||void 0===G?void 0:G.actionLabel)){const e=nt.pathname+nt.search;return await(0,A.CI)(i.j2),void rt("/authpage?returnUrl=".concat(encodeURIComponent(e),"&prompt=login"),{replace:!0})}B(!0),me(null),$(e=>e+1)},yt=async e=>{var t;const s=null===ve||void 0===ve||null===(t=ve.missingAnswer)||void 0===t?void 0:t.documentId;if(I&&s){$e(e);try{const t="discard"===e?se:te;await t({workspaceId:I,documentId:s})}catch(a){console.error(a),Re(a.message||"Could not update the knowledge draft.")}finally{$e(null)}}},jt=(0,n.useRef)(new Set),wt=(0,n.useRef)(0);(0,n.useEffect)(()=>{if(!I||!Ye||O)return;const e=_.length,t=wt.current;if(0===e&&0===t)return;if(wt.current=e,jt.current.has(I))return;const s=_.filter(e=>!0===e.unread&&!0!==e.archived);if(s.length>0){(0,k.gg)("\ud83d\udce7 Marking ".concat(s.length," unread chat(s) as read for workspace ").concat(I)),jt.current.add(I);(async()=>{const e=s.map(e=>ft(e.id));await Promise.all(e),(0,k.gg)("\u2705 All unread chats marked as read")})()}else jt.current.add(I)},[I,Ye,O,_,ft]);const Nt=_.filter(e=>{return!0!==e.isInternalSetup&&(Oe?(null===(t=e.missingAnswer)||void 0===t?void 0:t.status)===ae:(!_e||!0===e.liveRequestPending)&&(Me?!0===e.archived:!0!==e.archived));var t});return O&&"chats"===st?(0,D.jsxs)("div",{className:"flex flex-col h-full min-h-0 bg-gray-50",children:[(0,D.jsx)(de,{activeTab:st,onTabChange:at,hasUnreadChats:ot,hasUnreadViews:ut,hasUnreadForms:ct}),(0,D.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,D.jsx)("div",{className:"text-gray-500",children:"Loading chat history..."})})]}):G&&"chats"===st?(0,D.jsxs)("div",{className:"flex flex-col h-full min-h-0 bg-gray-50",children:[(0,D.jsx)(de,{activeTab:st,onTabChange:at,hasUnreadChats:ot,hasUnreadViews:ut,hasUnreadForms:ct}),(0,D.jsx)(oe,{title:G.title,message:G.message,actionLabel:G.actionLabel,onAction:bt})]}):"formResponses"===st?(0,D.jsxs)("div",{className:"flex flex-col h-full min-h-0 bg-gray-50",children:[(0,D.jsx)(de,{activeTab:st,onTabChange:at,hasUnreadChats:ot,hasUnreadViews:ut,hasUnreadForms:ct}),(0,D.jsx)("div",{className:"flex-1 min-h-0",children:(0,D.jsx)(R,{workspaceId:I})})]}):"views"===st?(0,D.jsxs)("div",{className:"flex flex-col h-full min-h-0 bg-gray-50",children:[(0,D.jsx)(de,{activeTab:st,onTabChange:at,hasUnreadChats:ot,hasUnreadViews:ut,hasUnreadForms:ct}),(0,D.jsx)("div",{className:"flex-1 min-h-0",children:(0,D.jsx)(X,{workspaceId:I})})]}):(0,D.jsxs)("div",{className:"flex flex-col h-full min-h-0 bg-gray-50",children:[(0,D.jsx)(de,{activeTab:st,onTabChange:at,hasUnreadChats:ot,hasUnreadViews:ut,hasUnreadForms:ct}),(0,D.jsxs)("div",{className:"flex flex-1 min-h-0",children:[(0,D.jsxs)("div",{className:"w-[25%] bg-white border-r border-gray-200 overflow-y-auto",children:[(0,D.jsxs)("div",{className:"p-4 border-b border-gray-200 bg-gray-50",children:[(0,D.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,D.jsx)("h2",{className:"text-lg font-semibold text-gray-900",children:"Chat 
2Conversations"}),(0,D.jsx)("button",{onClick:()=>Fe(!Me),className:"text-xs px-2 py-1 rounded bg-gray-200 hover:bg-gray-300 transition-colors",title:Me?"Show active chats":"Show archived chats",children:Me?"Active":"Archived"})]}),(0,D.jsxs)("label",{className:"flex items-center gap-2 text-xs text-gray-600 mb-2 cursor-pointer",children:[(0,D.jsx)("input",{type:"checkbox",checked:_e,onChange:e=>Ve(e.target.checked),className:"rounded border-gray-300"}),"Live requests only"]}),(0,D.jsxs)("label",{className:"flex items-center gap-2 text-xs text-gray-600 mb-2 cursor-pointer",children:[(0,D.jsx)("input",{type:"checkbox",checked:Oe,onChange:e=>Be(e.target.checked),className:"rounded border-gray-300"}),"Needs answers only",dt>0&&(0,D.jsx)("span",{className:"ml-auto inline-flex items-center justify-center min-w-5 h-5 rounded-full bg-amber-100 text-amber-800 text-[11px] font-semibold px-1.5",children:dt})]}),(0,D.jsxs)("p",{className:"text-sm text-gray-500",children:[Nt.length," ",Oe?"needs-answer":Me?"archived":"active"," conversations"]})]}),(0,D.jsxs)("div",{className:"divide-y divide-gray-200",children:[Nt.map(e=>{var t,s,a,r,n;const o=null===(t=e.messages)||void 0===t?void 0:t.find(e=>"user"===e.role),x=null===(s=e.lastUpdated)||void 0===s||null===(a=s.toDate)||void 0===a?void 0:a.call(s);return(0,D.jsxs)("div",{className:"group relative ".concat((null===ve||void 0===ve?void 0:ve.id)===e.id?"bg-blue-50 border-l-4 border-blue-500":""),children:[(0,D.jsx)("button",{onClick:()=>vt(e),className:"w-full text-left p-4 hover:bg-gray-50 transition-colors",children:(0,D.jsxs)("div",{className:"flex items-start gap-2",children:[(0,D.jsx)(c.A,{className:"w-4 h-4 text-gray-400 mt-1 flex-shrink-0"}),(0,D.jsxs)("div",{className:"flex-1 min-w-0 pr-8",children:[" ",(0,D.jsxs)("p",{className:"text-sm font-medium text-gray-900 line-clamp-2",children:[" ",(null===o||void 0===o?void 0:o.content)||"New Chat"]}),(0,D.jsxs)("div",{className:"flex items-center gap-2 mt-1",children:[(0,D.jsx)(d.A,{className:"w-3 h-3 text-gray-400"}),(0,D.jsx)("p",{className:"text-xs text-gray-500",children:(null===x||void 0===x?void 0:x.toLocaleString())||"Unknown"})]}),(0,D.jsxs)("p",{className:"text-xs text-gray-400 mt-1",children:[e.messageCount||(null===(r=e.messages)||void 0===r?void 0:r.length)||0," messages"]}),e.liveRequestPending&&(0,D.jsx)("span",{className:"inline-flex items-center gap-1 mt-1 text-xs font-medium text-amber-800 bg-amber-50 border border-amber-200 px-1.5 py-0.5 rounded",children:"Live request"}),e.contactSubmitted&&(0,D.jsxs)("span",{className:"inline-flex items-center gap-1 mt-1 text-xs font-medium text-green-700 bg-green-50 border border-green-200 px-1.5 py-0.5 rounded",children:[(0,D.jsx)(m.A,{className:"w-3 h-3"}),"Contact submitted"]}),(null===(n=e.missingAnswer)||void 0===n?void 0:n.status)===ae&&(0,D.jsxs)("span",{className:"inline-flex items-center gap-1 mt-1 ml-1 text-xs font-medium text-amber-800 bg-amber-50 border border-amber-200 px-1.5 py-0.5 rounded",children:[(0,D.jsx)(u,{className:"w-3 h-3"}),"Needs answer"]})]})]})}),(0,D.jsx)("button",{onClick:t=>{t.stopPropagation(),(async(e,t)=>{try{const s=(0,l.doc)(i.db,"workspaces",I,"chatLogs",e);await(0,l.mZ)(s,{archived:!t,archivedAt:t?null:new Date}),(null===ve||void 0===ve?void 0:ve.id)!==e||t||be(null)}catch(s){console.error("Error toggling archive:",s)}})(e.id,e.archived)},className:"absolute top-4 right-4 p-1.5 rounded opacity-0 group-hover:opacity-100 hover:bg-gray-200 transition-all",title:e.archived?"Unarchive":"Archive",children:e.archived?(0,D.jsx)(h.A,{className:"w-4 h-4 text-gray-600"}):(0,D.jsx)(g.A,{className:"w-4 h-4 text-gray-600"})})]},e.id)}),0===Nt.length&&(0,D.jsxs)("div",{className:"p-8 text-center text-gray-500",children:[(0,D.jsx)(g.A,{className:"w-12 h-12 mx-auto mb-2 text-gray-300"}),(0,D.jsxs)("p",{className:"text-sm",children:["No ",Me?"archived":"active"," conversations"]})]})]})]}),(0,D.jsx)("div",{className:"flex-1 flex flex-col min-h-0 min-w-0",children:ve?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)("div",{className:"p-4 bg-white border-b border-gray-200",children:[(0,D.jsx)("h3",{className:"text-lg font-semibold text-gray-900",children:"Chat Details"}),(0,D.jsxs)("p",{className:"text-sm text-gray-500 mt-1",children:["Chat ID: ",ve.id]}),(0,D.jsxs)("p",{className:"text-xs text-gray-400 mt-1",children:["Last updated: ",null===(o=ve.lastUpdated)||void 0===o||null===(x=o.toDate)||void 0===x||null===(y=x.call(o))||void 0===y?void 0:y.toLocaleStr
2ing()]})]}),(0,D.jsxs)("div",{className:"flex-1 flex flex-col min-h-0",children:[(0,D.jsxs)("div",{ref:it,className:"flex-1 overflow-y-auto p-6 space-y-4",children:[null===(j=ve.messages)||void 0===j?void 0:j.map((e,t)=>{var s,a,r;const n="assistant"===e.role&&"human"===e.source;return(0,D.jsx)("div",{className:"flex ".concat("user"===e.role?"justify-end":"justify-start"),children:(0,D.jsxs)("div",{className:"max-w-2xl rounded-lg p-4 ".concat("user"===e.role?"bg-blue-500 text-white":n?"bg-emerald-50 border border-emerald-200 text-emerald-950 shadow-sm":"bg-white border border-gray-200 text-gray-900 shadow-sm"),children:[(0,D.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[n&&(e.photoURL||e.photoUrl||e.avatarUrl)&&(0,D.jsx)("img",{src:e.photoURL||e.photoUrl||e.avatarUrl,alt:"",className:"w-7 h-7 rounded-full object-cover border border-emerald-200 shrink-0"}),(0,D.jsx)("span",{className:"text-xs font-semibold",children:"user"===e.role?"User":n?e.senderName||"Team member":"Assistant"}),(0,D.jsx)("span",{className:"text-xs ".concat("user"===e.role?"text-blue-100":"text-gray-500"),children:(null===(s=e.timestamp)||void 0===s||null===(a=s.toDate)||void 0===a||null===(r=a.call(s))||void 0===r?void 0:r.toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}))||"Unknown time"})]}),"assistant"!==e.role||n?(0,D.jsx)("div",{className:"text-sm whitespace-pre-wrap",children:e.content}):(0,D.jsx)("div",{className:"text-sm whitespace-pre-wrap",dangerouslySetInnerHTML:{__html:pt(e.content,e.ragContext)}}),"assistant"===e.role&&e.ragContext&&!n&&(()=>{const t=Array.isArray(e.ragContext.pdfSources)?e.ragContext.pdfSources:[],s=Array.isArray(e.ragContext.viewerDocuments)?e.ragContext.viewerDocuments:[],a=new Set([...t,...s].map(e=>String((null===e||void 0===e?void 0:e.title)||"").trim().toLowerCase()).filter(Boolean)),r=(e.ragContext.documentsReferenced||[]).filter(e=>e&&!a.has(String(e).trim().toLowerCase())),n=t.length>0,l=r.length>0;return n||l?(0,D.jsxs)("div",{className:"mt-3 pt-3 border-t ".concat("user"===e.role?"border-blue-400":"border-gray-200"),children:[n&&(0,D.jsx)(Y.E,{pdfSources:t,className:"!mt-0"}),l&&(0,D.jsxs)("div",{className:n?"mt-2":"",children:[(0,D.jsx)("p",{className:"text-xs text-gray-500",children:n?"Other documents referenced:":"Documents:"}),(0,D.jsx)("div",{className:"flex flex-wrap gap-1 mt-1",children:r.map((e,t)=>(0,D.jsx)("span",{className:"text-xs bg-gray-100 text-gray-700 px-2 py-0.5 rounded",children:e},t))})]})]}):null})()]})},t)}),ve.contactSubmitted&&ve.contactInfo&&(0,D.jsx)("div",{className:"mx-6 mb-6 bg-white border border-green-200 rounded-lg overflow-hidden shadow-sm",children:(0,D.jsxs)("div",{className:"border-l-4 border-green-500 p-4",children:[(0,D.jsx)("h4",{className:"text-sm font-semibold text-gray-900 mb-3",children:"Contact Information Submitted"}),(0,D.jsxs)("div",{className:"space-y-2",children:[ve.contactInfo.name&&(0,D.jsxs)("div",{className:"flex items-center gap-2 text-sm text-gray-700",children:[(0,D.jsx)(m.A,{className:"w-4 h-4 text-gray-400"}),(0,D.jsx)("span",{children:ve.contactInfo.name})]}),ve.contactInfo.email&&(0,D.jsxs)("div",{className:"flex items-center gap-2 text-sm",children:[(0,D.jsx)(p.A,{className:"w-4 h-4 text-gray-400"}),(0,D.jsx)("a",{href:"mailto:".concat(ve.contactInfo.email),className:"text-blue-600 hover:underline",children:ve.contactInfo.email})]}),ve.contactInfo.phone&&(0,D.jsxs)("div",{className:"flex items-center gap-2 text-sm",children:[(0,D.jsx)(f.A,{className:"w-4 h-4 text-gray-400"}),(0,D.jsx)("a",{href:"tel:".concat(ve.contactInfo.phone),className:"text-blue-600 hover:underline",children:ve.contactInfo.phone})]})]}),ve.contactInfo.submittedAt&&(0,D.jsxs)("p",{className:"text-xs text-gray-400 mt-3",children:["Submitted ",(null===(w=(S=ve.contactInfo.submittedAt).toDate)||void 0===w||null===(C=w.call(S))||void 0===C?void 0:C.toLocaleString())||"",ve.contactInfo.leadCaptureReason&&"no_answer"!==ve.contactInfo.leadCaptureReason&&(0,D.jsx)("span",{className:"ml-2 inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-blue-100 text-blue-700",children:"high_intent"===ve.contactInfo.leadCaptureReason?"High intent":"repeated_intent"===ve.contactInfo.leadCaptureReason?"Repeated intent":ve.contactInfo.leadCaptureReason})]})]})}),ve.missingAnswer&&(0,D.jsx)("div",{className:"mx-6 mb-6 bg-white border border-amber-200 rounded-lg overflow-hidden shadow-sm",children:(0,D.jsxs)("div",{className:"border-l-4 border-amber-500 p-4",children:[(0,D.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,D.jsxs)("div",{children:[(0,D.jsx)("h4",{className:"text-sm font-semibold text-gray-900 mb-1",children:"Knowledge draft from email reply"}),(0,D.jsx)("p",{className:"text-xs text-gray-600",children:"Publishes an internal knowledge document for the chatbot. It does not message the visitor."})]}),(0,D.jsx)(ce,{status:ve.missingAnswer.status})]}),ve.missingAnswer.questionPreview&&(0,D.jsxs)("div",{className:"mt-3 rounded-md bg-amber-50 border border-amber-100 p-3",children:[(0,D.jsx)("p",{className:"text-xs font-medium text-amber-900 mb
2-1",children:"Original unanswered question"}),(0,D.jsx)("p",{className:"text-sm text-amber-950",children:ve.missingAnswer.questionPreview})]}),ve.missingAnswer.status===ae&&ve.missingAnswer.documentId&&(0,D.jsxs)("div",{className:"mt-4 flex flex-wrap gap-2",children:[(0,D.jsxs)("button",{type:"button",onClick:()=>yt("publish"),disabled:null!==We,className:"inline-flex items-center gap-1.5 px-3 py-2 rounded-lg bg-blue-600 text-white text-sm font-medium hover:bg-blue-700 disabled:opacity-50",children:[(0,D.jsx)(v.A,{className:"w-4 h-4"}),"publish"===We?"Publishing...":"Publish knowledge"]}),(0,D.jsxs)("button",{type:"button",onClick:()=>yt("discard"),disabled:null!==We,className:"inline-flex items-center gap-1.5 px-3 py-2 rounded-lg border border-gray-300 text-gray-700 text-sm font-medium hover:bg-gray-50 disabled:opacity-50",children:[(0,D.jsx)(b.A,{className:"w-4 h-4"}),"discard"===We?"Discarding...":"Discard"]})]}),ve.missingAnswer.status===ne&&(0,D.jsx)("p",{className:"mt-3 text-xs text-green-700",children:"Published - indexing started. The document will become searchable after indexing finishes."}),ve.missingAnswer.status===re&&(0,D.jsx)("p",{className:"mt-3 text-xs text-gray-500",children:"Discarded. This reply is no longer actionable."})]})})]}),(0,D.jsxs)("div",{className:"border-t border-gray-200 bg-white p-4 shrink-0",children:[(0,D.jsx)("p",{className:"text-xs font-medium text-gray-700 mb-2",children:"Reply as team"}),De&&(0,D.jsx)("p",{className:"text-xs text-red-600 mb-2",children:De}),(0,D.jsxs)("div",{className:"flex gap-2",children:[(0,D.jsx)("textarea",{value:we,onChange:e=>Ne(e.target.value),placeholder:"Type a message to the visitor\u2026",rows:2,className:"flex-1 min-w-0 px-3 py-2 border border-gray-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-blue-500",disabled:Se}),(0,D.jsx)("button",{type:"button",onClick:async()=>{const e=we.trim();if(e&&null!==ve&&void 0!==ve&&ve.id&&I){Ce(!0),Re(null);try{await ee({workspaceId:I,chatId:ve.id,message:e}),Ne("")}catch(t){console.error(t),Re(t.message||"Failed to send reply")}finally{Ce(!1)}}},disabled:Se||!we.trim(),className:"self-end px-4 py-2 bg-blue-600 text-white text-sm font-medium rounded-lg hover:bg-blue-700 disabled:opacity-50 shrink-0",children:Se?"Sending\u2026":"Send"})]})]})]})]}):he?(0,D.jsx)(oe,{title:he.title,message:he.message,actionLabel:"Back to chat list",onAction:()=>ge(null)}):(0,D.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center text-gray-500",children:[(0,D.jsx)(c.A,{className:"w-16 h-16 mb-4 text-gray-300"}),(0,D.jsx)("p",{className:"text-lg font-medium",children:"Select a chat to view details"}),(0,D.jsx)("p",{className:"text-sm mt-1",children:"Choose from the list on the left"})]})})]})]})}},10655(e,t,s){s.d(t,{A:()=>d});var a=s(5544),r=s(65043),n=s(7104),l=s(1862),i=s(40643),o=s(61702),c=s(70579);function d(e){let t=e.documentId,s=e.value,d=e.fieldType;const m=(0,r.useState)(null),x=(0,a.A)(m,2),u=x[0],h=x[1],g=(0,r.useState)(!0),p=(0,a.A)(g,2),f=p[0],v=p[1],b=(0,r.useState)(!1),y=(0,a.A)(b,2),j=y[0],w=y[1];if((0,r.useEffect)(()=>{if(!(0,i.nM)(s)||!t)return void v(!1);let e=!1;return(async()=>{try{const a=await(0,o.Xd)(t,s.storagePath);e||h(a)}catch(a){(0,l.gg)("FormResponseFileValue:",a),e||w(!0)}finally{e||v(!1)}})(),()=>{e=!0}},[t,s]),!(0,i.nM)(s))return null;const N=s.fileName||"Uploaded file";return f?(0,c.jsx)("span",{className:"text-sm text-gray-500",children:"Loading file\u2026"}):j||!u?(0,c.jsx)("span",{className:"text-sm text-gray-900",children:N}):"image"===d?(0,c.jsxs)("div",{className:"space-y-2",children:[(0,c.jsx)("img",{src:u,alt:N,className:"max-w-xs max-h-48 rounded-md border border-gray-200 object-cover"}),(0,c.jsx)("a",{href:u,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-indigo-600 hover:underline",children:N})]}):(0,c.jsxs)("a",{href:u,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-indigo-600 hover:underline inline-flex items-center gap-1",children:[(0,c.jsx)(n.A,{className:"w-4 h-4"}),N]})}},61702(e,t,s){s.d(t,{Xd:()=>i,tL:()=>l});var a=s(52395),r=s(96822),n=s(40643);async function l(e){let t=e.fieldType,s=e.file,l=e.documentId,i=e.formId,o=e.fieldId,c=e.uploadSessionId;const d=(0,n.Rq)(t,s);if(!d.ok)throw new Error(d.message);const m="pdf"!==t||s.type?s.type||"application/octet-stream":"application/pdf",x=await async function(e){const t=(0,a.httpsCallable)(r.Cn,"createFormResponseUploadUrl"),s=await t(e),n=null===s||void 0===s?void 0:s.data;if(null===n||void 0===n||!n.success||!n.signedWriteUrl||!n.storagePath)throw new Error((null===n||void 0===n?void 0:n.message)||"Could not start file upload");return{uploadId:n.uploadId,storagePath:n.storagePath,signedWriteUrl:n.signedWriteUrl,expiresAt:n.expiresAt}}({documentId:l,formId:i,fieldId:o,uploadSessionId:c,fileName:s.name,contentType:m,fileSize:s.size}),u=x.uploadId,h=x.storagePath,g=x.signedWriteUrl;return await async function(e,t,s){const a=await fetch(t,{method:"PUT",headers:{"Content-Type":s||e.type||"application/octet-stream"},body:e});if(!a.ok)throw new Error("Upload failed (".concat(a.status,")"))}(s,g,m),{uploadId:u,storagePath:h,fileName:s.name,contentType:m,size:s.size}}async function i(e,t){const s=(0,a.httpsCallable)(r.Cn,"getFormResponseFileDownloadUrl"),n=await s({documentId:e,storagePath:t}),l=null===n||void 0===n?void 0:n.data;if(null===l||void 0===l||!l.success||!l.signedReadUrl)throw new Error("Could not load file");return l.signedReadUrl}}
2,40643(e,t,s){s.d(t,{LO:()=>l,Mu:()=>i,Rq:()=>r,nM:()=>n});new Set(["image","pdf"]);const a=new Set(["image/jpeg","image/png","image/webp","image/gif"]);function r(e,t){if(!t||"number"!==typeof t.size)return{ok:!1,message:"No file selected"};const s=String(t.type||"").trim().toLowerCase();return"image"===e?a.has(s)?t.size>26214400?{ok:!1,message:"Image must be 25 MB or smaller"}:{ok:!0}:{ok:!1,message:"Please choose a JPEG, PNG, WebP, or GIF image"}:"pdf"===e?"application/pdf"===s||/\.pdf$/i.test(t.name||"")?t.size>54525952?{ok:!1,message:"PDF must be 52 MB or smaller"}:{ok:!0}:{ok:!1,message:"Please choose a PDF file"}:{ok:!1,message:"Unsupported file field type"}}function n(e){return!(!e||"object"!==typeof e||Array.isArray(e))&&("string"===typeof e.storagePath&&e.storagePath.trim().length>0)}function l(e){return"image"===e?"image/jpeg,image/png,image/webp,image/gif":"pdf"===e?"application/pdf,.pdf":""}function i(){return"undefined"!==typeof crypto&&"function"===typeof crypto.randomUUID?crypto.randomUUID():"upload-".concat(Date.now().toString(36),"-").concat(Math.random().toString(36).slice(2,10))}},76245(e,t,s){s.d(t,{A:()=>a});const a=(0,s(77784).A)("circle-x",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]])},84669(e,t,s){s.d(t,{A:()=>a});const a=(0,s(77784).A)("message-square",[["path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",key:"1lielz"}]])},91286(e,t,s){s.d(t,{A:()=>a});const a=(0,s(77784).A)("phone",[["path",{d:"M13.832 16.568a1 1 0 0 0 1.213-.303l.355-.465A2 2 0 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 6.392 6.384",key:"9njp5v"}]])}}]);
3//# sourceMappingURL=150.e5f00124.chunk.js.map

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.