PageSourceSearch

https://www.trybased.com/static/js/4373.f57f0bb9.chunk.js

js trybased.com collected 2026-10-02 01:47:17 UTC 164,393 bytes, 3 lines download raw bytes

1/*! For license information please see 4373.f57f0bb9.chunk.js.LICENSE.txt */
2"use strict";(self.webpackChunkknowledge_base_saas=self.webpackChunkknowledge_base_saas||[]).push([[4373],{65899(e,t,n){n.d(t,{A:()=>i});var r=n(5544),o=n(65043),a=n(63370),s=n(70579);function i(e){let t=e.onSubmit,n=e.submitting,i=void 0!==n&&n,u=e.title;const l=(0,o.useState)(""),c=(0,r.A)(l,2),d=c[0],m=c[1],g=(0,o.useState)(""),h=(0,r.A)(g,2),p=h[0],f=h[1],x=(0,o.useState)(""),D=(0,r.A)(x,2),y=D[0],v=D[1],b=(0,o.useState)(""),F=(0,r.A)(b,2),w=F[0],A=F[1];return(0,s.jsxs)("div",{className:"w-full max-w-md mx-auto px-4 py-10",children:[(0,s.jsx)("h2",{className:"font-display text-headline-lg text-on-surface mb-2",children:u||"Enter your details to continue"}),(0,s.jsx)("p",{className:"text-sm text-on-surface/70 mb-6",children:"Provide your first name, last name, and email to view this shared content."}),(0,s.jsxs)("form",{onSubmit:async e=>{e.preventDefault(),A("");const n=(0,a.Se)({firstName:d,lastName:p,email:y});if(n.ok)try{await t(n)}catch(r){A((null===r||void 0===r?void 0:r.message)||"Could not submit. Please try again.")}else A(n.error)},className:"space-y-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{htmlFor:"share-contact-first",className:"block text-sm font-medium text-on-surface mb-1",children:"First name"}),(0,s.jsx)("input",{id:"share-contact-first",type:"text",autoComplete:"given-name",value:d,onChange:e=>m(e.target.value),className:"w-full rounded-brand-md border border-hairline bg-white px-3 py-2.5 text-base text-on-surface",disabled:i,required:!0})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{htmlFor:"share-contact-last",className:"block text-sm font-medium text-on-surface mb-1",children:"Last name"}),(0,s.jsx)("input",{id:"share-contact-last",type:"text",autoComplete:"family-name",value:p,onChange:e=>f(e.target.value),className:"w-full rounded-brand-md border border-hairline bg-white px-3 py-2.5 text-base text-on-surface",disabled:i,required:!0})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{htmlFor:"share-contact-email",className:"block text-sm font-medium text-on-surface mb-1",children:"Email"}),(0,s.jsx)("input",{id:"share-contact-email",type:"email",autoComplete:"email",value:y,onChange:e=>v(e.target.value),className:"w-full rounded-brand-md border border-hairline bg-white px-3 py-2.5 text-base text-on-surface",disabled:i,required:!0})]}),w?(0,s.jsx)("p",{className:"text-sm text-red-600",role:"alert",children:w}):null,(0,s.jsx)("button",{type:"submit",disabled:i,className:"w-full rounded-brand-md bg-brand px-4 py-2.5 text-base font-medium text-white hover:bg-brand-hover disabled:opacity-60",children:i?"Submitting\u2026":"Continue"})]})]})}},54373(e,t,n){n.r(t),n.d(t,{default:()=>ft});var r=n(5544),o=n(65043),a=n(47874),s=n(67898),i=n(52395),u=n(89379),l=n(23658),c=n(38326),d=n(40614),m=n(65469),g=n(5379),h=n(1523),p=n(28969),f=n(22633),x=n(42983),D=n(92382),y=n(70067),v=n(41680),b=n(84669),F=n(87183),w=n(42574),A=n(1862),C=n(97885);function E(e){if(e.nodeType===Node.TEXT_NODE)return E(e.parentNode)+"/text()["+Array.from(e.parentNode.childNodes).indexOf(e)+"]";if(e.nodeType===Node.ELEMENT_NODE){const t=[];let n=e;for(;n&&n.nodeType===Node.ELEMENT_NODE;){let e=1,r=n.previousSibling;for(;r;)r.nodeType===Node.ELEMENT_NODE&&r.nodeName===n.nodeName&&e++,r=r.previousSibling;t.unshift(n.nodeName.toLowerCase()+"["+e+"]"),n=n.parentNode}return"/"+t.join("/")}return""}function k(e,t){if(!e||!t)return!1;return 0!==e.toString().trim().length&&t.contains(e.commonAncestorContainer)}function j(e,t,n){if(!e||!t)return[];const r=t.querySelector('mark[data-comment-id="'.concat(n,'"]'));if(r)return[r];try{const r=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,{acceptNode:function(e){let n=e.parentNode;for(;n&&n!==t;){if("MARK"===n.tagName&&n.classList.contains("comment-highlight"))return NodeFilter.FILTER_REJECT;n=n.parentNode}return NodeFilter.FILTER_ACCEPT}},!1);let o,a=0;const s=[];for(;o=r.nextNode();){const r=o.textContent.length,i=a;if(a+r>e.startOffset&&i<e.endOffset){const u=Math.max(0,e.startOffset-i),l=Math.min(r,e.endOffset-i);if(l>u){let e=o.parentNode,i=!1;for(;e&&e!==t;){if("MARK"===e.tagName&&e.classList.contains("comment-highlight")){i=!0;break}e=e.parentNode}if(i){a+=r;continue}const c=o.textContent.substring(0,u),d=o.textContent.substring(u,l),m=o.textContent.substring(l),g=document.createElement("mark");
2g.className="comment-highlight",g.setAttribute("data-comment-id",n),g.style.backgroundColor="#fef08a",g.style.cursor="pointer",g.textContent=d;const h=document.createDocumentFragment();c&&h.appendChild(document.createTextNode(c)),h.appendChild(g),m&&h.appendChild(document.createTextNode(m)),o.parentNode.replaceChild(h,o),s.push(g)}}a+=r}return s}catch(o){return console.error("Error highlighting text range:",o),[]}}function N(e,t){if(!t)return;t.querySelectorAll('mark[data-comment-id="'.concat(e,'"]')).forEach(e=>{const t=e.parentNode,n=e.textContent,r=document.createTextNode(n);t.replaceChild(r,e),t.normalize()})}function S(e,t){if(!t)return;let n=t.querySelector('mark[data-comment-id="'.concat(e,'"]'));if(!n){const r=t.querySelectorAll("mark.comment-highlight");for(const t of r)if(t.getAttribute("data-comment-id")===e){n=t;break}}n?(n.scrollIntoView({behavior:"smooth",block:"center"}),n.style.transition="background-color 0.3s, box-shadow 0.3s",n.style.backgroundColor="#fbbf24",n.style.boxShadow="0 0 0 3px rgba(251, 191, 36, 0.3)",setTimeout(()=>{n.style.backgroundColor="#fef08a",n.style.boxShadow="none"},1e3)):console.warn("Highlight not found for comment ".concat(e))}const B="modal",I=[".comment-button",".comment-panel","[data-comment-thread-id]","[data-comment-modal]"];function T(e){let t=e.pointerDown,n=e.didDrag,r=e.eventType,o=e.clickCount,a=void 0===o?1:o;return t||"selectionchange"===r?null:"dblclick"===r?0:"click"===r?a>=2?0:null:"pointerup"===r||"mouseup"===r?n||a>=2?0:350:null}function L(e){return!(!e||"function"!==typeof e.closest)&&I.some(t=>e.closest(t))}function R(e){return!(!e||"function"!==typeof e.closest)&&Boolean(e.closest("[data-document-content]"))}var P=n(77784);const O=(0,P.A)("circle",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]]);var z=n(82054),M=n(55472),U=n(14459),q=n(75088),V=n(36210);const _=(0,P.A)("reply",[["polyline",{points:"9 17 4 12 9 7",key:"hvgpf2"}],["path",{d:"M20 18v-2a4 4 0 0 0-4-4H4",key:"5vmcpk"}]]);var H=n(70579);const W=e=>{if(!e)return"just now";const t=new Date,n=e instanceof Date?e:e.toDate(),r=Math.floor((t-n)/1e3);if(r<60)return"just now";const o=Math.floor(r/60);if(o<60)return"".concat(o," minute").concat(1!==o?"s":""," ago");const a=Math.floor(o/60);if(a<24)return"".concat(a," hour").concat(1!==a?"s":""," ago");const s=Math.floor(a/24);if(s<30)return"".concat(s," day").concat(1!==s?"s":""," ago");const i=Math.floor(s/30);if(i<12)return"".concat(i," month").concat(1!==i?"s":""," ago");const u=Math.floor(i/12);return"".concat(u," year").concat(1!==u?"s":""," ago")},K=e=>{let t=e.comment,n=e.onResolve,a=e.onReply,s=e.currentUserId;const i=(0,o.useState)(!1),u=(0,r.A)(i,2),l=u[0],c=u[1],d=(0,o.useState)(""),m=(0,r.A)(d,2),g=m[0],h=m[1],p=(0,o.useState)(!1),f=(0,r.A)(p,2),x=f[0],D=f[1],y=!0===t.resolved,v=s&&t.authorId===s;return(0,H.jsxs)("div",{className:"border rounded-lg p-4 mb-4 ".concat(y?"bg-gray-50 opacity-75":"bg-white"),children:[(0,H.jsxs)("div",{className:"flex items-start justify-between mb-2",children:[(0,H.jsxs)("div",{className:"flex items-center gap-2",children:[(0,H.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-100 flex items-center justify-center",children:(0,H.jsx)(U.A,{className:"w-4 h-4 text-blue-600"})}),(0,H.jsxs)("div",{children:[(0,H.jsx)("div",{className:"font-medium text-gray-900",children:t.authorName||"Anonymous"}),(0,H.jsxs)("div",{className:"text-xs text-gray-500 flex items-center gap-1",children:[(0,H.jsx)(q.A,{className:"w-3 h-3"}),t.createdAt&&W(t.createdAt)]})]})]}),v&&!y&&(0,H.jsxs)("button",{onClick:()=>n(t.id),className:"text-sm text-gray-600 hover:text-gray-900 flex items-center gap-1",title:"Resolve comment",children:[(0,H.jsx)(V.A,{className:"w-4 h-4"}),"Resolve"]}),y&&(0,H.jsxs)("span",{className:"text-xs text-green-600 flex items-center gap-1",children:[(0,H.jsx)(V.A,{className:"w-4 h-4"}),"Resolved"]})]}),t.selectedText&&(0,H.jsxs)("div",{className:"mb-3 p-2 bg-yellow-50 border-l-4 border-yellow-400 rounded",children:[(0,H.jsx)("div",{className:"text-xs text-gray-600 mb-1",children:"Selected text:"}),(0,H.jsxs)("div",{className:"text-sm text-gray-800 italic",children:['"',t.selectedText.length>150?t.selectedText.substring(0,150)+"...":t.selectedText,'"']})]}),(0,H.jsx)("div",{className:"text-gray-700 mb-3 whitespace-pre-wrap",children:t.comment}),t.mentionedUsers&&t.mentionedUsers.length>0&&(0,H.jsxs)("div",{className:"mb-3 flex items-center gap-2 flex-wrap",children:[(0,H.jsx)("span",{className:"text-xs text-gray-500",children:"Mentioned:"}),t.mentionedUsers.map((e,t)=>(0,H.jsx)("span",{className:"text-xs bg-blue-100 text-blue-700 px-2 py-1 rounded",children:e.displayName||e.email},t))]}),t.replies&&t.replies.length>0&&(0,H.jsx)("div",{className:"ml-6 mt-3 space-y-2 border-l-2 border-gray-200 pl-4",children:t.replies.map((e,t)=>(0,H.jsxs)("div",{className:"text-sm",children:[(0,H.jsx)("div",{className:"font-medium text-gray-900",children:e.authorName||"Anonymous"}),(0,H.jsx)("div",{className:"text-gray-700",children:e.content}),(0,H.jsx)("div",{className:"text-xs text-gray-500 mt-1",children:e.createdAt&&W(e.createdAt)})]},t))}),!y&&(0,H.jsx)("div",{className:"mt-3",children:l?(0,H.jsxs)("div",{className:"space-y-2",children:[(0,H.jsx)("textarea",{value:g,onChange:e=>h(e.target.value),placeholder:"Write a reply...",className:"w-full px-3 py-2 border border-gray-300 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500",rows:3}),(0,H.jsxs)("div",{className:"flex gap-2",children:[(0,H.jsx)("button",{onClick:async()=>
2{if(g.trim()){D(!0);try{await a(t.id,g),h(""),c(!1)}catch(e){console.error("Error submitting reply:",e)}finally{D(!1)}}},disabled:!g.trim()||x,className:"px-3 py-1 bg-blue-600 text-white text-sm rounded-md hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed",children:x?"Posting...":"Post Reply"}),(0,H.jsx)("button",{onClick:()=>{c(!1),h("")},className:"px-3 py-1 bg-gray-200 text-gray-700 text-sm rounded-md hover:bg-gray-300",children:"Cancel"})]})]}):(0,H.jsxs)("button",{onClick:()=>c(!0),className:"text-sm text-blue-600 hover:text-blue-700 flex items-center gap-1",children:[(0,H.jsx)(_,{className:"w-3 h-3"}),"Reply"]})})]})},J=e=>{let t=e.isOpen,n=e.onClose,a=e.documentId,i=e.linkId,l=(e.workspaceId,e.currentUserId),c=e.highlightCommentId,m=void 0===c?null:c;const g=(0,o.useState)([]),h=(0,r.A)(g,2),p=h[0],f=h[1],x=(0,o.useState)(!0),D=(0,r.A)(x,2),y=D[0],v=D[1],F=(0,o.useState)("all"),w=(0,r.A)(F,2),C=w[0],E=w[1],k=(0,o.useRef)(null);(0,o.useEffect)(()=>{if(!t||!a||!i)return f([]),void v(!1);v(!0);const e=(0,M.aU)(),n=i.split("/")[0].split("?")[0].split("#")[0].trim();(0,A.gg)("Querying comments for documentId:",a,"linkId:",n);const r=(0,M.P)((0,M.rJ)(e,"documentComments"),(0,M._M)("documentId","==",a),(0,M._M)("linkId","==",n),(0,M.My)("createdAt","desc")),o=(0,M.aQ)(r,e=>{const t=e.docs.map(e=>(0,u.A)({id:e.id},e.data()));(0,A.gg)("Fetched comments:",t.length),f(t),v(!1),t.length>0&&setTimeout(()=>{if(t.forEach(e=>{if(e.textRange&&e.documentId){const t=document.querySelector('[data-document-content][data-document-id="'.concat(e.documentId,'"]'));if(t){t.querySelector('mark[data-comment-id="'.concat(e.id,'"]'))||k.current===e.id||j(e.textRange,t,e.id)}}}),m){const e=t.find(e=>e.id===m);e&&setTimeout(()=>{const t=document.querySelector('[data-comment-thread-id="'.concat(m,'"]'));if(t&&(t.scrollIntoView({behavior:"smooth",block:"center"}),e.textRange&&e.documentId)){const t=document.querySelector('[data-document-content][data-document-id="'.concat(e.documentId,'"]'));t&&S(m,t)}},200)}},100)},e=>{console.error("Error fetching comments:",e),console.error("Error details:",{code:e.code,message:e.message,documentId:a,linkId:n}),v(!1)});return()=>o()},[t,a,i,m]);const N=p.filter(e=>"resolved"===C?!0===e.resolved:"unresolved"!==C||!0!==e.resolved),B=async e=>{if(e&&l)try{const t=(0,M.aU)(),n=(0,M.doc)(t,"documentComments",e),r=p.find(t=>t.id===e),o=!0===(null===r||void 0===r?void 0:r.resolved);await(0,M.mZ)(n,{resolved:!o,resolvedAt:o?null:(0,M.O5)(),resolvedBy:o?null:l,updatedAt:(0,M.O5)()}),(0,A.gg)("\u2705 Comment ".concat(o?"unresolved":"resolved",":"),e)}catch(t){console.error("Error resolving comment:",t),alert("Failed to resolve comment: "+t.message)}else console.error("Cannot resolve comment: missing commentId or currentUserId")},I=async(e,t)=>{if(e&&t&&t.trim())try{const n=(0,M.aU)(),r=(0,s.xI)(),o=(0,M.doc)(n,"documentComments",e),a=r.currentUser,i={content:t.trim(),authorId:(null===a||void 0===a?void 0:a.uid)||null,authorEmail:(null===a||void 0===a?void 0:a.email)||"[email protected]",authorName:(null===a||void 0===a?void 0:a.displayName)||(null===a||void 0===a?void 0:a.email)||"Anonymous",createdAt:new Date};await(0,M.mZ)(o,{replies:(0,M.hq)(i),updatedAt:(0,M.O5)()}),(0,A.gg)("\u2705 Reply added to comment:",e)}catch(n){throw console.error("Error adding reply:",n),alert("Failed to add reply: "+n.message),n}else console.error("Cannot reply: missing commentId or replyText")};return t?(0,H.jsxs)("div",{className:"comment-panel fixed right-0 top-0 bottom-0 w-96 bg-white shadow-xl z-50 flex flex-col",children:[(0,H.jsxs)("div",{className:"flex items-center justify-between p-4 border-b border-gray-200",children:[(0,H.jsxs)("div",{className:"flex items-center gap-2",children:[(0,H.jsx)(b.A,{className:"w-5 h-5 text-blue-600"}),(0,H.jsx)("h2",{className:"text-lg font-semibold text-gray-900",children:"Comments"}),(0,H.jsxs)("span",{className:"text-sm text-gray-500",children:["(",N.length,")"]})]}),(0,H.jsx)("button",{onClick:n,className:"p-1 hover:bg-gray-100 rounded",children:(0,H.jsx)(d.A,{className:"w-5 h-5 text-gray-500"})})]}),(0,H.jsx)("div",{className:"p-4 border-b border-gray-200",children:(0,H.jsxs)("div",{className:"flex gap-2",children:[(0,H.jsx)("button",{onClick:()=>E("all"),className:"px-3 py-1 text-sm rounded-md ".concat("all"===C?"bg-blue-100 text-blue-700":"bg-gray-100 text-gray-700 hover:bg-gray-200"),children:"All"}),(0,H.jsxs)("button",{onClick:()=>E("unresolved"),className:"px-3 py-1 text-sm rounded-md flex items-center gap-1 ".concat("unresolved"===C?"bg-blue-100 text-blue-700":"bg-gray-100 text-gray-700 hover:bg-gray-200"),children:[(0,H.jsx)(O,{className:"w-3 h-3"}),"Unresolved"]}),(0,H.jsxs)("button",{onClick:()=>E("resolved"),className:"px-3 py-1 text-sm rounded-md flex items-center gap-1 ".concat("resolved"===C?"bg-blue-100 text-blue-700":"bg-gray-100 text-gray-700 hover:bg-gray-200"),children:[(0,H.jsx)(z.A,{className:"w-3 h-3"}),"Resolved"]})]})}),(0,H.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:y?(0,H.jsx)("div",{className:"text-center text-gray-500 py-8",children:"Loading comments..."}):0===N.length?(0,H.jsx)("div",{className:"text-center text-gray-500 py-8",children:"all"===C?"No comments yet":"No ".concat(C," comments")}):N.map(e=>(0,H.jsx)("div",{"data-comment-thread-id":e.id,onClick:t=>((e,t)=>{if(t&&(t.stopPropagation(),t.preventDefault()),e.textRange&&e.documentId){const t=document.querySelector('[data-document-content][data-document-id="'.concat(e.documentId,'"]'));if(t){k.current=e.id;const n=window.getSelection();if(n&&n.removeAllRanges(),t.querySelector('mark[data-comment-id="'.concat(e.id,'"]')))return S(e.id,t),void setTimeout(()=>{k.current=null},1e3);(()=>{const n=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,null,!1);let r,o=0,a=null;for(;r=n.nextNode();){const t=r.textContent.length,n=o;if(o+t>e.textRange.startOffset&&n<e.textRange.endOffset){a=r;break}o+=t}var s;a?null===(s=a.parentElement)||void 0===s||s.scrollIntoView({behavior:"smooth",block:"center"}):t.scrollIntoView({behavior:"smooth",block:"start"})})(),setTimeout(()=>{const n=j(e.textRange,t,e.id);n&&n.length>0?requestAnimationFrame(()=>{requestAnimationFrame(()=>{S(e.id,t),setTimeout(()=>{k.current=null},500)})}):k.current=null},800)}}})(e,t),className:"cursor-pointer ".concat(e.id===m?"bg-blue-50 border-l-4 border-blue-500 pl-2":""),children:(0,H.jsx)(K,{comment:e,onResolve:B,onReply:I,currentUserId:l})},e.id))})]}):null};
2var Y=n(92339),G=n(92212),X=n(78324),Q=n(9463),Z=n(13407),$=n(40643),ee=n(61702);const te="w-full px-3 py-2 border border-hairline rounded-brand-md text-sm text-on-surface bg-white outline-none focus:border-brand box-border";function ne(e){let t=e.fields,n=void 0===t?[]:t,r=e.documentId,a=e.formId,s=e.uploadSessionId,i=e.values,u=void 0===i?{}:i,l=e.onChange,c=e.errors,d=void 0===c?{}:c,m=e.onUploadsInProgressChange,g=e.autoFocusFieldId,h=void 0===g?null:g,p=e.autoFocusStepKey,f=void 0===p?0:p;const x=(0,o.useRef)(null),D=(0,o.useRef)(0);(0,o.useEffect)(()=>{if(!h||!x.current)return;const e=x.current.querySelector('[data-form-field-id="'.concat(h,'"]'));if(!e)return;const t=e.querySelector('input:not([type="hidden"]):not([disabled]), textarea:not([disabled]), select:not([disabled])');if(!t)return;const n=requestAnimationFrame(()=>{t.focus({preventScroll:!1}),t.scrollIntoView({block:"nearest",behavior:"smooth"})});return()=>cancelAnimationFrame(n)},[h,f]);const y=(0,o.useCallback)(e=>{D.current=Math.max(0,D.current+e),null===m||void 0===m||m(D.current)},[m]);return(0,H.jsxs)("div",{ref:x,className:"flex flex-col gap-3",children:[d._form&&(0,H.jsx)("p",{className:"text-xs text-state-danger",children:d._form}),n.map(e=>{const t=d[e.id],n=u[e.id];return(0,H.jsxs)("div",{"data-form-field-id":e.id,children:[(0,H.jsx)("label",{className:"block text-xs font-medium text-on-surface mb-1",children:(e.label||e.type)+(e.required?" *":"")}),"textarea"===e.type&&(0,H.jsx)("textarea",{rows:3,className:"".concat(te," resize-y min-h-[80px]"),value:"string"===typeof n?n:"",placeholder:e.placeholder||"",required:!!e.required,onChange:t=>null===l||void 0===l?void 0:l(e.id,t.target.value)}),"select"===e.type&&(0,H.jsxs)("select",{className:te,value:"string"===typeof n?n:"",required:!!e.required,onChange:t=>null===l||void 0===l?void 0:l(e.id,t.target.value),children:[(0,H.jsx)("option",{value:"",children:e.placeholder||"Select..."}),(0,Z.Ze)(e.options).map(e=>(0,H.jsx)("option",{value:e,children:e},e))]}),"radio"===e.type&&(0,H.jsx)("div",{className:"flex flex-col gap-1.5",children:(0,Z.Ze)(e.options).map(t=>(0,H.jsxs)("label",{className:"flex items-center gap-2 text-sm text-on-surface cursor-pointer",children:[(0,H.jsx)("input",{type:"radio",name:"form-".concat(a,"-").concat(e.id),value:t,checked:n===t,required:!!e.required,onChange:()=>null===l||void 0===l?void 0:l(e.id,t)}),t]},t))}),"checkbox"===e.type&&(0,H.jsx)("div",{className:"flex flex-col gap-1.5",children:(0,Z.Ze)(e.options).map(t=>{const r=Array.isArray(n)&&n.includes(t);return(0,H.jsxs)("label",{className:"flex items-center gap-2 text-sm text-on-surface cursor-pointer",children:[(0,H.jsx)("input",{type:"checkbox",name:"form-".concat(a,"-").concat(e.id),value:t,checked:r,onChange:n=>((e,t,n)=>{const r=Array.isArray(u[e])?u[e]:[],o=n?[...new Set([...r,t])]:r.filter(e=>e!==t);null===l||void 0===l||l(e,o)})(e.id,t,n.target.checked)}),t]},t)})}),("image"===e.type||"pdf"===e.type)&&(0,H.jsx)(re,{field:e,value:n,documentId:r,onSelect:t=>(async(e,t)=>{if(t&&r){y(1);try{const n=await(0,ee.tL)({fieldType:e.type,file:t,documentId:r,formId:a,fieldId:e.id,uploadSessionId:s});null===l||void 0===l||l(e.id,n)}catch(n){throw null===l||void 0===l||l(e.id,null),n}finally{y(-1)}}})(e,t),onRemove:()=>null===l||void 0===l?void 0:l(e.id,null)}),!["textarea","select","radio","checkbox","image","pdf"].includes(e.type)&&(0,H.jsx)("input",{type:"email"===e.type?"email":"phone"===e.type?"tel":"number"===e.type?"number":"date"===e.type?"date":"url"===e.type?"url":"text",className:te,value:"string"===typeof n?n:"",placeholder:e.placeholder||"",required:!!e.required,onChange:t=>null===l||void 0===l?void 0:l(e.id,t.target.value)}),t&&(0,H.jsx)("p",{className:"text-xs text-state-danger mt-1",children:t})]},e.id)})]})}function re(e){let t=e.field,n=e.value,a=e.documentId,s=e.onSelect,i=e.onRemove;const u=(0,o.useRef)(null),l=(0,o.useState)(null),c=(0,r.A)(l,2),d=c[0],m=c[1],g=(0,o.useState)(null),h=(0,r.A)(g,2),p=h[0],f=h[1],x=(0,o.useState)(!1),D=(0,r.A)(x,2),y=D[0],v=D[1],b=(0,$.nM)(n)?n:null,F=(0,o.useCallback)(e=>{u.current&&URL.revokeObjectURL(u.current),u.current=e,m(e)},[]);(0,o.useEffect)(()=>()=>{u.current&&(URL.revokeObjectURL(u.current),u.current=null)},[]),(0,o.useEffect)(()=>{b||(F(null),f(null))},[b,F]),(0,o.useEffect)(()=>
2{if("image"!==t.type||null===b||void 0===b||!b.storagePath||!a||d)return void(d||f(null));let e=!1;return v(!0),(0,ee.Xd)(a,b.storagePath).then(t=>{e||f(t)}).catch(()=>{e||f(null)}).finally(()=>{e||v(!1)}),()=>{e=!0}},[t.type,null===b||void 0===b?void 0:b.storagePath,a,d]);const w=d||p;return(0,H.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,H.jsx)("input",{type:"file",accept:(0,$.LO)(t.type),className:"text-sm w-full",onChange:async e=>{var n;const r=null===(n=e.target.files)||void 0===n?void 0:n[0];if(r){"image"===t.type&&(F(URL.createObjectURL(r)),f(null));try{await s(r)}catch(o){F(null),e.target.value=""}}}}),(null===b||void 0===b?void 0:b.fileName)&&(0,H.jsxs)("div",{className:"flex items-center gap-2 flex-wrap mt-1",children:["image"===t.type&&(y&&!w?(0,H.jsx)("span",{className:"text-xs text-on-surface/60",children:"Loading preview\u2026"}):w?(0,H.jsx)("img",{src:w,alt:b.fileName||"Uploaded image",className:"max-w-[160px] max-h-[120px] rounded-brand-md border border-hairline object-cover"}):null),(0,H.jsx)("span",{className:"text-sm text-on-surface",children:b.fileName}),(0,H.jsx)("button",{type:"button",className:"text-xs text-state-danger bg-transparent border-0 cursor-pointer p-0",onClick:()=>{F(null),f(null),i()},children:"Remove"})]})]})}function oe(e){let t=e.currentStepIndex,n=void 0===t?0:t,r=e.totalSteps,o=void 0===r?1:r,a=e.stepLabel,s=void 0===a?"":a;const i=Math.max(1,o),u=Math.min(Math.max(0,n),i-1);return(0,H.jsxs)("div",{className:"mb-6",children:[(0,H.jsxs)("div",{className:"flex items-center justify-between gap-3 mb-3",children:[(0,H.jsxs)("p",{className:"text-sm font-medium text-on-surface",children:["Step ",u+1," of ",i]}),s?(0,H.jsx)("p",{className:"text-sm text-on-surface/70 truncate",children:s}):null]}),(0,H.jsx)("div",{className:"flex items-center gap-1.5",children:Array.from({length:i},(e,t)=>(0,H.jsx)("span",{className:"h-2 flex-1 rounded-full transition-colors ".concat(t<=u?"bg-brand":"bg-surface-muted border border-hairline"),"aria-hidden":!0},t))})]})}const ae={email:{test:e=>/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(e),msg:"Please enter a valid email address"},phone:{test:e=>/^[+]?[\d\s().-]{7,}$/.test(e),msg:"Please enter a valid phone number"},url:{test:e=>/^https?:\/\/[^\s/$.?#].[^\s]*$/i.test(e),msg:"Please enter a valid URL (e.g. https://example.com)"}};function se(e,t){const n={};if(((arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}).uploadsInProgress||0)>0)return n._form="Please wait for file uploads to finish.",{valid:!1,errors:n};for(const r of e||[]){const e=null===t||void 0===t?void 0:t[r.id];if("checkbox"===r.type){const t=Array.isArray(e)?e:[];r.required&&0===t.length&&(n[r.id]="".concat(r.label||"Selection"," is required"));continue}if("radio"===r.type){const t="string"===typeof e?e.trim():"";r.required&&!t&&(n[r.id]="".concat(r.label||"Selection"," is required"));continue}if("image"===r.type||"pdf"===r.type){r.required&&!(0,$.nM)(e)&&(n[r.id]="Please upload a file.");continue}const o="string"===typeof e?e.trim():"";if(r.required&&!o){n[r.id]="".concat(r.label||r.type," is required");continue}const a=ae[r.type];a&&o&&!a.test(o)&&(n[r.id]=a.msg)}return{valid:0===Object.keys(n).length,errors:n}}function ie(e,t){return!e||("checkbox"===e.type?!Array.isArray(t)||0===t.length:"radio"===e.type?"string"!==typeof t||!t.trim():"image"===e.type||"pdf"===e.type?!(0,$.nM)(t):"string"!==typeof t||!t.trim())}function ue(e,t){const n={};for(const r of e||[]){const e=null===t||void 0===t?void 0:t[r.id];"checkbox"===r.type?n[r.id]=Array.isArray(e)?e:[]:"radio"===r.type||"text"===r.type||"textarea"===r.type||"email"===r.type||"phone"===r.type||"number"===r.type||"date"===r.type||"url"===r.type||"select"===r.type?n[r.id]="string"===typeof e?e:null==e?"":String(e):"image"===r.type||"pdf"===r.type?n[r.id]=(0,$.nM)(e)?e:null:n[r.id]=null!==e&&void 0!==e?e:""}return n}function le(e){let t=e.formStepCount,n=void 0===t?0:t,r=e.hasSignatureBlocks,o=void 0!==r&&r,a=e.hasPaymentStep,s=void 0!==a&&a;return Math.max(0,n)+(o?1:0)+(s?1:0)}function ce(e){let t=e.phase,n=e.formStepIndex,r=void 0===n?0:n,o=e.formStepCount,a=void 0===o?0:o,s=e.hasSignatureBlocks,i=void 0!==s&&s,u=e.hasPaymentStep,l=void 0!==u&&u;const c=Math.max(0,a),d=le({formStepCount:c,hasSignatureBlocks:i,hasPaymentStep:l});if(0===d)return 0;if("wizard"===t)return Math.min(Math.max(0,r),Math.max(0,c-1));let m=c;return"postForm"===t?i?c:Math.max(0,c-1):"payment"===t?(m=c+(i?1:0),Math.min(m,d-1)):d-1}function de(e){let t=e.phase,n=e.hasSignatureBlocks;return"postForm"===t&&(void 0!==n&&n)?"Signature":"payment"===t?"Payment":""}const me="wizard",ge="postForm",he="payment",pe="complete";function fe(e,t){return"".concat("share-onboarding:").concat(e,":").concat(t)}function xe(e,t){if("undefined"===typeof window||!e||!t)return null;try{const n=window.sessionStorage.getItem(fe(e,t));if(!n)return null;const r=JSON.parse(n);return r&&"object"===typeof r?r:null}catch(n){return null}}function De(e,t,n){if("undefined"!==typeof window&&e&&t)try{const r=xe(e,t)||{};window.sessionStorage.setItem(fe(e,t),JSON.stringify((0,u.A)((0,u.A)({},r),n)))}catch(r){}}function ye(e){let t=e.steps,n=void 0===t?[]:t,a=e.documentId,s=e.documentTitle,l=void 0===s?"":s,d=e.uploadSessionId,m=e.onComplete,g=e.brandColors,h=e.hasSignatureBlocks,p=void 0!==h&&h,f=e.hasPaymentStep,x=void 0!==f&&f;const D=(0,o.useMemo)(()=>d||(0,$.Mu)(),[d]),y=(0,o.useState)(0),v=(0,r.A)(y,2),b=v[0],F=v[1],w=(0,o.useState)({}),A=(0,r.A)(w,2),C=A[0],E=A[1],k=(0,o.useState)({}),j=(0,r.A)(k,2),N=j[0],S=j[1],B=(0,o.useState)(0),I=(0,r.A)(B,2),T=I[0],L=I[1],R=(0,o.useState)(!1),P=(0,r.A)(R,2),O=P[0],z=P[1],M=(0,o.useState)(""),U=(0,r.A)(M,2),q=U[0],V=U[1],_=(0,o.useState)(null),W=(0,r.A)(_,2),K=W[0],J=W[1],Y=(0,o.useState)(0),X=(0,r.A)(Y,2),Z=X[0],ee=X[1],te=(0,o.useRef)(null),re=n.length,ae=n[b],de=b>=re-1,ge=le({formStepCount:re,hasSignatureBlocks:p,hasPaymentStep:x}),he=ce({phase:me,formStepIndex:b,formStepCount:re,hasSignatureBlocks:p,hasPaymentStep:x}),pe=(0,o.useMemo)(()=>ae&&C[ae.formId]||{},[C,ae]),fe=(0,o.useMemo)(()=>{var e;return null!==ae&&void 0!==ae&&null!==(e=ae.contentBlocks)&&void 0!==e&&e.length?{type:"doc",content:ae.contentBlocks}:null},[ae]),xe=!!fe,De=(0,o.useRef)(C);De.current=C,(0,o.useEffect)(()=>{const e=n[b];if(!e)return;const t=te.current;if(te.current=b,null===t||t===b)return;const r=function(e,t){for(const n of e||[])if(ie(n,null===t||void 0===t?void 0:t[n.id]))return n.id;return null}(e.fields,De.current[e.formId]||{});J(r),ee(e=>e+1)},[b,n]);const ye=(0,o.useCallback)((e,t)=>{ae&&(E(n=>(0,u.A)((0,u.A)({},n),{},{[ae.formId]:(0,u.A)((0,u.A)({},n[ae.formId]||{}),{},{[e]:t})})),S(t=>{if(!t[e]&&!t._form)return t;const n=(0,u.A)({},t);return delete n[e],delete n._form,n}))},[ae]),ve=(0,o.useCallback)(()=>
2{if(!ae)return!1;const e=se(ae.fields,pe,{uploadsInProgress:T});return S(e.errors),e.valid},[ae,pe,T]),be=(0,o.useCallback)(()=>{if(T>0)return S({_form:"Please wait for file uploads to finish."}),!1;for(const e of n){const t=C[e.formId]||{},n=se(e.fields,t,{uploadsInProgress:0});if(!n.valid)return F(e.stepIndex),S(n.errors),!1}return S({}),!0},[n,C,T]);if(!ae||0===re)return null;const Fe=(null===g||void 0===g?void 0:g.primary)||void 0;return(0,H.jsxs)("div",{className:"max-w-2xl mx-auto my-6 px-4",children:[l&&(0,H.jsx)("h1",{className:"text-headline-lg font-display text-on-surface mb-4",children:l}),(0,H.jsx)(oe,{currentStepIndex:he,totalSteps:ge,stepLabel:ae.title}),xe&&(0,H.jsx)("div",{className:"prose max-w-none mb-6 text-on-surface [&_.ProseMirror]:outline-none",children:(0,H.jsx)(G.A,{json:fe,documentId:a,formRenderMode:"inline"})},"prose-".concat(ae.formId)),(0,H.jsxs)("div",{className:"rounded-brand-md border border-hairline bg-surface-muted p-6",children:[!xe&&(0,H.jsx)("h2",{className:"text-lg font-semibold text-on-surface mb-1",children:ae.title}),ae.description&&(0,H.jsx)("p",{className:"text-sm text-on-surface/70 mb-4",children:ae.description}),(0,H.jsx)(ne,{fields:ae.fields,documentId:a,formId:ae.formId,uploadSessionId:D,values:pe,onChange:ye,errors:N,onUploadsInProgressChange:L,autoFocusFieldId:K,autoFocusStepKey:Z}),q&&(0,H.jsx)("p",{className:"text-sm text-state-danger mt-4",children:q}),(0,H.jsxs)("div",{className:"flex items-center justify-between gap-3 mt-6 pt-4 border-t border-hairline",children:[(0,H.jsxs)("button",{type:"button",onClick:()=>{F(e=>Math.max(e-1,0)),S({})},disabled:0===b||O,className:"inline-flex items-center gap-1 px-4 py-2 text-sm font-medium rounded-brand-md border border-hairline bg-white text-on-surface disabled:opacity-40 disabled:cursor-not-allowed hover:bg-surface-muted transition-colors",children:[(0,H.jsx)(Q.A,{className:"w-4 h-4"}),"Back"]}),de?(0,H.jsx)("button",{type:"button",onClick:async()=>{if(be()){z(!0),V("");try{var e;const t=n.map(e=>({formId:e.formId,responses:ue(e.fields,C[e.formId]||{})})),r=(0,i.getFunctions)(),o=(0,i.httpsCallable)(r,"submitFormWizardResponse"),s=await o({documentId:a,steps:t});null===m||void 0===m||m({answers:C,responseId:(null===s||void 0===s||null===(e=s.data)||void 0===e?void 0:e.responseId)||null})}catch(t){V((null===t||void 0===t?void 0:t.message)||"Failed to submit form. Please try again.")}finally{z(!1)}}},disabled:O||T>0,className:"inline-flex items-center gap-1 px-5 py-2 text-sm font-medium rounded-brand-md text-white disabled:opacity-50 disabled:cursor-not-allowed transition-colors bg-brand hover:bg-brand-hover",style:Fe?{backgroundColor:Fe}:void 0,children:O?"Submitting\u2026":p?"Continue to sign":"Finish"}):(0,H.jsxs)("button",{type:"button",onClick:()=>{ve()&&(F(e=>Math.min(e+1,re-1)),S({}))},disabled:O||T>0,className:"inline-flex items-center gap-1 px-5 py-2 text-sm font-medium rounded-brand-md text-white disabled:opacity-50 disabled:cursor-not-allowed transition-colors bg-brand hover:bg-brand-hover",children:["Next",(0,H.jsx)(c.A,{className:"w-4 h-4"})]})]})]})]})}var ve=n(81452);function be(e){let t=e.documentTitle,n=void 0===t?"":t,r=e.variant,a=void 0===r?"default":r,s=e.paymentAmountCents,i=void 0===s?null:s,u=e.subtitle,l=void 0===u?"":u,c=e.onContinue,d=void 0===c?null:c,m=e.continueLabel,g=void 0===m?"Continue":m,h=e.continueDisabled,p=void 0!==h&&h,f=e.continueLoading,x=void 0!==f&&f,D=e.showConfetti,y=void 0===D||D,v=e.formStepCount,b=void 0===v?0:v,F=e.hasSignatureBlocks,w=void 0!==F&&F,A=e.hasPaymentStep,C=void 0!==A&&A;(0,o.useEffect)(()=>{if(!y)return;return function(){var e,t;if("undefined"===typeof window||"undefined"===typeof document)return()=>{};if(null!==(e=(t=window).matchMedia)&&void 0!==e&&e.call(t,"(prefers-reduced-motion: reduce)").matches)return()=>{};const n=document.createElement("canvas");n.setAttribute("aria-hidden","true"),Object.assign(n.style,{position:"fixed",inset:"0",width:"100%",height:"100%",pointerEvents:"none",zIndex:"9999"}),document.body.appendChild(n);const r=n.getContext("2d"),o=window.innerWidth,a=window.innerHeight;n.width=o,n.height=a;const s=["#2563eb","#16a34a","#f59e0b","#ec4899","#8b5cf6","#06b6d4"],i=Array.from({length:140},()=>({x:.5*o+(Math.random()-.5)*o*.5,y:.35*a+80*(Math.random()-.5),vx:9*(Math.random()-.5),vy:-4-6*Math.random(),size:5+7*Math.random(),color:s[Math.floor(Math.random()*s.length)],rot:Math.random()*Math.PI*2,vr:.25*(Math.random()-.5)}));let u=0,l=0;const c=()=>
2{r.clearRect(0,0,o,a),i.forEach(e=>{e.x+=e.vx,e.y+=e.vy,e.vy+=.18,e.vx*=.99,e.rot+=e.vr,r.save(),r.translate(e.x,e.y),r.rotate(e.rot),r.fillStyle=e.color,r.fillRect(-e.size/2,-e.size/4,e.size,e.size/2),r.restore()}),u+=1,u<200?l=requestAnimationFrame(c):n.remove()};return l=requestAnimationFrame(c),()=>{cancelAnimationFrame(l),n.remove()}}()},[y]);const E="payment"===a,k="paymentSuccess"===a,j=k?"Payment received":E?"You're all set":"Thank you!",N=k?"Your payment was processed successfully.":E?l||"Complete payment to finish.":"Everything was submitted successfully.",S=k?"Thank you \u2014 we'll be in touch if anything else is needed.":E?"We've saved your responses. The next step is secure checkout.":"We've received your responses and will follow up if needed.",B=E&&i?(0,ve.yP)(i).replace(/^Pay\s*/i,""):null,I=E&&b>0&&C,T=I?le({formStepCount:b,hasSignatureBlocks:w,hasPaymentStep:C}):0,L=I?ce({phase:he,formStepCount:b,hasSignatureBlocks:w,hasPaymentStep:C}):0,R=I?de({phase:he}):"";return(0,H.jsx)("div",{className:"min-h-[60vh] flex items-center justify-center px-4 py-12",children:(0,H.jsxs)("div",{className:"w-full max-w-lg text-center",children:[n&&(0,H.jsx)("p",{className:"text-xs font-medium uppercase tracking-wider text-on-surface/60 mb-3",children:n}),I&&(0,H.jsx)("div",{className:"text-left mb-4",children:(0,H.jsx)(oe,{currentStepIndex:L,totalSteps:T,stepLabel:R})}),(0,H.jsxs)("div",{className:"rounded-brand-md border border-hairline bg-white shadow-sm px-8 py-10",children:[(0,H.jsx)("div",{className:"w-16 h-16 bg-state-success-soft rounded-full flex items-center justify-center mx-auto mb-5",children:(0,H.jsx)(V.A,{className:"w-8 h-8 text-state-success",strokeWidth:2.5})}),(0,H.jsx)("h1",{className:"text-headline-lg font-display text-on-surface mb-2",children:j}),B&&(0,H.jsx)("p",{className:"text-3xl font-display font-semibold text-on-surface mb-3",children:B}),(0,H.jsx)("p",{className:"text-base text-on-surface/80 mb-1",children:N}),(0,H.jsx)("p",{className:"text-sm text-on-surface/60",children:S}),"function"===typeof d&&(0,H.jsx)("button",{type:"button",onClick:d,disabled:p,className:"mt-8 inline-flex items-center justify-center px-6 py-3 text-sm font-medium rounded-brand-md text-white bg-brand hover:bg-brand-hover transition-colors disabled:opacity-50",children:x?"Redirecting to payment\u2026":g})]})]})})}function Fe(e){let t=e.children,n=e.formStepCount,r=void 0===n?1:n,o=e.hasSignatureBlocks,a=void 0===o||o,s=e.hasPaymentStep,i=void 0!==s&&s;const u=le({formStepCount:r,hasSignatureBlocks:a,hasPaymentStep:i}),l=ce({phase:ge,formStepCount:r,hasSignatureBlocks:a,hasPaymentStep:i}),c=de({phase:ge,hasSignatureBlocks:a});return(0,H.jsxs)("div",{className:"max-w-2xl mx-auto my-6 px-4",children:[(0,H.jsx)(oe,{currentStepIndex:l,totalSteps:u,stepLabel:c}),(0,H.jsx)("div",{className:"rounded-brand-md border border-hairline bg-white shadow-sm px-6 py-5 mb-6",children:(0,H.jsxs)("div",{className:"min-w-0 text-left",children:[(0,H.jsx)("h2",{className:"mt-0 text-lg font-display font-semibold text-on-surface leading-snug mb-1",children:"Please sign below"}),(0,H.jsx)("p",{className:"text-sm text-on-surface/60 mb-0",children:"Review the acknowledgment and complete your signature to continue."})]})}),t]})}function we(e){return!e||"object"!==typeof e||"paragraph"===e.type&&(!Array.isArray(e.content)||0===e.content.length)}function Ae(e){const t=(e||[]).filter(e=>{return e&&!we(e)&&!("signatureBlock"===(null===(t=e)||void 0===t?void 0:t.type)||"paymentButton"===(null===t||void 0===t?void 0:t.type));var t});if(0===t.length)return{formTrailing:[],signatureLeadIn:[]};let n=-1;for(let r=0;r<t.length;r+=1)"heading"===t[r].type&&(n=r);return n>=0?{formTrailing:t.slice(0,n),signatureLeadIn:t.slice(n)}:{formTrailing:t.slice(0,-1),signatureLeadIn:t.slice(-1)}}function Ce(e){if(!e||"object"!==typeof e)return null;const t=Array.isArray(e.content)?e.content:[];if(0===t.length)return null;const n=function(e){const t=Array.isArray(e)?e:[];let n=-1;for(let u=0;u<t.length;u+=1){var r;"formBlock"===(null===(r=t[u])||void 0===r?void 0:r.type)&&(n=u)}const o=n>=0?t.slice(n+1):t,a=[],s=[];for(const l of o)l&&"object"===typeof l&&"formBlock"!==l.type&&"paymentButton"!==l.type&&("signatureBlock"!==l.type?we(l)||a.push(l):s.push((0,u.A)({},l)));if(0===s.length)return{formTrailing:a,signatureStepBlocks:[]};const i=Ae(a);return{formTrailing:i.formTrailing,signatureStepBlocks:[...i.signatureLeadIn.map(e=>(0,u.A)({},e)),...s]}}(t),r=n.signatureStepBlocks;
2if(r.length>0)return{type:"doc",content:r};const o=[],a=e=>{e&&"object"===typeof e&&("signatureBlock"!==e.type?Array.isArray(e.content)&&e.content.forEach(a):o.push((0,u.A)({},e)))};return t.forEach(a),0===o.length?null:{type:"doc",content:o}}var Ee=n(77052);function ke(e){return"signatureBlock"===(null===e||void 0===e?void 0:e.type)||"paymentButton"===(null===e||void 0===e?void 0:e.type)}function je(e){return e.filter(e=>{return!ke(e)&&!(!(t=e)||"object"!==typeof t||"paragraph"===t.type&&(!Array.isArray(t.content)||0===t.content.length));var t})}function Ne(e){if(!e||"doc"!==e.type)return[];const t=(0,Z.Us)(e),n=[];let r=0,o=[];for(const u of t.content||[]){var a,s,i;if("formBlock"!==u.type)ke(u)||o.push(u);else n.push({formId:(null===(a=u.attrs)||void 0===a?void 0:a.formId)||"form-".concat(r),title:(null===(s=u.attrs)||void 0===s?void 0:s.title)||"Form",description:(null===(i=u.attrs)||void 0===i?void 0:i.description)||"",fields:(0,Z.WB)(u),stepIndex:r,contentBlocks:je(o)}),o=[],r+=1}if(n.length>0&&o.length>0){const e=(t.content||[]).some(ke),r=je(o);if(r.length>0){const t=n[n.length-1];if(e){const e=Ae(r).formTrailing;e.length>0&&(t.contentBlocks=[...t.contentBlocks,...e])}else t.contentBlocks=[...t.contentBlocks,...r]}}return n}var Se=n(42773),Be=n(21949);function Ie(e){return String(e||"").normalize("NFKC").replace(/(?:[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26A7\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDC2C-\uDC2F\uDC94-\uDC9F\uDCAF\uDCB0\uDCC0\uDCCF\uDCD0\uDCF6-\uDCFF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDAE-\uDDE5\uDE01-\uDE0F\uDE1A\uDE2F\uDE32-\uDE3A\uDE3C-\uDE3F\uDE49-\uDE5F\uDE66-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFA]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD7A\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA4\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED2\uDED5-\uDEE5\uDEE9\uDEEB-\uDEF0\uDEF3-\uDEFF\uDFDA-\uDFFF]|\uD83E[\uDC0C-\uDC0F\uDC48-\uDC4F\uDC5A-\uDC5F\uDC88-\uDC8F\uDCAE\uDCAF\uDCBC-\uDCBF\uDCC2-\uDCCF\uDCD9-\uDCFF\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDDFF\uDE58-\uDE5F\uDE6E-\uDEFF]|\uD83F[\uDC00-\uDFFD])/g,"").toLowerCase().replace(/(?:[\0-\x08\x0E-\x1F!-\/:-@\[-`\{-\x9F\xA1-\xA9\xAB-\xB1\xB4\xB6-\xB8\xBB\xBF\xD7\xF7\u02C2-\u02C5\u02D2-\u02DF\u02E5-\u02EB\u02ED\u02EF-\u036F\u0375\u0378\u0379\u037E\u0380-\u0385\u0387\u038B\u038D\u03A2\u03F6\u0482-\u0489\u0530\u0557\u0558\u055A-\u055F\u0589-\u05CF\u05EB-\u05EE\u05F3-\u061F\u064B-\u065F\u066A-\u066D\u0670\u06D4\u06D6-\u06E4\u06E7-\u06ED\u06FD\u06FE\u0700-\u070F\u0711\u0730-\u074C\u07A6-\u07B0\u07B2-\u07BF\u07EB-\u07F3\u07F6-\u07F9\u07FB-\u07FF\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u083F\u0859-\u085F\u086B-\u086F\u0888\u0890-\u089F\u08CA-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962-\u0965\u0970\u0981-\u0984\u098D\u098E\u0991\u0992\u09A9\u09B1\u09B3-\u09B5\u09BA-\u09BC\u09BE-\u09CD\u09CF-\u09DB\u09DE\u09E2-\u09E5\u09F2\u09F3\u09FA\u09FB\u09FD-\u0A04\u0A0B-\u0A0E\u0A11\u0A12\u0A29\u0A31\u0A34\u0A37\u0A3A-\u0A58\u0A5D\u0A5F-\u0A65\u0A70\u0A71\u0A75-\u0A84\u0A8E\u0A92\u0AA9\u0AB1\u0AB4\u0ABA-\u0ABC\u0ABE-\u0ACF\u0AD1-\u0ADF\u0AE2-\u0AE5\u0AF0-\u0AF8\u0AFA-\u0B04\u0B0D\u0B0E\u0B11\u0B12\u0B29\u0B31\u0B34\u0B3A-\u0B3C\u0B3E-\u0B5B\u0B5E\u0B62-\u0B65\u0B70\u0B78-\u0B82\u0B84\u0B8B-\u0B8D\u0B91\u0B96-\u0B98\u0B9B\u0B9D\u0BA0-\u0BA2\u0BA5-\u0BA7\u0BAB-\u0BAD\u0BBA-\u0BCF\u0BD1-\u0BE5\u0BF3-\u0C04\u0C0D\u0C11\u0C29\u0C3A-\u0C3C\u0C3E-\u0C57\u0C5B\u0C5E\u0C5F\u0C62-\u0C65\u0C70-\u0C77\u0C7F\u0C81-\u0C84\u0C8D\u0C91\u0CA9\u0CB4\u0CBA-\u0CBC\u0CBE-\u0CDB\u0CDF\u0CE2-\u0CE5\u0CF0\u0CF3-\u0D03\u0D0D\u0D11\u0D3B\u0D3C\u0D3E-\u0D4D\u0D4F-\u0D53\u0D57\u0D62-\u0D65\u0D79\u0D80-\u0D84\u0D97-\u0D99\u0DB2\u0DBC\u0DBE\u0DBF\u0DC7-\u0DE5\u0DF0-\u0E00\u0E31\u0E34-\u0E3F\u0E47-\u0E4F\u0E5A-\u0E80\u0E83\u0E85\u0E8B\u0EA4\u0EA6\u0EB1\u0EB4-\u0EBC\u0EBE\u0EBF\u0EC5\u0EC7-\u0ECF\u0EDA\u0EDB\u0EE0-\u0EFF\u0F01-\u0F1F\u0F34-\u0F3F\u0F48\u0F6D-\u0F87\u0F8D-\u0FFF\u102B-\u103E\u104A-\u104F\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109F\u10C6\u10C8-\u10CC\u10CE\u10CF\u10FB\u1249\u124E\u124F\u1257\u1259\u125E\u125F\u1289\u128E\u128F\u12B1\u12B6\u12B7\u12BF\u12C1\u12C6\u12C7\u12D7\u1311\u1316\u1317\u135B-\u1368\u137D-\u137F\u1390-\u139F\u13F6\u13F7\u13FE-\u1400\u166D\u166E\u169B-\u169F\u16EB-\u16ED\u16F9-\u16FF\u1712-\u171E\u1732-\u173F\u1752-\u175F\u176D\u1771-\u177F\u17B4-\u17D6\u17D8-\u17DB\u17DD-\u17DF\u17EA-\u17EF\u17FA-\u180F\u181A-\u181F\u1879-\u187F\u1885\u1886\u18A9\u18AB-\u18AF\u18F6-\u18FF\u191F-\u1945\u196E\u196F\u1975-\u197F\u19AC-\u19AF\u19CA-\u19CF\u19DB-\u19FF\u1A17-\u1A1F\u1A55-\u1A7F\u1A8A-\u1A8F\u1A9A-\u1AA6\u1AA8-\u1B04\u1B34-\u1B44\u1B4D-\u1B4F\u1B5A-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BFF\u1C24-\u1C3F\u1C4A-\u1C4C\u1C7E\u1C7F\u1C8B-\u1C8F\u1CBB\u1CBC\u1CC0-\u1CE8\u1CED\u1CF4\u1CF7-\u1CF9\u1CFB-\u1CFF\u1DC0-\u1DFF\u1F16\u1F17\u1F1E\u1F1F\u1F46\u1F47\u1F4E\u1F4F\u1F58\u1F5A\u1F5C\u1F5E\u1F7E\u1F7F\u1FB5\u1FBD\u1F
2BF-\u1FC1\u1FC5\u1FCD-\u1FCF\u1FD4\u1FD5\u1FDC-\u1FDF\u1FED-\u1FF1\u1FF5\u1FFD-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u206F\u2072\u2073\u207A-\u207E\u208A-\u208F\u209D-\u2101\u2103-\u2106\u2108\u2109\u2114\u2116-\u2118\u211E-\u2123\u2125\u2127\u2129\u212E\u213A\u213B\u2140-\u2144\u214A-\u214D\u214F\u218A-\u245F\u249C-\u24E9\u2500-\u2775\u2794-\u2BFF\u2CE5-\u2CEA\u2CEF-\u2CF1\u2CF4-\u2CFC\u2CFE\u2CFF\u2D26\u2D28-\u2D2C\u2D2E\u2D2F\u2D68-\u2D6E\u2D70-\u2D7F\u2D97-\u2D9F\u2DA7\u2DAF\u2DB7\u2DBF\u2DC7\u2DCF\u2DD7\u2DDF-\u2E2E\u2E30-\u2FFF\u3001-\u3004\u3008-\u3020\u302A-\u3030\u3036\u3037\u303D-\u3040\u3097-\u309C\u30A0\u30FB\u3100-\u3104\u3130\u318F-\u3191\u3196-\u319F\u31C0-\u31EF\u3200-\u321F\u322A-\u3247\u3250\u3260-\u327F\u328A-\u32B0\u32C0-\u33FF\u4DC0-\u4DFF\uA48D-\uA4CF\uA4FE\uA4FF\uA60D-\uA60F\uA62C-\uA63F\uA66F-\uA67E\uA69E\uA69F\uA6F0-\uA716\uA720\uA721\uA789\uA78A\uA7DD-\uA7F0\uA802\uA806\uA80B\uA823-\uA82F\uA836-\uA83F\uA874-\uA881\uA8B4-\uA8CF\uA8DA-\uA8F1\uA8F8-\uA8FA\uA8FC\uA8FF\uA926-\uA92F\uA947-\uA95F\uA97D-\uA983\uA9B3-\uA9CE\uA9DA-\uA9DF\uA9E5\uA9FF\uAA29-\uAA3F\uAA43\uAA4C-\uAA4F\uAA5A-\uAA5F\uAA77-\uAA79\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAC3-\uAADA\uAADE\uAADF\uAAEB-\uAAF1\uAAF5-\uAB00\uAB07\uAB08\uAB0F\uAB10\uAB17-\uAB1F\uAB27\uAB2F\uAB5B\uAB6A-\uAB6F\uABE3-\uABEF\uABFA-\uABFF\uD7A4-\uD7AF\uD7C7-\uD7CA\uD7FC-\uD7FF\uE000-\uF8FF\uFA6E\uFA6F\uFADA-\uFAFF\uFB07-\uFB12\uFB18-\uFB1C\uFB1E\uFB29\uFB37\uFB3D\uFB3F\uFB42\uFB45\uFBB2-\uFBD2\uFD3E-\uFD4F\uFD90\uFD91\uFDC8-\uFDEF\uFDFC-\uFE6F\uFE75\uFEFD\uFEFE\uFF00-\uFF0F\uFF1A-\uFF20\uFF3B-\uFF40\uFF5B-\uFF65\uFFBF-\uFFC1\uFFC8\uFFC9\uFFD0\uFFD1\uFFD8\uFFD9\uFFDD-\uFFFF]|\uD800[\uDC0C\uDC27\uDC3B\uDC3E\uDC4E\uDC4F\uDC5E-\uDC7F\uDCFB-\uDD06\uDD34-\uDD3F\uDD79-\uDD89\uDD8C-\uDE7F\uDE9D-\uDE9F\uDED1-\uDEE0\uDEFC-\uDEFF\uDF24-\uDF2C\uDF4B-\uDF4F\uDF76-\uDF7F\uDF9E\uDF9F\uDFC4-\uDFC7\uDFD0\uDFD6-\uDFFF]|\uD801[\uDC9E\uDC9F\uDCAA-\uDCAF\uDCD4-\uDCD7\uDCFC-\uDCFF\uDD28-\uDD2F\uDD64-\uDD6F\uDD7B\uDD8B\uDD93\uDD96\uDDA2\uDDB2\uDDBA\uDDBD-\uDDBF\uDDF4-\uDDFF\uDF37-\uDF3F\uDF56-\uDF5F\uDF68-\uDF7F\uDF86\uDFB1\uDFBB-\uDFFF]|\uD802[\uDC06\uDC07\uDC09\uDC36\uDC39-\uDC3B\uDC3D\uDC3E\uDC56\uDC57\uDC77\uDC78\uDC9F-\uDCA6\uDCB0-\uDCDF\uDCF3\uDCF6-\uDCFA\uDD1C-\uDD1F\uDD3A-\uDD3F\uDD5A-\uDD7F\uDDB8-\uDDBB\uDDD0\uDDD1\uDE01-\uDE0F\uDE14\uDE18\uDE36-\uDE3F\uDE49-\uDE5F\uDE7F\uDEA0-\uDEBF\uDEC8\uDEE5-\uDEEA\uDEF0-\uDEFF\uDF36-\uDF3F\uDF56\uDF57\uDF73-\uDF77\uDF92-\uDFA8\uDFB0-\uDFFF]|\uD803[\uDC49-\uDC7F\uDCB3-\uDCBF\uDCF3-\uDCF9\uDD24-\uDD2F\uDD3A-\uDD3F\uDD66-\uDD6E\uDD86-\uDE5F\uDE7F\uDEAA-\uDEAF\uDEB2-\uDEC1\uDEC8-\uDEFF\uDF28-\uDF2F\uDF46-\uDF50\uDF55-\uDF6F\uDF82-\uDFAF\uDFCC-\uDFDF\uDFF7-\uDFFF]|\uD804[\uDC00-\uDC02\uDC38-\uDC51\uDC70\uDC73\uDC74\uDC76-\uDC82\uDCB0-\uDCCF\uDCE9-\uDCEF\uDCFA-\uDD02\uDD27-\uDD35\uDD40-\uDD43\uDD45\uDD46\uDD48-\uDD4F\uDD73-\uDD75\uDD77-\uDD82\uDDB3-\uDDC0\uDDC5-\uDDCF\uDDDB\uDDDD-\uDDE0\uDDF5-\uDDFF\uDE12\uDE2C-\uDE3E\uDE41-\uDE7F\uDE87\uDE89\uDE8E\uDE9E\uDEA9-\uDEAF\uDEDF-\uDEEF\uDEFA-\uDF04\uDF0D\uDF0E\uDF11\uDF12\uDF29\uDF31\uDF34\uDF3A-\uDF3C\uDF3E-\uDF4F\uDF51-\uDF5C\uDF62-\uDF7F\uDF8A\uDF8C\uDF8D\uDF8F\uDFB6\uDFB8-\uDFD0\uDFD2\uDFD4-\uDFFF]|\uD805[\uDC35-\uDC46\uDC4B-\uDC4F\uDC5A-\uDC5E\uDC62-\uDC7F\uDCB0-\uDCC3\uDCC6\uDCC8-\uDCCF\uDCDA-\uDD7F\uDDAF-\uDDD7\uDDDC-\uDDFF\uDE30-\uDE43\uDE45-\uDE4F\uDE5A-\uDE7F\uDEAB-\uDEB7\uDEB9-\uDEBF\uDECA-\uDECF\uDEE4-\uDEFF\uDF1B-\uDF2F\uDF3C-\uDF3F\uDF47-\uDFFF]|\uD806[\uDC2C-\uDC9F\uDCF3-\uDCFE\uDD07\uDD08\uDD0A\uDD0B\uDD14\uDD17\uDD30-\uDD3E\uDD40\uDD42-\uDD4F\uDD5A-\uDD9F\uDDA8\uDDA9\uDDD1-\uDDE0\uDDE2\uDDE4-\uDDFF\uDE01-\uDE0A\uDE33-\uDE39\uDE3B-\uDE4F\uDE51-\uDE5B\uDE8A-\uDE9C\uDE9E-\uDEAF\uDEF9-\uDFBF\uDFE1-\uDFEF\uDFFA-\uDFFF]|\uD807[\uDC09\uDC2F-\uDC3F\uDC41-\uDC4F\uDC6D-\uDC71\uDC90-\uDCFF\uDD07\uDD0A\uDD31-\uDD45\uDD47-\uDD4F\uDD5A-\uDD5F\uDD66\uDD69\uDD8A-\uDD97\uDD99-\uDD9F\uDDAA-\uDDAF\uDDDC-\uDDDF\uDDEA-\uDEDF\uDEF3-\uDF01\uDF03\uDF11\uDF34-\uDF4F\uDF5A-\uDFAF\uDFB1-\uDFBF\uDFD5-\uDFFF]|\uD808[\uDF9A-\uDFFF]|\uD809[\uDC6F-\uDC7F\uDD44-\uDFFF]|[\uD80A\uD812-\uD817\uD819\uD824-\uD82A\uD82D\uD82E\uD830-\uD832\uD836\uD83D\uD83F\uD87C\uD87D\uD87F\uD88E-\uDBFF][\uDC00-\uDFFF]|\uD80B[\uDC00-\uDF8F\uDFF1-\uDFFF]|\uD80D[\uDC30-\uDC40\uDC47-\uDC5F]|\uD810[\uDFFB-\uDFFF]|\uD811[\uDE47-\uDFFF]|\uD818[\uDC00-\uDCFF\uDD1E-\uDD2F\uDD3A-\uDFFF]|\uD81A[\uDE39-\uDE3F\uDE5F\uDE6A-\uDE6F\uDEBF\uDECA-\uDECF\uDEEE-\uDEFF\uDF30-\uDF3F\uDF44-\uDF4F\uDF5A\uDF62\uDF78-\uDF7C\uDF90-\uDFFF]|\uD81B[\uDC00-\uDD3F\uDD6D-\uDD6F\uDD7A-\uDE3F\uDE97-\uDE9F\uDEB9\uDEBA\uDED4-\uDEFF\uDF4B-\uDF4F\uDF51-\uDF92\uDFA0-\uDFDF\uDFE2\uDFE4-\uDFF1\uDFF7-\uDFFF]|\uD823[\uDCD6-\uDCFE\uDD1F-\uDD7F\uDDF3-\uDFFF]|\uD82B[\uDC00-\uDFEF\uDFF4\uDFFC\uDFFF]|\uD82C[\uDD23-\uDD31\uDD33-\uDD4F\uDD53\uDD54\uDD56-\uDD63\uDD68-\uDD6F\uDEFC-\uDFFF]|\uD82F[\uDC6B-\uDC6F\uDC7D-\uDC7F\uDC89-\uDC8F\uDC9A-\uDFFF]|\uD833[\uDC00-\uDCEF\uDCFA-\uDFFF]|\uD834[\uDC00-\uDEBF\uDED4-\uDEDF\uDEF4-\uDF5F\uDF79-\uDFFF]|\uD835[\uDC55\uDC9D\uDCA0\uDCA1\uDCA3\uDCA4\uDCA7\uDCA8\uDCAD\uDCBA\uDCBC\uDCC4\uDD06\uDD0B\uDD0C\uDD15\uDD1D\uDD3A\uDD3F\uDD45\uDD47-\uDD49\uDD51\uDEA6\uDEA7\uDEC1\uDEDB\uDEFB\uDF15\uDF35\uDF4F\uDF6F\uDF89\uDFA9\uDFC3\uDFCC\uDFCD]|\uD837[\uDC00-\uDEFF\uDF1F-\uDF24\uDF2B-\uDFFF]|\uD838[\uDC00-\uDC2F\uDC6E-\uDCFF\uDD2D-\uDD36\uDD3E\uDD3F\uDD4A-\uDD4D\uDD4F-\uDE8F\uDEAE-\uDEBF\uDEEC-\uDEEF\uDEFA-\uDFFF]|\uD839[\uDC00-\uDCCF\uDCEC-\uDCEF\uDCFA-\uDDCF\uDDEE\uDDEF\uDDFB-\uDEBF\uDEDF\uDEE3\uDEE6\uDEEE\uDEEF\uDEF5-\uDEFD\uDF00-\uDFDF\uDFE7\uDFEC\uDFEF\uDFFF]|\uD83A[\uDCC5\uDCC6\uDCD0-\uDCFF\uDD44-\uDD4A\uDD4C-\uDD4F\uDD5A-\uDFFF]|\uD83B[\uDC00-\uDC70\uDCAC\uDCB0\uDCB5-\uDD00\uDD2E\uDD3E-\uDDFF\uDE04\uDE20\uDE23\uDE25\uDE26\uDE28\uDE33\uDE38\uDE3A\uDE3C-\uDE41\uDE43-\uDE46\uDE48\uDE4A\uDE4C\uDE50\uDE53\uDE55\uDE56\uDE58\uDE5A\uDE5C\uDE5E\uDE60\uDE63\uDE65\uDE66\uDE6B\uDE73\uDE78\uDE7D\uDE7F\uDE8A\uDE9C-\uDEA0\uDEA4\uDEAA\uDEBC-\uDFFF]|\uD83C[\uDC00-\uDCFF\uDD0D-\uDFFF]|\uD83E[\uDC00-\uDFEF\uDFFA-\uDFFF]|\uD869[\uDEE0-\uDEFF]|\uD86E[\uDC1E\uDC1F]|\uD873[\uDEAE\uDEAF]|\uD87A[\uDFE1-\uDFEF]|\uD87B[\uDE5E-\uDFFF]|\uD87E[\uDE1E-\uDFFF]|\uD884[\uDF4B-\uDF4F]|\uD88D[\uDC7A-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])/g,"").replace(/\s+/g," ").trim()}function Te(e,t){if(!e||!t)return!1;const n=e.trim().match(/^<h1\b[^>]*>([\s\S]*?)<\/h1>/i);if(!n)return!1;return function(e,t){const n=Ie(e),r=Ie(t);return n.length>0&&n===r}(n[1].replace(/<[^>]+>/g,"").trim(),t)}var Le=n(74634),Re=n(6858),Pe=n(92298),Oe=n(76031),ze=n(82378),Me=n(47935),Ue=n(62658),qe=n(25349),Ve=n(86353),_e=n(36401),He=n(38288),We=n(99264),Ke=n(45580),Je=n(12602),Ye=n(77927);const Ge=e=>{const t=(e||"").trim().toLowerCase();return!t||"uncategorized"===t||"general"===t||"other"===t},Xe=()=>
2{document.querySelectorAll('link[rel*="icon"]').forEach(e=>e.remove())},Qe=e=>{if(e){const t=new Image;t.onload=()=>{Xe();const t=document.createElement("link");t.type="image/x-icon",t.rel="shortcut icon",t.href=e,document.getElementsByTagName("head")[0].appendChild(t);const n=document.createElement("link");n.rel="apple-touch-icon",n.href=e,document.getElementsByTagName("head")[0].appendChild(n),(0,A.gg)("\ud83c\udfa8 Favicon updated to:",e)},t.onerror=()=>{if((t=e)&&(t.startsWith("http")||t.startsWith("data:")))return void(0,A.gg)("\ud83c\udfa8 Favicon image failed to load via Image() test, keeping existing favicon:",e);var t;console.warn("\ud83c\udfa8 Failed to load favicon image:",e,"Using default instead"),Xe();const n=document.createElement("link");n.type="image/png",n.rel="shortcut icon",n.href="/based-logo.png",document.getElementsByTagName("head")[0].appendChild(n)},t.src=e}else{Xe();const e=document.createElement("link");e.type="image/png",e.rel="shortcut icon",e.href="/based-logo.png",document.getElementsByTagName("head")[0].appendChild(e),(0,A.gg)("\ud83c\udfa8 Favicon restored to default")}};const Ze=e=>{var t,n;let a=e.workspaceId,s=e.config,i=(e.knowledgeBaseTitle,e.orgLogo),l=void 0===i?null:i,x=e.orgName,D=void 0===x?"":x,y=e.documents,v=void 0===y?[]:y,b=e.documentsForRag,F=void 0===b?null:b,E=e.shareLinkId,k=void 0===E?null:E,j=e.viewerBaseOrigin,N=void 0===j?null:j,S=e.onOpenSharedPdfDocument,B=void 0===S?null:S;const I=null!=F?F:v,T=(0,o.useState)(!1),L=(0,r.A)(T,2),R=L[0],P=L[1],O=(0,o.useState)("home"),z=(0,r.A)(O,2),M=z[0],U=z[1],q=(0,o.useState)(null),V=(0,r.A)(q,2),_=V[0],W=V[1],K=(0,o.useState)([{type:"bot",content:s.welcomeMessage,timestamp:Date.now()}]),J=(0,r.A)(K,2),G=J[0],X=J[1],Q=(0,o.useState)(""),Z=(0,r.A)(Q,2),$=Z[0],ee=Z[1],te=(0,o.useState)(!1),ne=(0,r.A)(te,2),re=ne[0],oe=ne[1],ae=(0,o.useState)(!1),se=(0,r.A)(ae,2),ie=se[0],ue=se[1],le=(0,o.useState)(!1),ce=(0,r.A)(le,2),de=ce[0],me=ce[1],ge=(0,o.useState)(!1),he=(0,r.A)(ge,2),pe=he[0],fe=he[1],xe=(0,o.useState)(!1),De=(0,r.A)(xe,2),ye=De[0],ve=De[1],be=(0,o.useRef)(null),Fe=(0,o.useRef)("chat_".concat(a,"_").concat(Date.now())),we=(0,o.useRef)(""),Ae=(0,o.useRef)(!1),Ce=(0,o.useRef)(null),Ee=(0,o.useState)(null),ke=(0,r.A)(Ee,2),je=ke[0],Ne=ke[1],Be=(0,o.useState)({name:"",email:"",phone:""}),Ie=(0,r.A)(Be,2),Oe=Ie[0],ze=Ie[1],We=(0,o.useState)(!1),Je=(0,r.A)(We,2),Ye=Je[0],Ge=Je[1],Xe=(0,o.useState)(!1),Qe=(0,r.A)(Xe,2),Ze=Qe[0],$e=Qe[1],et=(0,o.useRef)(null),tt=(0,o.useRef)(0),nt=(0,o.useRef)(null),rt=(0,o.useRef)(null),ot=(0,o.useRef)(null),at=(0,o.useRef)(null),st=(0,o.useRef)(""),it=(0,o.useCallback)(()=>{nt.current&&(clearInterval(nt.current),nt.current=null)},[]);(0,o.useEffect)(()=>()=>it(),[it]),(0,o.useEffect)(()=>()=>{try{var e;null===(e=ot.current)||void 0===e||e.abort()}catch(t){}ot.current=null,null!=at.current&&(cancelAnimationFrame(at.current),at.current=null)},[]),(0,o.useEffect)(()=>{Fe.current="chat_".concat(a,"_").concat(Date.now()),et.current=null,tt.current=0,it()},[a,it]);const ut=(0,o.useCallback)(()=>{it(),et.current&&(nt.current=setInterval(async()=>{try{const e=et.current;if(!e)return;const t=await fetch((0,Le.jI)(),{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({data:{workspaceId:a,chatId:Fe.current,sessionToken:e,sinceIndex:tt.current}})}),n=await t.json(),r=n.result||n.data||n,o=r.messages||[];for(const a of o)if("assistant"===a.role&&"human"===a.source){const e=a.photoURL||a.photoUrl||a.avatarUrl||"";X(t=>[...t,{type:"human",content:a.content||"",senderName:a.senderName||"Team",photoURL:e||void 0,timestamp:Date.now()}])}"number"===typeof r.fullLength&&(tt.current=r.fullLength)}catch(e){(0,A.gg)("getExternalChatMessages poll error",e)}},4e3))},[a,it]);(0,o.useEffect)(()=>{const e=()=>ue(window.matchMedia("(max-width: 768px)").matches);return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),(0,o.useEffect)(()=>{if(R&&ie){const e=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.body.style.overflow=e}}},[R,ie]),(0,o.useEffect)(()=>
2{if(R&&"chat"===M){ve(!1);const e=setTimeout(()=>ve(!0),1500);return()=>clearTimeout(e)}ve(!1)},[R,M]),(0,o.useEffect)(()=>{const e=rt.current;e&&e.scrollTo({top:e.scrollHeight,behavior:"smooth"})},[G,re,ye,je]),(0,o.useEffect)(()=>{if(!de)return;const e=e=>{be.current&&!be.current.contains(e.target)&&me(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[de]);const lt=async()=>{if(!$.trim()||re)return;const e=$.trim();ee("");const t=G.slice(-10).filter(e=>"user"===e.type||"bot"===e.type).map(e=>({role:"user"===e.type?"user":"assistant",content:e.content})),n={type:"user",content:e,timestamp:Date.now()};X(e=>[...e,n]),oe(!0);const r=!!s.liveRequestsEnabled&&(0,Pe.M_)(e);try{var o;null===(o=ot.current)||void 0===o||o.abort()}catch(d){}null!=at.current&&(cancelAnimationFrame(at.current),at.current=null);const i=new AbortController;ot.current=i,st.current="";let l=null,c=!1;try{const n=(0,_e.Ww)({workspaceId:a,chatId:Fe.current,message:e,surface:He.qN.SHARED_DOCS,ragAudience:"visitor",conversationHistory:t,documents:I,sessionToken:et.current||null});(0,A.gg)("\ud83e\udd16 Streaming message to RAG system:",n);const o=()=>{null==at.current&&(at.current=requestAnimationFrame(()=>{at.current=null;const e=st.current;X(t=>{const n=t.slice(),r=n[n.length-1];return r&&"bot"===r.type&&r.streaming&&(n[n.length-1]=(0,u.A)((0,u.A)({},r),{},{content:e})),n})}))},d=await(0,Re.R)(n,{onDelta:e=>{r?st.current+=e:(c||(c=!0,oe(!1),X(e=>[...e,{type:"bot",content:"",timestamp:Date.now(),streaming:!0}])),st.current+=e,o())}},{signal:i.signal});if(null!=at.current&&(cancelAnimationFrame(at.current),at.current=null),l=d,d.liveSessionUserMessageOnly)c&&X(e=>{const t=e[e.length-1];return t&&"bot"===t.type&&t.streaming?e.slice(0,-1):e});else{let e="";if(e=d.content?d.content:d.message?d.message:d.response?d.response:d.answer?d.answer:"string"===typeof d?d:"I received your message but had trouble generating a response. Please try again.",r){const t=(0,Pe.JA)((0,Pe.fy)(s,"share"));e=(0,Pe.VL)(e,{agent:s,surface:"share",teamOnShift:t})}const t={type:"bot",content:e,timestamp:Date.now(),ragContext:d.ragContext||null};X(c?e=>{const n=e.slice(),r=n[n.length-1];return r&&"bot"===r.type&&r.streaming?n[n.length-1]=t:n.push(t),n}:e=>[...e,t])}we.current=e;if(!1!==s.leadCaptureEnabled&&!Ae.current){const e=d.leadCapture,t=s.liveRequestsEnabled&&(0,Pe.JA)((0,Pe.fy)(s,"share"));if(r&&t);else if(e&&e.leadCaptureSuggested){Ce.current=e.leadCaptureReason;const t="high_intent"===e.leadCaptureReason;setTimeout(()=>Ne(t?"softPrompt":"prompt"),600)}else d.noAnswer&&(Ce.current="no_answer",setTimeout(()=>Ne("prompt"),600))}d.sessionToken&&d.liveHandoff&&(et.current=d.sessionToken,tt.current="number"===typeof d.guestPollSinceIndex?d.guestPollSinceIndex:2,ut())}catch(m){if(m&&"AbortError"===m.name)return;console.error("Error sending message:",m);let e="Sorry about that \u2014 I'm having a little trouble right now. Please try again in a moment.";m.message&&m.message.includes("HTTP 400")&&(e="I didn't quite catch that \u2014 could you try rephrasing your question?");const t={type:"bot",content:e,timestamp:Date.now()};X(e=>{const n=e.slice(),r=n[n.length-1];return c&&r&&"bot"===r.type&&r.streaming?n[n.length-1]=t:n.push(t),n})}finally{null!=at.current&&(cancelAnimationFrame(at.current),at.current=null),ot.current===i&&(ot.current=null),oe(!1),s.liveRequestsEnabled&&l&&(r||l.noAnswer)&&(0,Pe.JA)((0,Pe.fy)(s,"share"))&&$e(!0)}},ct={default:{primary:"#3B82F6",secondary:"#F3F4F6"},dark:{primary:"#1F2937",secondary:"#374151"},green:{primary:"#10B981",secondary:"#ECFDF5"},purple:{primary:"#8B5CF6",secondary:"#F5F3FF"},orange:{primary:"#F59E0B",secondary:"#FFFBEB"}},dt=ct[s.theme]||ct.default;return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)("div",{style:(()=>{const e={position:"fixed",zIndex:1e3};switch(s.position){case"bottom-left":return(0,u.A)((0,u.A)({},e),{},{bottom:"20px",left:"20px"});case"top-right":return(0,u.A)((0,u.A)({},e),{},{top:"80px",right:"20px"});case"top-left":return(0,u.A)((0,u.A)({},e),{},{top:"80px",left:"20px"});default:return(0,u.A)((0,u.A)({},e),{},{bottom:"20px",right:"20px"})}})(),children:(0,H.jsxs)("button",{onClick:()=>{R||U("home"),P(!R)},className:"relative w-16 h-16 rounded-full shadow-lg hover:scale-105 transition-all duration-300 flex items-center justify-center",style:{backgroundColor:dt.primary},title:s.name,children:[(0,H.jsx)(w.A,{className:"w-8 h-8 text-white absolute transition-all duration-300 ".concat(R?"opacity-0 rotate-90 scale-0":"opacity-100 rotate-0 scale-100")}),(0,H.jsx)(d.A,{className:"w-8 h-8 text-white absolute transition-all duration-300 ".concat(R?"opacity-100 rotate-0 scale-100":"opacity-0 -rotate-90 scale-0")})]})}),(0,H.jsx)("div",{style:ie?{position:"fixed",inset:0,zIndex:1002,width:"100vw",height:"100vh"}:(()=>{var e,t;const n=null===(e=s.position)||void 0===e?void 0:e.includes("top"),r=null===(t=s.position)||void 0===t?void 0:t.includes("left"),o={small:{width:320,height:400},medium:{width:380,height:500},large:{width:450,height:600}},a=o[s.size]||o.medium,i=pe?{width:688,height:859}:a,l=i.width,c=i.height;return(0,u.A)((0,u.A)({},{position:"fixed",zIndex:1001,transition:"width 0.35s cubic-bezier(0.4,0,0.2,1), height 0.35s cubic-bezier(0.4,0,0.2,1)"}),{},{[n?"top":"bottom"]:n?"calc(var(--kb-header-h) + 60px + env(safe-area-inset-top))":"calc(90px + env(safe-area-inset-bottom))",[r?"left"
2:"right"]:"16px",width:"min(".concat(l,"px, calc(100vw - 32px))"),height:"min(".concat(c,"px, calc(100vh - var(--kb-header-h) - 120px))")})})(),className:"flex flex-col overflow-hidden will-change-transform transition-all duration-300 ease-out\n     ".concat(ie?"bg-white shadow-none border-0 rounded-none":"bg-white rounded-lg shadow-2xl border border-gray-200","\n     ").concat(R?"opacity-100 scale-100 translate-y-0 pointer-events-auto":"opacity-0 scale-95 translate-y-4 pointer-events-none"),children:"home"===M?(0,H.jsxs)("div",{className:"flex flex-col flex-1 bg-white",children:[(0,H.jsxs)("div",{className:"flex items-center justify-between px-5 pt-5 pb-2",children:[(0,H.jsx)("div",{className:"flex items-center",children:l?(0,H.jsx)("img",{src:l,alt:D,className:"h-8 max-w-[140px] object-contain",crossOrigin:"anonymous"}):(0,H.jsx)("div",{className:"h-8 w-8 rounded-md flex items-center justify-center text-white font-bold text-sm",style:{backgroundColor:dt.primary},children:(D||s.name||"?").charAt(0).toUpperCase()})}),(0,H.jsx)("button",{onClick:()=>P(!1),className:"text-gray-400 hover:text-gray-600 hover:bg-gray-100 rounded-full p-1.5 transition-colors",children:(0,H.jsx)(d.A,{className:"w-5 h-5"})})]}),(0,H.jsxs)("div",{className:"px-5 pt-6 pb-8",children:[(0,H.jsx)("p",{className:"text-gray-400 text-xl mb-1",children:"Hello there."}),(0,H.jsx)("p",{className:"text-gray-900 text-2xl font-semibold",children:"How can we help?"})]}),(0,H.jsx)("div",{className:"px-5",children:(0,H.jsxs)("button",{onClick:()=>U("chat"),className:"w-full text-left bg-gray-50 hover:bg-gray-100 border border-gray-200 rounded-xl px-4 py-4 flex items-center gap-3 transition-colors group",children:[(0,H.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,H.jsx)("p",{className:"text-gray-900 text-sm font-medium",children:"Ask a question"}),(0,H.jsx)("p",{className:"text-gray-500 text-xs mt-0.5",children:"AI Agent and team can help"})]}),(0,H.jsxs)("div",{className:"flex items-center gap-2 shrink-0",children:[l?(0,H.jsx)("img",{src:l,alt:"",className:"h-6 w-6 rounded object-contain",crossOrigin:"anonymous"}):(0,H.jsx)("div",{className:"h-6 w-6 rounded flex items-center justify-center text-white text-xs font-bold",style:{backgroundColor:dt.primary},children:(D||s.name||"?").charAt(0).toUpperCase()}),(0,H.jsx)(c.A,{className:"w-4 h-4 text-gray-400 group-hover:text-gray-600 transition-colors"})]})]})}),s.showKnowledgeBaseContent&&v.length>0&&(0,H.jsx)("div",{className:"flex-1 overflow-y-auto px-5 pt-4 pb-2 space-y-3",children:v.map(e=>{var t,n;return(0,H.jsxs)("button",{onClick:()=>{W(e),U("document")},className:"w-full text-left bg-white border border-gray-200 rounded-xl overflow-hidden hover:border-gray-300 hover:shadow-sm transition-all group",children:[e.coverImageUrl&&(0,H.jsx)("div",{className:"w-full h-32 overflow-hidden",children:(0,H.jsx)(qe.D,{src:(0,Ue.a)(e.coverImageUrl,{width:480}),className:"w-full h-full object-cover group-hover:scale-105 transition-transform duration-300",style:(0,Me.jR)(e.coverImagePosition)})}),(0,H.jsxs)("div",{className:"px-4 py-3",children:[(0,H.jsx)("p",{className:"text-gray-900 text-sm font-semibold line-clamp-2 leading-snug",children:(0,Ve.Od)(e,"Untitled")}),((null===(t=e.info)||void 0===t?void 0:t.category)||e.category)&&(0,H.jsx)("p",{className:"text-gray-400 text-xs mt-1.5 truncate",children:(null===(n=e.info)||void 0===n?void 0:n.category)||e.category})]})]},e.id)})}),(!s.showKnowledgeBaseContent||0===v.length)&&(0,H.jsx)("div",{className:"flex-1"}),s.branding&&(0,Se.BP)()&&(0,H.jsxs)("div",{className:"px-5 py-3 text-center text-xs text-gray-400",children:["Powered by ",(0,H.jsx)("a",{href:"https://trybased.com",target:"_blank",rel:"noopener noreferrer",className:"text-blue-500 hover:text-blue-600 hover:underline",children:"Based"})]})]}):"document"===M&&_?(0,H.jsxs)("div",{className:"flex flex-col flex-1 bg-white",children:[(0,H.jsxs)("div",{className:"px-4 py-3 bg-white border-b border-gray-200 flex items-center gap-3",children:[(0,H.jsx)("button",{onClick:()=>{U("home"),W(null)},className:"text-gray-400 hover:text-gray-600 hover:bg-gray-100 rounded p-1 transition-colors shrink-0",children:(0,H.jsx)(m.A,{className:"w-4 h-4"})}),(0,H.jsx)("p",{className:"text-sm font-medium text-gray-900 truncate flex-1",children:_.title||_.fileName||"Document"}),(0,H.jsx)("button",{onClick:()=>P(!1),className:"text-gray-400 hover:text-gray-600 hover:bg-gray-100 rounded-full p-1 transition-colors shrink-0",children:(0,H.jsx)(d.A,{className:"w-4 h-4"})})]}),(0,H.jsxs)("div",{className:"flex-1 overflow-y-auto",children:[_.coverImageUrl&&(0,H.jsx)(qe.D,{src:_.coverImageUrl,className:"w-full h-48 object-cover",style:(0,Me.Hw)(_.coverImagePosition),loading:"eager"}),(0,H.jsxs)("div",{className:"px-5 py-4",children:[((null===(t=_.info)||void 0===t?void 0:t.category)||_.category)&&(0,H.jsx)("span",{className:"inline-block text-xs font-medium px-2 py-0.5 rounded-full bg-gray-100 text-gray-600 mb-3",children:(null===(n=_.info)||void 0===n?void 0:n.category)||_.category}),(e=>{const t=(_.title||_.fileName||"").trim();return(null===(e=_.editorHtml)||void 0===e?void 0:e.trim())&&Te(_.editorHtml,t)?null:(0,H.jsx)("h2",{className:"text-lg font-bold text-gray-900 mb-4 leading-snug",children:_.title||_.fileName||"Untitled"})})(),(0,H.jsx)("div",{className:"prose prose-sm max-w-none text-gray-700 text-sm leading-relaxed",children:_.editorHtml?(0,H.jsx)("div",{dangerouslySetInnerHTML:{__html:_.editorHtml}}):_.formattedContent?(0,H.jsx)("div",{dangerouslySetInnerHTML:{__html:(0,C.c)(_.formattedContent)}}):_.textContent&&"[Encrypted Content]"!==_.textContent?(0,H.jsx)("div",{className:"whitespace-pre-wrap",children:_.textContent}):(0,H.jsx)("p",{className:"text-gray-400 italic",children:"No content available."})})]})]}),s.branding&&(0,Se.BP)()&&(0,H.jsxs)("div",{className:"px-5 py-3 text-center text-xs text-gray-400 border-t border-gray-100",children:["Powered by ",(0,H.jsx)("a",{href:"https://trybased.com",target:"_blank",rel:"noopener noreferrer",className:"text-blue-500 hover:text-blue-600 hover:underline",children:"Based"})]})]}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)("div",{className:"px-4 py-3 bg-white border-b border-gray-200 flex items-center gap-3 relative",children:[(0,H.jsx)("button",{onClick:()=>U("home"),className:"text-gray-400 hover:text-gray-600 hover:bg-gray-100 rounded p-1 transition-colors shrink-0",children:(0,H.jsx)(m.A,{className:"w-4 h-4"})}),l?(0,H.jsx)("img",{src:l,alt:D,className:"h-7 max-w-[100px] object-contain",crossOrigin:"anonymous"}):(0,H.jsx)("div",{className:"h-7 w-7 rounded-md flex items-center justify-center text-white font-bold text-xs",style:{backgroundColor:dt.primary},children:(D||s.name||"?").charAt(0).toUpperCase()}),(0,H.jsx)("div",{className:"flex-1 min-w-0",children:(0,H.jsx)("h3",{className:"font-semibold text-sm text-gray-900",children:s.name})}),!ie&&(0,H.jsxs)("div",{className:"relative",ref:be,children:[(0,H.jsx)("button",{onClick:()=>me(e=>!e),className:"text-gray-400 hover:text-gray-600 hover:bg-gray-100 rounded-full p-1.5 transition-colors shrink-0",children:(0,H.jsx)(g.A,{className:"w-5 h-5"})}),de&&(0,H.jsx)("div",{className:"absolute right-0 top-full mt-1 bg-white border border-gray-200 rounded-lg shadow-lg py-1 z-50 min-w-[160px]",children:(0,H.jsxs)("button",{onClick:()=>{fe(e=>!e),me(!1)},className:"w-full text-left px-3 py-2 text-sm text-gray-700 hover:bg-gray-50 flex items-center gap-2 transition-colors",children:[pe?(0,H.jsx)(h.A,{className:"w-4 h-4"}):(0,H.jsx)(p.A,{className:"w-4 h-4"}),pe?"Shrink window":"Expand window"]})})]}),(0,H.jsx)("button",{onClick:()=>P(!1),className:"text-gray-400 hover:text-gray-600 hover:bg-gray-100 rounded-full p-1.5 transition-colors shrink-0",children:(0,H.jsx)(d.A,{className:"w-5 h-5"})})]}),(0,H.jsxs)("div",{ref:rt,className:"flex-1 min-h-0 overflow-y-auto p-4 space-y-3 bg-gray-50",children:[!ye&&G.length>0&&"bot"===G[0].type&&(0,H.jsx)("div",{className:"flex justify-start",children:(0,H.jsx)("div",{className:"bg-white border border-gray-200 px-3 py-2 rounded-lg",children:(0,H.jsxs)("div",{className:"flex space-x-1",children:[(0,H.jsx)("div",{className:"w-2 h-2 bg-gray-400 rounded-full animate-bounce"}),(0,H.jsx)("div",{className:"w-2 h-2 bg-gray-400 rounded-full animate-bounce",style:{animationDelay:"0.1s"}}),(0,H.jsx)("div",{className:"w-2 h-2 bg-gray-400 rounded-full animate-bounce",style:{animationDelay:"0.2s"}})]})})}),G.map((e,t)=>{var n,r,o,a;const i=0===t&&"bot"===e.type;if(i&&!ye)return null;const u="user"===e.type,l="human"===e.type;return(0,H.jsx)("div",{className:"flex ".concat(u?"justify-end":"justify-start"),children:(0,H.jsxs)("div",{className:"bot"===e.type||l?"max-w-xs lg:max-w-md":"",children:[l&&(0,H.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[e.photoURL?(0,H.jsx)("img",{src:e.photoURL,alt:"",className:"w-7 h-7 rounded-full object-cover border border-emerald-200 shrink-0"}):null,(0,H.jsx)("p",{className:"text-xs font-semibold text-emerald-800",children:e.senderName||"Team"})]}),(0,H.jsx)("div",{className:"px-3 py-2 rounded-lg text-sm ".concat(u?"text-white max-w-xs lg:max-w-md":l?"bg-emerald-50 text-emerald-900 border border-emerald-200 max-w-xs lg:max-w-md":"bg-white text-gray-800 border border-gray-200").concat(i&&ye?" animate-fadeIn":""),style:u?{backgroundColor:dt.primary}:{},children:"bot"===e.type?(0,H.jsx)("div",{className:"prose prose-sm max-w-none text-gray-800 [&_a]:text-blue-600",dangerouslySetInnerHTML:{__html:(0,C.c)(e.content,{viewerDocuments:null===(n=e.ragContext)||void 0===n?void 0:n.viewerDocuments,shareLinkId:k,viewerBaseOrigin:N})}}):e.content}),"bot"===e.type&&(null!==(r=null===(o=e.ragContext)||void 0===o||null===(a=o.pdfSources)||void 0===a?void 0:a.length)&&void 0!==r?r:0)>0&&(0,H.jsx)(Ke.E,{pdfSources:e.ragContext.pdfSources,shareLinkId:k,viewerBaseOrigin:N,className:"mt-2",onOpenSharedPdfDocument:B}),"bot"===e.type&&(0,H.jsxs)("p",{className:"text-xs text-gray-400 mt-1 ml-1",children:[s.name," \xb7 AI Agent \xb7 Just now"]})]})},t)}),"prompt"===je&&(0,H.jsx)("div",{className:"flex justify-start",children:(0,H.jsxs)("div",{className:"bg-white border border-gray-200 rounded-lg px-3 py-2 text-sm text-gray-700 max-w-xs lg:max-w-md 
2space-y-2",children:[(0,H.jsx)("p",{children:"Want someone from the team to follow up? Share your contact details here."}),(0,H.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,H.jsx)("button",{type:"button",onClick:()=>{Ae.current=!0,Ne("form")},className:"px-4 py-1.5 rounded-lg text-white text-sm font-medium",style:{backgroundColor:dt.primary},children:"Yes, please"}),(0,H.jsx)("button",{type:"button",onClick:()=>{Ae.current=!0,Ne(null)},className:"px-4 py-1.5 rounded-lg text-sm font-medium border border-gray-200 bg-gray-50 text-gray-700 hover:bg-gray-100",children:"No thanks"})]})]})}),"softPrompt"===je&&(0,H.jsx)("div",{className:"flex justify-start",children:(0,H.jsxs)("div",{className:"bg-blue-50 border border-blue-100 rounded-lg px-3 py-2 text-sm text-gray-700 max-w-xs lg:max-w-md space-y-2",children:[(0,H.jsx)("p",{children:"If you'd like, I can have someone from the team follow up about this."}),(0,H.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,H.jsx)("button",{type:"button",onClick:()=>{Ae.current=!0,Ne("form")},className:"px-4 py-1.5 rounded-lg text-white text-sm font-medium",style:{backgroundColor:dt.primary},children:"Sure, share my details"}),(0,H.jsx)("button",{type:"button",onClick:()=>{Ne(null)},className:"px-4 py-1.5 rounded-lg text-sm font-medium border border-gray-200 bg-gray-50 text-gray-700 hover:bg-gray-100",children:"No thanks"})]})]})}),"form"===je&&(0,H.jsx)("div",{className:"flex justify-start",children:(0,H.jsxs)("div",{className:"bg-white border border-gray-200 rounded-lg px-3 py-3 text-sm text-gray-700 max-w-xs lg:max-w-md w-full space-y-2",children:[(0,H.jsx)("p",{className:"text-gray-700",children:"Add your details below and we'll reach out."}),(0,H.jsx)("input",{type:"text",value:Oe.name,onChange:e=>ze(t=>(0,u.A)((0,u.A)({},t),{},{name:e.target.value})),placeholder:"Your name",className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm"}),(0,H.jsx)("input",{type:"email",value:Oe.email,onChange:e=>ze(t=>(0,u.A)((0,u.A)({},t),{},{email:e.target.value})),placeholder:"Email address",className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm"}),(0,H.jsx)("input",{type:"tel",value:Oe.phone,onChange:e=>ze(t=>(0,u.A)((0,u.A)({},t),{},{phone:e.target.value})),placeholder:"Phone number",className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm"}),(0,H.jsx)("button",{type:"button",disabled:Ye,onClick:async()=>{const e=Oe.email.trim(),t=Oe.phone.trim();if(e||t){Ge(!0);try{if(!(await fetch("https://us-central1-aiknowledgebase-7427e.cloudfunctions.net/submitChatContactInfo",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({data:{workspaceId:a,chatId:Fe.current,name:Oe.name.trim(),email:e,phone:t,question:we.current,leadCaptureReason:Ce.current||"no_answer"}})})).ok)throw new Error("Request failed");Ne("submitted"),ze({name:"",email:"",phone:""})}catch(n){console.error(n),Y.Ay.error("Something went wrong. Please try again.")}finally{Ge(!1)}}else Y.Ay.error("Please provide at least an email or phone number.")},className:"w-full mt-1 py-2 rounded-lg text-white text-sm font-medium disabled:opacity-50",style:{backgroundColor:dt.primary},children:Ye?"Submitting\u2026":"Submit"})]})}),"submitted"===je&&(0,H.jsx)("div",{className:"flex justify-start",children:(0,H.jsx)("div",{className:"bg-green-50 border border-green-200 rounded-lg px-3 py-2 text-sm text-green-800 max-w-xs lg:max-w-md",children:"Thanks! Someone from our team will be in touch shortly."})}),re&&(0,H.jsx)("div",{className:"flex justify-start",children:(0,H.jsx)("div",{className:"bg-white border border-gray-200 px-3 py-2 rounded-lg",children:(0,H.jsxs)("div",{className:"flex space-x-1",children:[(0,H.jsx)("div",{className:"w-2 h-2 bg-gray-400 rounded-full animate-bounce"}),(0,H.jsx)("div",{className:"w-2 h-2 bg-gray-400 rounded-full animate-bounce",style:{animationDelay:"0.1s"}}),(0,H.jsx)("div",{className:"w-2 h-2 bg-gray-400 rounded-full animate-bounce",style:{animationDelay:"0.2s"}})]})})})]}),s.liveRequestsEnabled&&Ze&&!G.some(e=>"human"===e.type)&&(0,Pe.JA)((0,Pe.fy)(s,"share"))&&(0,H.jsx)("div",{className:"px-4 pt-2 pb-1 bg-gray-50 border-t border-gray-100",children:(0,H.jsx)("button",{type:"button",onClick:async()=>
2{if(re)return;const e={type:"user",content:"Speak to our team",timestamp:Date.now()},t=[...G,e];X(t),oe(!0);const n=t.filter(e=>"user"===e.type||"bot"===e.type).map(e=>({role:"user"===e.type?"user":"assistant",content:e.content}));try{const e=(0,_e.Ww)({workspaceId:a,chatId:Fe.current,message:"[LIVE_HANDOFF]",surface:He.qN.SHARED_DOCS,ragAudience:"visitor",conversationHistory:n,documents:I,extras:(0,u.A)({requestLiveHandoff:!0,liveHandoffSurface:"share"},k&&"string"===typeof k&&k.trim()?{shareLinkId:k.trim()}:{})}),t=await fetch((0,Le.CN)(),{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(e)});if(!t.ok)throw new Error("HTTP ".concat(t.status));const r=await t.json(),o=r.result||r.data||r;let s=o.content||o.message||o.response||o.answer||"";X(e=>[...e,{type:"bot",content:s,timestamp:Date.now()}]),o.sessionToken&&o.liveHandoff&&(et.current=o.sessionToken,tt.current="number"===typeof o.guestPollSinceIndex?o.guestPollSinceIndex:2,ut())}catch(r){console.error(r),X(e=>[...e,{type:"bot",content:"Could not connect you to the team. Please try again.",timestamp:Date.now()}])}finally{oe(!1)}},disabled:re,className:"w-full py-2.5 rounded-full border border-gray-200 bg-white text-sm font-semibold text-gray-900 shadow-sm hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:s.liveRequestCapsuleLabel||"Speak to our team"})}),(0,H.jsx)("div",{className:"px-4 py-3 border-t border-gray-200 bg-white",children:(0,H.jsxs)("div",{className:"relative border border-gray-300 rounded-2xl focus-within:ring-2 focus-within:ring-opacity-50 transition-shadow",style:{"--tw-ring-color":dt.primary},children:[(0,H.jsx)("textarea",{value:$,onChange:e=>ee(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),lt())},placeholder:s.placeholder,rows:1,className:"w-full resize-none bg-transparent px-4 py-3 pr-12 text-sm focus:outline-none",disabled:re}),(0,H.jsx)("button",{onClick:lt,disabled:!$.trim()||re,className:"absolute right-2.5 top-1/2 -translate-y-1/2 w-8 h-8 shrink-0 flex items-center justify-center text-white rounded-full disabled:opacity-50 disabled:cursor-not-allowed hover:opacity-90 transition-opacity",style:{backgroundColor:dt.primary},children:(0,H.jsx)(f.A,{className:"w-4 h-4"})})]})}),s.branding&&(0,Se.BP)()&&(0,H.jsxs)("div",{className:"px-4 py-2 text-center text-xs text-gray-500 bg-gray-50 border-t border-gray-200",children:["Powered by ",(0,H.jsx)("a",{href:"https://trybased.com",target:"_blank",rel:"noopener noreferrer",className:"text-blue-500 hover:underline",children:"Based"})]})]})})]})},$e=e=>{let t=e.json,n=e.documentId,a=e.linkId,s=e.paymentRevealAfterSignature,l=void 0!==s&&s,c=e.paymentEnabled,d=void 0!==c&&c,m=e.paymentAmountCents,g=void 0===m?null:m,h=e.formWizardMode,p=void 0===h?"auto":h,f=e.hideTimeEntryTimestamps,x=void 0!==f&&f;const D=o.useRef(null),y=o.useRef(new Set),v=o.useRef(null),b=o.useRef(!1),F=o.useState(!1),w=(0,r.A)(F,2),C=w[0],E=w[1],k=o.useState(!1),j=(0,r.A)(k,2),N=j[0],S=j[1],B=o.useState(!1),I=(0,r.A)(B,2),T=I[0],L=I[1],R=o.useState(me),P=(0,r.A)(R,2),O=P[0],z=P[1],M=o.useState(!1),U=(0,r.A)(M,2),q=U[0],V=U[1],_=o.useState([]),W=(0,r.A)(_,2),K=W[0],J=W[1],X=o.use
2State(null),Q=(0,r.A)(X,2),Z=Q[0],$=Q[1],ee=o.useMemo(()=>"undefined"!==typeof window&&"success"===new URLSearchParams(window.location.search).get("payment"),[])||q,te=o.useMemo(()=>{if(!t)return null;try{return"string"===typeof t?JSON.parse(t):t}catch(e){return null}},[t]),ne=o.useMemo(()=>te?Ne(te):[],[te]),re=o.useMemo(()=>!!te&&(0,Ee.Mp)(te,p),[te,p]),oe=o.useMemo(()=>{if(!te)return!1;try{var e;const t=(0,ze.HQ)(te).signatureBlocks;return(null!==(e=null===t||void 0===t?void 0:t.length)&&void 0!==e?e:0)>0}catch(t){return!1}},[te]),ae=o.useMemo(()=>{if(!te)return!1;if(d||l)return!0;const e=t=>!(!t||"object"!==typeof t)&&("paymentButton"===t.type||!!Array.isArray(t.content)&&t.content.some(e));return e(te)},[te,d,l]),se=o.useMemo(()=>te?re&&O===ge?Ce(te):te:null,[te,re,O]),ie=!re||O===ge;o.useEffect(()=>{if(!re||!a||!n||b.current)return;b.current=!0;const e=xe(a,n),t=function(e){let t=e.paymentComplete,n=e.hasPaymentStep,r=e.restored;return t&&n?{phase:pe,wizardSubmitted:!0,signingComplete:!(null===r||void 0===r||!r.signingComplete)}:null!==r&&void 0!==r&&r.wizardSubmitted&&r.phase?{phase:r.phase,wizardSubmitted:!0,signingComplete:!!r.signingComplete}:{phase:me,wizardSubmitted:!1,signingComplete:!1}}({paymentComplete:ee,hasPaymentStep:ae,restored:e});t.wizardSubmitted&&(L(!0),z(t.phase),t.signingComplete&&(E(!0),y.current.add(n)),null!==e&&void 0!==e&&e.submissionId&&(v.current=e.submissionId,$(e.submissionId))),ee&&ae&&function(e,t){if("undefined"!==typeof window&&e&&t)try{window.sessionStorage.removeItem(fe(e,t))}catch(n){}}(a,n)},[re,a,n,ee,ae]),o.useEffect(()=>{const e=Z||v.current;if(!n||!e)return;let t=!1;return(async()=>{try{var r,o;const a=(0,i.getFunctions)(),s=(0,i.httpsCallable)(a,"getSharedSubmissionPaymentStatus"),u=await s({documentId:n,submissionId:e});if(t)return;null!==u&&void 0!==u&&null!==(r=u.data)&&void 0!==r&&r.paymentCompletedAt&&V(!0),Array.isArray(null===u||void 0===u||null===(o=u.data)||void 0===o?void 0:o.paidLinkIds)&&J(u.data.paidLinkIds)}catch(a){(0,A.gg)("[payment status] fetch failed",a)}})(),()=>{t=!0}},[n,Z]),o.useEffect(()=>{if(!n)return;let e=!1;return(async()=>{try{var t;const r=(0,i.getFunctions)(),o=(0,i.httpsCallable)(r,"getSharedDocumentPaymentStatus"),a=await o({documentId:n});if(e)return;const s=null===a||void 0===a||null===(t=a.data)||void 0===t?void 0:t.paidLinkIds;Array.isArray(s)&&s.length&&J(e=>Array.from(new Set([...e||[],...s])))}catch(r){(0,A.gg)("[document payment status] fetch failed",r)}})(),()=>{e=!0}},[n]),o.useEffect(()=>{if(!C||!re||!T||O!==ge||!a||!n)return;const e={hasPaymentStep:ae}.hasPaymentStep?he:pe;z(e),De(a,n,{wizardSubmitted:!0,phase:e,signingComplete:!0,submissionId:v.current})},[C,re,T,O,ae,a,n]),o.useEffect(()=>{if(!ie)return;if(!D.current||!a||!n)return;const e=D.current;let t=new Map;try{const e=se;if(e&&"object"===typeof e&&Array.isArray(e.content)){const n=(0,ze.HQ)(e).signatureBlocks;t=new Map(n.map(e=>[e.id,e]))}}catch(c){}let r=0;let o=null;const s=()=>{const t=e.querySelectorAll("[data-signature-block-id]:not([data-shared-signing-rendered])");0!==t.length?l(t):r<8&&(r++,o=setTimeout(s,r<=2?100:300))},l=r=>{const o='"Brush Script MT", "Segoe Script", "Apple Chancery", "Snell Roundhand", cursive',s=y.current.has(n);r.forEach(r=>{if(r.getAttribute("data-shared-signing-rendered"))return;r.setAttribute("data-shared-signing-rendered","true");const l=r.getAttribute("data-signature-block-id"),c=l?t.get(l):null,d=null===c||void 0===c?void 0:c.defaultSignature,m=null!=d&&""!==String(d).trim()?String(d):r.getAttribute("data-default-signature")||"";if(r.innerHTML="",r.style.cssText="margin:1rem 0;padding:1.5rem;border:1px solid #e2e8f0;border-radius:10px;background:linear-gradient(135deg,#f8fafc 0%,#f1f5f9 100%)",s)return void(r.innerHTML='\n          <div style="text-align:center;padding:2rem 1rem;">\n            <div style="width:48px;height:48px;background:#dcfce7;border-radius:50%;display:inline-flex;align-items:center;justify-content:center;margin-bottom:1rem;">\n              <svg width="24" height="24" fill="none" stroke="#16a34a" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>\n            </div>\n            <h3 style="margin:0 0 0.5rem;font-size:1.1rem;font-weight:600;color:#111827;">Signature submitted</h3>\n            <p style="margin:0;color:#6b7280;font-size:0.875rem;">Check your email for your signed copy.</p>\n          </div>');if(m){const e=null!=(null===c||void 0===c?void 0:c.defaultSignerName)&&""!==c.defaultSignerName?c.defaultSignerName:r.getAttribute("data-default-signer-name")||"",t=null!=(null===c||void 0===c?void 0:c.defaultSignerEmail)&&""!==c.defaultSignerEmail?c.defaultSignerEmail:r.getAttribute("data-default-signer-email")||"",n=null!=(null===c||void 0===c?void 0:c.defaultSignedAt)&&""!==c.defaultSignedAt?c.defaultSignedAt:r.getAttribute("data-default-signed-at")||"",a=document.createElement("div");if(a.style.cssText="padding:0.5rem 0",m.startsWith("data:")){const e=document.createElement("img");e.src=m,e.alt="Signature",e.style.cssText="max-height:60px;
2max-width:200px",a.appendChild(e)}else{const e=document.createElement("span");e.textContent=m,e.style.cssText="font-family:".concat(o,";font-size:1.35rem;color:#111827"),a.appendChild(e)}if(e||t||n){const r=document.createElement("div");r.style.cssText="font-size:11px;color:#6b7280;margin-top:4px";const o=()=>r.appendChild(document.createTextNode(" \xb7 "));if(e&&r.appendChild(document.createTextNode(e)),t){e&&o();const n=document.createElement("a");n.href="mailto:".concat(t),n.textContent=t,n.style.cssText="color:#2563eb;text-decoration:underline",r.appendChild(n)}if(n){let a;(e||t)&&o();try{a="Signed on ".concat(new Date(n).toLocaleString(void 0,{dateStyle:"medium",timeStyle:"short"}))}catch(j){a="Signed on ".concat(n)}r.appendChild(document.createTextNode(a))}a.appendChild(r)}return void r.appendChild(a)}const g=document.createElement("div");g.setAttribute("data-sig-widget",l);let h="",p="",f=!1,x="type",D="",b="",F=!1,w=!1,A=!1,C=!1;const k=()=>{g.innerHTML="";const t=document.createElement("p");t.textContent="Sign this document",t.style.cssText="margin:0 0 1rem;font-size:1.1rem;font-weight:600;color:#1e293b",g.appendChild(t);const r=document.createElement("div");r.style.cssText="display:flex;flex-direction:column;gap:0.75rem";const s="width:100%;padding:0.5rem 0.75rem;border:1px solid #d1d5db;border-radius:6px;font-size:0.875rem;outline:none;box-sizing:border-box;background:#fff",l=document.createElement("label");l.textContent="Full legal name *",l.style.cssText="font-size:0.8rem;font-weight:500;color:#374151;margin-bottom:0.15rem",r.appendChild(l);const c=document.createElement("input");c.type="text",c.value=h,c.placeholder="Your full legal name",c.style.cssText=s,c.addEventListener("input",e=>{h=e.target.value}),r.appendChild(c);const d=document.createElement("label");d.textContent="Email address *",d.style.cssText="font-size:0.8rem;font-weight:500;color:#374151;margin-bottom:0.15rem",r.appendChild(d);const m=document.createElement("input");m.type="email",m.value=p,m.placeholder="[email protected]",m.style.cssText=s,m.addEventListener("input",e=>{p=e.target.value}),r.appendChild(m);const j=document.createElement("div");if(j.style.cssText="display:flex;gap:0.5rem;margin-top:0.25rem",["type","draw"].forEach(e=>{const t=document.createElement("button");t.type="button",t.textContent="type"===e?"Type name":"Draw",t.style.cssText="padding:0.25rem 0.75rem;font-size:0.8rem;border-radius:4px;border:none;cursor:pointer;".concat(x===e?"background:#dbeafe;color:#1e40af;font-weight:500":"background:#f3f4f6;color:#374151"),t.addEventListener("click",()=>{x=e,k()}),j.appendChild(t)}),r.appendChild(j),"type"===x){const e=document.createElement("input");e.type="text",e.value=D,e.placeholder="Type your signature",e.style.cssText=s+";font-family:".concat(o,";font-size:1.35rem;"),e.addEventListener("input",e=>{D=e.target.value}),r.appendChild(e)}else{const e=document.createElement("div");e.style.cssText="position:relative";const t=document.createElement("canvas");if(t.width=400,t.height=120,t.style.cssText="border:1px solid #d1d5db;border-radius:6px;width:100%;max-width:400px;cursor:crosshair;touch-action:none;user-select:none;-webkit-user-select:none;background:#fff",t.setAttribute("draggable","false"),b){const e=new Image;e.onload=()=>{const n=t.getContext("2d");n.clearRect(0,0,t.width,t.height),n.drawImage(e,0,0,t.width,t.height),w=!0},e.src=b}const n=e=>{const n=t.getBoundingClientRect(),r=t.width/n.width,o=t.height/n.height;return{x:(e.clientX-n.left)*r,y:(e.clientY-n.top)*o}},o=e=>{F=!0;const r=t.getContext("2d");r.strokeStyle="#111827",r.lineWidth=2,r.lineCap="round",r.lineJoin="round",r.beginPath();const o=n(e);r.moveTo(o.x,o.y)},a=e=>{if(!F)return;const r=t.getContext("2d"),o=n(e);r.lineTo(o.x,o.y),r.stroke(),w=!0},s=()=>{F&&(F=!1,w&&(b=t.toDataURL("image/png")))};t.addEventListener("mousedown",e=>{e.preventDefault(),o(e)}),t.addEventListener("mousemove",e=>{F&&e.preventDefault(),a(e)}),t.addEventListener("mouseup",s),t.addEventListener("mouseleave",s),t.addEventListener("touchstart",e=>{e.preventDefault();const t=e.touches[0];t&&o({clientX:t.clientX,clientY:t.clientY})},{passive:!1}),t.addEventListener("touchmove",e=>{e.preventDefault();const t=e.touches[0];t&&a({clientX:t.clientX,clientY:t.clientY})},{passive:!1}),t.addEventListener("touchend",e=>{e.preventDefault(),s()}),e.appendChild(t);const i=document.createElement("button");i.type="button",i.textContent="Clear",i.style.cssText="margin-top:0.35rem;font-size:0.8rem;color:#6b7280;background:none;border:none;cursor:pointer",i.addEventListener("click",()=>{t.getContext("2d").clearRect(0,0,t.width,t.height),w=!1,b=""}),e.appendChild(i),r.appendChild(e)}const N=document.createElement("div");N.style.cssText="display:flex;flex-direction:column;gap:0.35rem;margin-top:0.25rem";
2const S=p?(0,Oe.VP)({uid:null,signerEmail:p}):null,B=S?(0,Oe.sM)(S):null,I="type"===x?D.trim():b;if(B&&!I){const e=document.createElement("button");e.type="button",e.textContent="Use saved signature",e.style.cssText="background:none;border:none;color:#2563eb;font-size:0.8rem;font-weight:500;cursor:pointer;text-align:left;padding:0",e.addEventListener("click",()=>{"draw"===B.mode&&B.value.startsWith("data:")?(b=B.value,x="draw",w=!0):(D=B.value,x="type"),k()}),N.appendChild(e)}if(I){const e=document.createElement("label");e.style.cssText="display:flex;align-items:center;gap:0.4rem;font-size:0.8rem;color:#374151;cursor:pointer";const t=document.createElement("input");t.type="checkbox",t.checked=C,t.style.cssText="flex-shrink:0",t.addEventListener("change",e=>{C=e.target.checked}),e.appendChild(t);const n=document.createElement("span");n.textContent="Save signature for future use",e.appendChild(n),N.appendChild(e)}N.childNodes.length>0&&r.appendChild(N);const T=document.createElement("label");T.style.cssText="display:flex;align-items:flex-start;gap:0.5rem;font-size:0.8rem;color:#374151;cursor:pointer;margin-top:0.25rem";const L=document.createElement("input");L.type="checkbox",L.checked=f,L.style.cssText="margin-top:2px;flex-shrink:0",L.addEventListener("change",e=>{f=e.target.checked}),T.appendChild(L);const R=document.createElement("span");R.textContent=Ye.Z,T.appendChild(R),r.appendChild(T);const P=document.createElement("div");P.style.cssText="color:#dc2626;font-size:0.8rem;min-height:1.2em",r.appendChild(P);const O=document.createElement("button");O.type="button",O.textContent=A?"Submitting...":"Submit Signature",O.disabled=A,O.style.cssText="margin-top:0.25rem;padding:0.6rem 1.25rem;background:".concat(A?"#9ca3af":"#16a34a",";color:#fff;border:none;border-radius:6px;font-size:0.875rem;font-weight:500;cursor:").concat(A?"not-allowed":"pointer",";align-self:flex-start"),O.addEventListener("click",async()=>{if(P.textContent="",!h.trim())return void(P.textContent="Full legal name is required.");if(!/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(p))return void(P.textContent="Please enter a valid email address.");const t="type"===x?D.trim():b;if(!t)return void(P.textContent="Please provide your signature.");if(!f)return void(P.textContent="You must accept the consent checkbox.");A=!0,k();const r=e.querySelectorAll("[data-signature-block-id][data-shared-signing-rendered]"),o={};r.forEach(e=>{const n=e.getAttribute("data-signature-block-id");e.querySelector('[data-sig-widget="'.concat(n,'"]'))&&(o[n]=t)});try{var s;const e=(0,i.getFunctions)(),l=(0,i.httpsCallable)(e,"submitSharedSignatureSubmission"),c=xe(a,n),d=null!==c&&void 0!==c&&c.inlineFormResponseIds?Object.values(c.inlineFormResponseIds):[],m=await l((0,u.A)((0,u.A)({linkId:a,documentId:n,signatures:o,fullName:h.trim(),signerEmail:p.trim(),consentAccepted:!0,signerTimeZone:Intl.DateTimeFormat().resolvedOptions().timeZone},null!==c&&void 0!==c&&c.responseId?{formResponseId:c.responseId}:{}),d.length>0?{formResponseIds:d}:{}));if(null!==m&&void 0!==m&&null!==(s=m.data)&&void 0!==s&&s.submissionId&&(v.current=m.data.submissionId,$(m.data.submissionId)),y.current.add(n),E(!0),C&&p){const e=(0,Oe.VP)({uid:null,signerEmail:p.trim()});e&&(0,Oe.zI)(e,{mode:x,value:t})}r.forEach(e=>{e.innerHTML='\n                <div style="text-align:center;padding:2rem 1rem;">\n                  <div style="width:48px;height:48px;background:#dcfce7;border-radius:50%;display:inline-flex;align-items:center;justify-content:center;margin-bottom:1rem;">\n                    <svg width="24" height="24" fill="none" stroke="#16a34a" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>\n                  </div>\n                  <h3 style="margin:0 0 0.5rem;font-size:1.1rem;font-weight:600;color:#111827;">Signature submitted</h3>\n                  <p style="margin:0;color:#6b7280;font-size:0.875rem;">Check your email for your signed copy.</p>\n                </div>'})}catch(l){A=!1;const e=null===l||void 0===l?void 0:l.message,t=!e||"INTERNAL"===e||"INTERNAL"===String(e).toUpperCase();P.textContent=t?"Submission failed. Please try again.":e,k()}}),r.appendChild(O),g.appendChild(r)};k(),r.appendChild(g)})};return s(),()=>{o&&clearTimeout(o),e&&e.querySelectorAll("[data-signature-block-id][data-shared-signing-rendered]").forEach(e
2=>e.removeAttribute("data-shared-signing-rendered"))}},[se,a,n,ie]);const ue=o.useCallback(async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(!a||!n)return;S(!0);const t=window.location.origin,r="".concat(t,"/shared/").concat(a,"?payment=success"),o="".concat(t,"/shared/").concat(a);(0,A.gg)("[pay button] runPayment",{documentId:n,successUrl:r,cancelUrl:o});const s=window.open("about:blank","_blank");if(s)try{s.document.open(),s.document.write('\n      <!DOCTYPE html><html><head><meta charset="utf-8"><title>Redirecting...</title>\n      <style>body{margin:0;display:flex;align-items:center;justify-content:center;min-height:100vh;font-family:system-ui,sans-serif;background:#f9fafb}\n      .box{text-align:center;padding:1.5rem}.spinner{width:28px;height:28px;margin:0 auto 1rem;border:3px solid #e5e7eb;border-top-color:#2563eb;border-radius:50%;animation:spin .7s linear infinite}\n      @keyframes spin{to{transform:rotate(360deg)}}p{margin:0;color:#374151}.sub{color:#6b7280;font-size:.875rem;margin-top:.25rem}</style></head>\n      <body><div class="box"><div class="spinner"></div><p>Redirecting to checkout...</p><p class="sub">Please wait.</p></div></body></html>'),s.document.close()}catch(c){}(0,A.gg)("[pay button] window",s?"opened":"blocked (null)");try{var l;const t=(0,i.getFunctions)(),a=(0,i.httpsCallable)(t,"createDocumentPaymentCheckout"),c=y.current.has(n)&&v.current||void 0,d=await a((0,u.A)({documentId:n,submissionId:c,successUrl:r,cancelUrl:o},e?{paymentLinkId:e}:{})),m=null===d||void 0===d||null===(l=d.data)||void 0===l?void 0:l.url;(0,A.gg)("[pay button] result url",null!==m&&void 0!==m?m:"none"),m&&"string"===typeof m?s?s.location.href=m:Y.Ay.error("Popup blocked. Please allow pop-ups for this site and try again."):(s&&s.close(),Y.Ay.error("Could not start payment."))}catch(d){s&&s.close();const e=null===d||void 0===d?void 0:d.message,t=!e||"INTERNAL"===e||"internal"===e||"INTERNAL"===String(e).toUpperCase();console.error("[pay button] error",{code:null===d||void 0===d?void 0:d.code,message:e,details:null===d||void 0===d?void 0:d.details},d),Y.Ay.error(t?"Payment failed. Please try again or check that Stripe is configured.":e)}finally{S(!1)}},[a,n]);o.useEffect(()=>{if(re)return;if((0,A.gg)("[pay button] effect:",D.current?"has container":"NO container","linkId:",null!==a&&void 0!==a?a:"NO linkId"),!D.current||!a||!n)return void(0,A.gg)("[pay button] effect: bailing (no container, linkId, or documentId)");const e=D.current,t="[data-payment-button]",r=[];if(l){const n=()=>e.querySelectorAll(t).forEach(e=>{e.style.display="none"});n();const r=new MutationObserver(n);return r.observe(e,{childList:!0,subtree:!0}),()=>r.disconnect()}if(ee||Array.isArray(K)&&K.length>0){const t=()=>{(0,Be._b)(e,{paymentComplete:ee,paidLinkIds:K,paymentAmountCents:g})};t();const n=new MutationObserver(t);if(n.observe(e,{childList:!0,subtree:!0}),ee)return()=>n.disconnect();r.push(()=>n.disconnect())}const o=e=>{var n,r;const o=null===(n=e.target)||void 0===n||null===(r=n.closest)||void 0===r?void 0:r.call(n,t);o&&"true"!==o.getAttribute("data-payment-paid")&&((0,A.gg)("[pay button] click"),e.preventDefault(),e.stopPropagation(),ue(o.getAttribute("data-payment-link-id")||null))},s=e=>{var n,r;if("Enter"!==e.key&&" "!==e.key)return;const o=null===(n=e.target)||void 0===n||null===(r=n.closest)||void 0===r?void 0:r.call(n,t);o&&"true"!==o.getAttribute("data-payment-paid")&&((0,A.gg)("[pay button] keydown",e.key),e.preventDefault(),ue(o.getAttribute("data-payment-link-id")||null))},i=()=>{e.querySelectorAll(t).forEach(e=>{"true"!==e.getAttribute("data-payment-paid")&&(e.style.cursor="pointer",e.setAttribute("role","button"),e.hasAttribute("tabindex")||e.setAttribute("tabindex","0"))})};let u=null;const c=setTimeout(()=>{i();const n=e.querySelectorAll(t).length;(0,A.gg)("[pay button] found",n,"button(s)"),u=new MutationObserver(i),u.observe(e,{childList:!0,subtree:!0}),e.addEventListener("click",o),e.addEventListener("keydown",s)},0);return()=>{var t;clearTimeout(c),null===(t=u)||void 0===t||t.disconnect(),r.forEach(e
2=>e()),e.removeEventListener("click",o),e.removeEventListener("keydown",s)}},[re,t,a,n,l,C,ue,ee,g,K]);const le=o.useCallback(async e=>{let t=e.formId,r=e.documentId,o=e.responses;try{var s;const e=(0,i.getFunctions)(),l=(0,i.httpsCallable)(e,"submitFormResponse"),c=await l({formId:t,documentId:r||n,responses:o}),d=null===c||void 0===c||null===(s=c.data)||void 0===s?void 0:s.responseId;if(d&&a&&n){const e=xe(a,n)||{},r=(0,u.A)((0,u.A)({},e.inlineFormResponseIds||{}),{},{[t]:d});De(a,n,{inlineFormResponseIds:r})}}catch(l){throw console.error("Form submission error:",l),l}},[n,a]);if(!t)return null;const ce=g?(0,ve.yP)(g):"Pay now";if(re&&ne.length>0){if(O===me)return(0,H.jsx)(ye,{steps:ne,documentId:n,hasSignatureBlocks:oe,hasPaymentStep:ae,onComplete:e=>{let t=e.responseId;const r=function(e){let t=e.hasSignatureBlocks,n=e.hasPaymentStep;return t?ge:n?he:pe}({hasSignatureBlocks:oe,hasPaymentStep:ae});L(!0),z(r),a&&n&&De(a,n,{wizardSubmitted:!0,phase:r,responseId:t||null})}});if(O===pe)return ee&&ae?(0,H.jsx)(be,{variant:"paymentSuccess",showConfetti:!0}):(0,H.jsx)(be,{});if(O===he)return(0,H.jsx)(be,{variant:"payment",paymentAmountCents:g,subtitle:"Complete payment to finish onboarding.",onContinue:()=>ue(null),continueLabel:ce,continueDisabled:N,continueLoading:N,showConfetti:!oe,formStepCount:ne.length,hasSignatureBlocks:oe,hasPaymentStep:ae});if(O===ge&&se)return(0,H.jsx)(Fe,{formStepCount:ne.length,hasSignatureBlocks:oe,hasPaymentStep:ae,children:(0,H.jsx)("div",{ref:D,children:(0,H.jsx)(G.A,{json:se,documentId:n,hideTimeEntryTimestamps:x})})})}return(0,H.jsx)("div",{ref:D,children:(0,H.jsx)(G.A,{json:te||("string"===typeof t?JSON.parse(t):t),onFormSubmit:le,documentId:n,formRenderMode:"inline",hideTimeEntryTimestamps:x})})},et=e=>{var t,n,i,l,m,g,h,p;let w=e.documentId,C=void 0===w?null:w,S=e.isDocumentShare,I=void 0!==S&&S,P=e.knowledgeBase,O=e.organizationLogo,z=e.chatbotLogo,M=void 0===z?null:z,U=e.organizationName,q=void 0===U?"Company Name":U,V=(e.workspace,e.workspaceId),_=e.linkId,W=void 0===_?null:_;const K=(0,a.ok)(),Y=(0,r.A)(K,2),G=Y[0],Q=Y[1],Z=(0,o.useRef)(""),$=(0,o.useState)(null),ee=(0,r.A)($,2),te=ee[0],ne=ee[1],re=(0,o.useState)(""),oe=(0,r.A)(re,2),ae=oe[0],se=oe[1],ie=(0,o.useState)(!1),ue=(0,r.A)(ie,2),le=ue[0],ce=ue[1],de=(0,o.useState)(!1),me=(0,r.A)(de,2),ge=me[0],he=me[1],pe=(0,o.useState)({}),fe=(0,r.A)(pe,2),xe=fe[0],De=fe[1],ye=(0,o.useState)(!1),ve=(0,r.A)(ye,2),be=ve[0],Fe=ve[1],we=(null===P||void 0===P?void 0:P.categoryOrder)||null,Ae=(null===P||void 0===P?void 0:P.documentOrder)||null,Ce=(null===P||void 0===P?void 0:P.gridDocumentOrder)||null,Ee=(null===P||void 0===P?void 0:P.reportIntroduction)||"",ke=!(!Ee||!String(Ee).trim()),je=!(null===P||void 0===P||!P.shareAsReport)||ke,Ne=!0===(null===P||void 0===P?void 0:P.hideTimeEntryTimestamps);(0,A.gg)("\ud83d\udd0d ExternalKnowledgeBaseView share as report / intro:",{shareAsReport:je,hasIntroContent:ke,reportIntroductionLen:(Ee||"").length,showIntroSection:je||ke});const Be=(0,o.useState)(null),Ie=(0,r.A)(Be,2),Te=Ie[0],Le=Ie[1],Re=(0,o.useState)(!1),Pe=(0,r.A)(Re,2),Oe=Pe[0],ze=Pe[1],Me=(0,o.useState)(null),Ue=(0,r.A)(Me,2),qe=Ue[0],_e=Ue[1],He=(0,o.useState)(!1),Ke=(0,r.A)(He,2),Ye=Ke[0],Xe=Ke[1],et=(0,o.useState)({top:0,left:0}),tt=(0,r.A)(et,2),nt=tt[0],rt=tt[1],ot=(0,o.useState)(!1),at=(0,r.A)(ot,2),st=at[0],it=at[1],ut=(0,o.useState)(!1),lt=(0,r.A)(ut,2),ct=lt[0],dt=lt[1],mt=(0,o.useState)(""),gt=(0,r.A)(mt,2),ht=gt[0],pt=gt[1],ft=(0,o.useState)([]),xt=(0,r.A)(ft,2),Dt=xt[0],yt=xt[1],vt=(0,o.useState)(null),bt=(0,r.A)(vt,2),Ft=bt[0],wt=bt[1],At=(0,o.useRef)(null),Ct=((0,o.useRef)({}),(0,o.useRef)(!1)),Et=(0,o.useRef)(null),kt=(0,o.useRef)(null);Ct.current=ct;const jt=(0,o.useCallback)(()=>{dt(!1),pt(""),yt([]),Xe(!1),_e(null);const e=window.getSelection();e&&e.removeAllRanges()},[]),Nt=(0,s.xI)(),St=(null===(t=Nt.currentUser)||void 0===t?void 0:t.uid)||null;(0,o.useEffect)(()=>{const e=()=>{var e;const t=(null===(e=At.current)||void 0===e?void 0:e.offsetHeight)||64;document.documentElement.style.setProperty("--kb-footer-h","".concat(t,"px"))};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]);const Bt=(0,o.useState)(null),It=(0,r.A)(Bt,2),Tt=It[0],Lt=It[1],Rt=(0,o.useState)(!0),Pt=(0,r.A)(Rt,2),Ot=Pt[0],zt
2=Pt[1],Mt=(0,o.useState)(null),Ut=(0,r.A)(Mt,1)[0],qt=((0,F.a)().key,(0,o.useState)([])),Vt=(0,r.A)(qt,2),_t=Vt[0],Ht=Vt[1],Wt=(0,o.useRef)(null),Kt=(0,o.useMemo)(()=>{var e;const t=Array.isArray(null===P||void 0===P?void 0:P.documents)?P.documents:[],n=!0===(null===P||void 0===P||null===(e=P.agentConfig)||void 0===e?void 0:e.visitorPdfAccessForChat);return(0,Ve.Oy)(t,{visitorPdfAccessForChat:n,isDocumentShare:I,documentId:C})},[P,I,C]);(0,o.useEffect)(()=>{const e=()=>{var e;const t=(null===(e=Wt.current)||void 0===e?void 0:e.offsetHeight)||64;document.documentElement.style.setProperty("--kb-header-h","".concat(t,"px"))};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),(0,o.useEffect)(()=>{var e;(0,A.gg)("\ud83e\udd16 Checking for agent configuration in knowledge base:",null===P||void 0===P?void 0:P.agentConfig),null!==P&&void 0!==P&&null!==(e=P.agentConfig)&&void 0!==e&&e.enabled?(Le(P.agentConfig),(0,A.gg)("\u2705 Agent enabled with config:",P.agentConfig)):(Le(null),(0,A.gg)("\u274c No agent configuration found or agent disabled"))},[P]),(0,o.useEffect)(()=>{const e=!0===(null===P||void 0===P?void 0:P.commentsEnabled);ze(e),(0,A.gg)("\ud83d\udcac Comments enabled:",e)},[P]);const Jt=(0,o.useState)(null),Yt=(0,r.A)(Jt,2),Gt=Yt[0],Xt=Yt[1];(0,o.useEffect)(()=>{if(!Oe)return;const e=new URLSearchParams(window.location.search).get("commentId");e?((0,A.gg)("\ud83d\udcac Comment ID found in URL, opening comment sidebar:",e),Xt(e),it(!0),C&&wt(C)):Xt(null)},[Oe,C]),(0,o.useEffect)(()=>{if(!Oe){if(Xe(!1),_e(null),Et.current&&kt.current){try{N(Et.current,kt.current)}catch(g){}Et.current=null,kt.current=null}return}let e=!1,t=null,n=!1,r=null;const o=()=>{r&&(clearTimeout(r),r=null)},a=()=>{o(),Xe(!1),_e(null)},s=()=>{if(r=null,Ct.current)return;const e=window.getSelection();if(!e||0===e.rangeCount)return void a();const t=e.getRangeAt(0);if(!t)return void a();const n=document.querySelectorAll("[data-document-content]");let o=null;for(const r of n)if(k(t,r)){o=r;break}if(!o)return void a();const s=t.toString().trim();if(!s)return void a();const i=function(e,t){if(!e||!t)return null;try{t.innerText||t.textContent;const n=document.createRange();n.selectNodeContents(t);const r=e.cloneRange(),o=document.createRange();o.setStart(n.startContainer,n.startOffset),o.setEnd(r.startContainer,r.startOffset);const a=o.toString().length,s=document.createRange();s.setStart(n.startContainer,n.startOffset),s.setEnd(r.endContainer,r.endOffset);return{startOffset:a,endOffset:s.toString().length,selectedText:e.toString(),startContainer:E(r.startContainer),endContainer:E(r.endContainer),startOffsetInNode:r.startOffset,endOffsetInNode:r.endOffset}}catch(n){return console.error("Error converting range to text offset:",n),null}}(t,o);if(!i)return void a();const u=t.getBoundingClientRect();rt({top:u.bottom+5,left:u.left+u.width/2}),_e({text:s,range:i,container:o}),Xe(!0)},i=e=>{o(),null!==e&&void 0!==e&&(r=setTimeout(s,e))},u=r=>{if(o(),!Ct.current){if(function(e){let t=e.target;return!e.modalOpen&&!L(t)&&!R(t)}({target:r.target,modalOpen:!1}))return Xe(!1),void _e(null);e=!0,t={x:r.clientX,y:r.clientY},n=!1}},l=r=>{e&&t&&function(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:4;if(!e||!t)return!1;const r=t.x-e.x,o=t.y-e.y;return r*r+o*o>=n*n}(t,{x:r.clientX,y:r.clientY})&&(n=!0)},c=t=>{if(Ct.current||L(t.target))return void(e=!1);const r=T({pointerDown:!1,didDrag:n,eventType:"pointerup",clickCount:t.detail||1});e=!1,i(r)},d=e=>{if(Ct.current||L(e.target))return;if(!R(e.target))return;const t=T({pointerDown:!1,didDrag:!1,eventType:"dblclick",clickCount:2});i(t)},m=e=>{if(Ct.current||L(e.target))return;if(!R(e.target))return;const t=e.detail||1;if(t<2)return;const n=T({pointerDown:!1,didDrag:!1,eventType:"click",clickCount:t});i(n)};return document.addEventListener("pointerdown",u),document.addEventListener("pointermove",l),document.addEventListener("pointerup",c),document.addEventListener("dblclick",d),document.addEventListener("click",m),()=>{o(),document.removeEventListener("pointerdown",u),document.removeEventListener("pointermove",l),document.removeEventListener("pointerup",c),document.removeEventListener("dblclick",d),document.removeEventListener("click",m)}},[Oe]),(0,o.useEffect)(()=>
2{if(!ct||null===qe||void 0===qe||!qe.range||null===qe||void 0===qe||!qe.container)return;if(B!==B)return;const e=qe.container;if(null===e||void 0===e||!e.isConnected)return;const t="temp-selection";if(Et.current&&kt.current)try{N(Et.current,kt.current)}catch(n){}return Et.current=t,kt.current=e,j(qe.range,e,t),()=>{if(Et.current===t&&kt.current){try{N(t,kt.current)}catch(n){}Et.current=null,kt.current=null}}},[ct,qe]),(0,o.useEffect)(()=>{var e;(0,A.gg)("\ud83d\udd0d ExternalView: Ordering data from props:",{categoryOrder:we,documentOrder:Ae,knowledgeBaseKeys:Object.keys(P||{}),documentsCount:null===P||void 0===P||null===(e=P.documents)||void 0===e?void 0:e.length})},[P,we,Ae]),(0,o.useEffect)(()=>{var e;(0,A.gg)("\ud83d\udd0d ExternalView: Ordering data from props:",{categoryOrder:we,documentOrder:Ae,knowledgeBaseKeys:Object.keys(P||{}),documentsCount:null===P||void 0===P||null===(e=P.documents)||void 0===e?void 0:e.length})},[P,we,Ae]),(0,o.useEffect)(()=>{var e;const t=Array.isArray(null===P||void 0===P?void 0:P.documents)?P.documents:[],n=!0===(null===P||void 0===P||null===(e=P.agentConfig)||void 0===e?void 0:e.visitorPdfAccessForChat)?t:t.filter(e=>!(0,Ve.sI)(e));if(I&&C){var r,o;const e=n.filter(e=>String(e.id)===String(C));(0,A.gg)("\ud83d\udcc4 Document-level share: Filtering to single document",{documentId:C,totalDocs:t.length,filteredDocs:e.length,docIds:t.map(e=>e.id),matchedDoc:(null===(r=e[0])||void 0===r?void 0:r.title)||(null===(o=e[0])||void 0===o?void 0:o.fileName)||"none"}),Ht(e)}else Ht(n);t.some(e=>e.isEncrypted)&&console.error("Public share received encrypted documents - server should decrypt these"),Fe(!1)},[null===P||void 0===P?void 0:P.documents,null===P||void 0===P||null===(n=P.agentConfig)||void 0===n?void 0:n.visitorPdfAccessForChat,I,C]);(0,o.useEffect)(()=>{(async()=>{(0,A.gg)("\ud83c\udfe2 ExternalView: Skipping organization fetch for external viewer"),zt(!1),Lt(null)})()},[P.id]);const Qt=(0,o.useCallback)(()=>{if(!_t||!Array.isArray(_t))return{};if(I&&C&&1===_t.length){var e;const t=_t[0],n=(null===(e=t.info)||void 0===e?void 0:e.category)||t.category||"Uncategorized";return{[n]:[t]}}let t=_t;const n=Array.isArray(Ce)&&Ce.length>0;if(n){(0,A.gg)("\ud83d\udd0d ExternalView: Applying grid document order (list view order):",Ce);const e=new Map(_t.map(e=>[e.id,e])),n=[],r=new Set;Ce.forEach(t=>{const o=e.get(t);o&&!r.has(t)&&(n.push(o),r.add(t))}),_t.forEach(e=>{r.has(e.id)||n.push(e)}),t=n}const r={};if(t.forEach(e=>{var t;const n=(null===(t=e.info)||void 0===t?void 0:t.category)||e.category||"Uncategorized";(r[n]||(r[n]=[])).push(e)}),n)return r;if(Array.isArray(we)&&we.length){(0,A.gg)("\ud83d\udd0d ExternalView: Applying explicit category order from props:",we);const e={};return we.forEach(t=>{r[t]&&(e[t]=r[t])}),Object.keys(r).forEach(t=>{e[t]||(e[t]=r[t])}),e}Ae&&((0,A.gg)("\ud83d\udd0d ExternalView: Applying document order from props:",Ae),Object.keys(r).forEach(e=>{const t=Ae[e];if(Array.isArray(t)){const n=[],o=[];t.forEach(t=>{const o=r[e].find(e=>e.id===t);o&&n.push(o)}),r[e].forEach(e=>{t.includes(e.id)||o.push(e)}),r[e]=[...n,...o]}})),(0,A.gg)("\ud83d\udd0d ExternalView: Using alphabetical category order");const o={};return Object.keys(r).sort((e,t)=>e.localeCompare(t,void 0,{sensitivity:"base"})).forEach(e=>{o[e]=r[e]}),o},[_t,I,C,Ae,we,Ce]);(0,o.useEffect)(()=>{var e;if(!be&&(null!==(e=null===_t||void 0===_t?void 0:_t.length)&&void 0!==e?e:0)>0){const e=Qt(),t={};Object.keys(e).forEach(e=>{t[e]=!0}),De(t),(0,A.gg)("\ud83d\udd0d ExternalView: Initialized expanded sections:",Object.keys(t))}},[be,_t,we,Ae,Ce,Qt]),(0,o.useEffect)(()=>{if(be||!((null===_t||void 0===_t?void 0:_t.length)>0))return;const e=window.location.hash;if(!e)return;const t=e.slice(1),n="section-";if(t.startsWith(n)){const e=t.slice(8),n=Qt(),r=Object.keys(n).find(t=>t.replace(/\s+/g,"-").toLowerCase()===e);r&&De(e=>(0,u.A)((0,u.A)({},e),{},{[r]:!0}))}const r=setTimeout(()=>{const e=document.getElementById(t);e&&e.scrollIntoView({behavior:"smooth",block:"start"})},500);return()=>clearTimeout(r)},[be,_t,Qt]);const Zt=(0,o.useCallback)(e=>{var t;const n=null!=e?String(e).trim():"";if(!n)return;const r=(Array.isArray(null===P||void 0===P?void 0:P.documents)?P.documents:[]).find(e=>e&&String(e.id)===n);if(!r){const e=W?(0,We.Wp)(W,n):"";return void(e&&window.open(e,"_blank","noopener,noreferrer"))}if(!0===(null===P||void 0===P||null===(t=P.agentConfig)||void 0===t?void 0:t.visitorPdfAccessForChat)&&((0,Ve.sI)(r)||"pdf"===r.viewerMode))return void ne(r);if(!(_t||[]).some(e=>e&&String(e.id)===n)){const e=W?(0,We.Wp)(W,n):"";return void(e&&window.open(e,"_blank","noopener,noreferrer"))}wt(n),window.setTimeout(()=>{const e=document.getElementById("doc-".concat(n));e&&e.scrollIntoView({behavior:"smooth",block:"start"})},450)},[null===P||void 0===P?void 0:P.documents,null===P||void 0===P||null===(i=P.agentConfig)||void 0===i?void 0:i.visitorPdfAccessForChat,_t,W]);(0,o.useEffect)(()=>
2{if(!te)return;const e=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),Z.current="",ne(null))};return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[te]),(0,o.useEffect)(()=>{var e;const t=G.get("doc");if(!t||!String(t).trim())return;const n=String(t).trim(),r=(Array.isArray(null===P||void 0===P?void 0:P.documents)?P.documents:[]).find(e=>e&&String(e.id)===n);if(!r)return;if(!0===(null===P||void 0===P||null===(e=P.agentConfig)||void 0===e?void 0:e.visitorPdfAccessForChat)&&((0,Ve.sI)(r)||"pdf"===r.viewerMode)){if(Z.current===n)return;Z.current=n,ne(r);const e=new URLSearchParams(G);return e.delete("doc"),void Q(e,{replace:!0})}const o=_t||[];if(!o.length)return;if(!o.some(e=>e&&String(e.id)===n))return;if(Z.current===n)return;Z.current=n,wt(n);const a=new URLSearchParams(G);a.delete("doc"),Q(a,{replace:!0});const s=setTimeout(()=>{const e=document.getElementById("doc-".concat(n));e&&e.scrollIntoView({behavior:"smooth",block:"start"})},450);return()=>clearTimeout(s)},[G,_t,null===P||void 0===P?void 0:P.documents,null===P||void 0===P||null===(l=P.agentConfig)||void 0===l?void 0:l.visitorPdfAccessForChat,Q]);(0,o.useEffect)(()=>{const e=()=>{window.scrollY>500?ce(!0):ce(!1);const e=document.querySelectorAll("[data-section]");let t="";e.forEach(e=>{const n=e.getBoundingClientRect();n.top<=150&&n.bottom>=150&&(t=e.getAttribute("data-section"))}),t&&se(t)};return window.addEventListener("scroll",e),()=>window.removeEventListener("scroll",e)},[]);const $t=Qt(),en=!I&&Object.keys($t).some(e=>!Ge(e)),tn=()=>{const e=(0,o.useRef)(null);return(0,o.useEffect)(()=>{let t=!1;const n=()=>{t=!1;const n=window.scrollY||document.documentElement.scrollTop,r=document.documentElement,o=r.
2scrollHeight-r.clientHeight||1,a=Math.max(0,Math.min(1,n/o));e.current&&(e.current.style.transform="scaleX(".concat(a,")"))},r=()=>{t||(t=!0,requestAnimationFrame(n))};return window.addEventListener("scroll",r,{passive:!0}),window.addEventListener("resize",r,{passive:!0}),n(),()=>{window.removeEventListener("scroll",r),window.removeEventListener("resize",r)}},[]),(0,H.jsx)("div",{className:"fixed top-0 left-0 right-0 h-1 bg-gray-200 z-[60] pointer-events-none",children:(0,H.jsx)("div",{ref:e,className:"h-full bg-blue-500",style:{transformOrigin:"left center",transform:"scaleX(0)"}})})},nn=()=>{if((0,A.gg)("\ud83c\udfe2 getOrganizationDisplayData called with:",{organization:Tt,organizationName:q,organizationLogo:O,organizationLoading:Ot,organizationBranding:null===Tt||void 0===Tt?void 0:Tt.branding}),Tt&&Tt.name){var e,t,n;const r={name:Tt.name,logo:(null===(e=Tt.branding)||void 0===e?void 0:e.logoUrl)||O,hasLogo:!!(null!==(t=Tt.branding)&&void 0!==t&&t.logoUrl||O),primaryColor:(null===(n=Tt.branding)||void 0===n?void 0:n.primaryColor)||null,userRole:Tt.userRole||null};return(0,A.gg)("\ud83c\udfe2 Using fetched organization data:",r),r}const r={name:q,logo:O,hasLogo:!!O,primaryColor:null,userRole:null};return(0,A.gg)("\ud83c\udfe2 Using fallback organization data:",r),r};(0,o.useEffect)(()=>{const e=nn(),t=e.logo;(0,A.gg)("\ud83c\udfa8 Favicon Debug:",{orgDisplayData:e,faviconUrl:t,hasLogo:e.hasLogo,logoSource:t}),Qe(t);const n=(null===P||void 0===P?void 0:P.title)||"Knowledge Base";((e,t)=>{let n="Knowledge Base";t&&"Company Name"!==t&&(n="".concat(t,"'s Knowledge Base")),e&&"Shared Knowledge Base"!==e&&(n=t&&"Company Name"!==t?"".concat(e," - ").concat(t):e),document.title=n,(0,A.gg)("\ud83d\udcc4 Page title updated to:",n)})(n,e.name),(0,A.gg)("\ud83c\udfa8 Updated page metadata:",{favicon:t,title:document.title,organizationName:e.name,knowledgeBaseTitle:n})},[Tt,O,q,null===P||void 0===P?void 0:P.title]),(0,o.useEffect)(()=>()=>{Qe(null),document.title="Knowledge Base",(0,A.gg)("\ud83e\uddf9 Cleaned up page metadata on component unmount")},[]);const rn=nn();return(0,A.gg)("\ud83d\udd0d ExternalKnowledgeBaseView Enhanced Debug:",{knowledgeBase:P,documentsLength:null===P||void 0===P||null===(m=P.documents)||void 0===m?void 0:m.length,categoryOrder:null===P||void 0===P?void 0:P.categoryOrder,documentOrder:null===P||void 0===P?void 0:P.documentOrder,categories:Object.keys(Qt()),firstDoc:null===P||void 0===P||null===(g=P.documents)||void 0===g?void 0:g[0],hasOrderingData:!!(null!==P&&void 0!==P&&P.categoryOrder||null!==P&&void 0!==P&&P.documentOrder),actualCategoryOrder:(null===P||void 0===P?void 0:P.categoryOrder)||"MISSING",actualDocumentOrder:(null===P||void 0===P?void 0:P.documentOrder)||"MISSING",naturalCategoryOrder:Object.keys((0,u.A)({},null===P||void 0===P||null===(h=P.documents)||void 0===h?void 0:h.reduce((e,t)=>{var n;return e[(null===(n=t.info)||void 0===n?void 0:n.category)||t.category||"Uncategorized"]=!0,e},{}))),organization:Tt,organizationLoading:Ot,organizationError:Ut,orgDisplayData:rn,propOrganizationName:q,propOrganizationLogo:O}),(0,A.gg)("\ud83d\udd0d EXTERNAL VIEW ORDERING DEBUG:",{"Expected from Firestore":["Background","Contacts","Quotes","Claims"],"Received categoryOrder":null===P||void 0===P?void 0:P.categoryOrder,"Categories found in docs":null===P||void 0===P||null===(p=P.documents)||void 0===p?void 0:p.map(e=>{var t;return(null===(t=e.info)||void 0===t?void 0:t.category)||e.category||"Uncategorized"}).filter((e,t,n)=>n.indexOf(e)===t),"Final category order will be":Object.keys(Qt())}),(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(tn,{}),le&&window.innerWidth>=768&&(0,H.jsx)("div",{className:"fixed z-40",style:{right:28,bottom:"calc(140px + env(safe-area-inset-bottom))"},children:(0,H.jsx)("button",{onClick:()=>{window.scrollTo({top:0,behavior:"smooth"})},className:"p-4 bg-gray-800 text-white rounded-full shadow-lg","aria-label":"Back to top",children:(0,H.jsx)(f.A,{size:20})})}),(0,H.jsx)("header",{ref:Wt,className:"fixed top-0 inset-x-0 z-40 bg-white/95 shadow-sm safe-top",children:(0,H.jsx)("div",{className:"px-4 sm:px-6 py-3 flex items-center justify-between",children:(0,H.jsxs)("div",{className:"flex items-center gap-x-3",children:[en&&(0,H.jsx)("button",{className:"lg:hidden inline-flex items-center justify-center h-10 w-10 rounded-md border border-gray-200 hover:bg-gray-50",onClick:()=>he(e=>!e),"aria-label":"Toggle table of contents",children:ge?(0,H.jsx)(d.A,{className:"h-5 w-5"}):(0,H.jsx)(x.A,{className:"h-5 w-5"})}),rn.hasLogo?(0,H.jsxs)("div",{className:"flex items-center gap-x-3",children:[(0,H.jsx)("img",{src:rn.logo,alt:rn.name,className:"h-10 max-w-[200px] object-contain",crossOrigin:"anonymous"}),(0,H.jsx)("span",{className:"text-lg font-medium text-gray-900",children:rn.name})]}):(0,H.jsx)("div",{className:"h-10 w-10 bg-blue-500 text-white rounded-md flex items-center justify-center mr-3",children:(0,H.jsx)("span",{className:"text-xl font-bold",children:q.charAt(0).toUpperCase()})})]})})}),(0,H.jsxs)("div",{className:"flex",children:[en&&(0,H.jsxs)("div",{className:"w-64 bg-white border-r border-gray-200 fixed left-0 bottom-0 z-30 flex flex-col transform\n  ".concat(ge?"translate-x-0":"-translate-x-full"," lg:translate-x-0 transition-transform duration-200"),style:{to
2p:"var(--kb-header-h)"},children:[(0,H.jsx)("div",{className:"w-full border-b border-gray-200 flex items-center justify-center py-5",children:(0,H.jsx)("h2",{className:"text-lg font-medium text-gray-900",children:"Table of Contents"})}),(0,H.jsx)("nav",{className:"p-4 space-y-2 overflow-y-auto flex-grow",children:Object.entries($t).map(e=>{let t=(0,r.A)(e,2),n=t[0],o=t[1];const a="section-".concat(n.replace(/\s+/g,"-").toLowerCase()),s=ae===a,i=xe[n],l=Ge(n),d=Array.isArray(o)&&o.some(e=>e&&"pdf"===e.viewerMode);if(l&&!d)return null;const m=l?"Files":n;return(0,H.jsxs)("div",{className:"space-y-1",children:[(0,H.jsx)("div",{className:"flex items-center",children:(0,H.jsxs)("button",{onClick:()=>(e=>{De((0,u.A)((0,u.A)({},xe),{},{[e]:!xe[e]}))})(n),className:"w-full flex items-center text-left px-2 py-1.5 rounded-md hover:bg-gray-100 transition-colors",children:[(0,H.jsx)("span",{className:"w-5 inline-flex justify-center shrink-0 text-gray-500",children:i?(0,H.jsx)(D.A,{className:"h-4 w-4"}):(0,H.jsx)(c.A,{className:"h-4 w-4"})}),(0,H.jsx)("span",{className:"ml-1.5 text-sm font-medium truncate ".concat(s?"text-blue-600":"text-gray-700"),children:m})]})}),i&&(0,H.jsx)("div",{className:"pl-7 space-y-1",children:o.map(e=>{const t="doc-".concat(e.id),n=function(e){if(null!==e&&void 0!==e&&e.title&&String(e.title).trim())return e.title.trim();let t=null===e||void 0===e?void 0:e.editorJson;if(t&&"string"===typeof t)try{t=JSON.parse(t)}catch(a){}if(t&&"object"===typeof t&&Array.isArray(t.content))for(const s of t.content){var n,r;if("heading"===(null===s||void 0===s?void 0:s.type)&&null!==(n=s.content)&&void 0!==n&&null!==(r=n[0])&&void 0!==r&&r.text){const e=String(s.content[0].text).trim();if(e)return e}}const o=null===e||void 0===e?void 0:e.editorHtml;if(o&&"string"===typeof o){const e=o.match(/<h[12][^>]*>(.*?)<\/h[12]>/i);if(null!==e&&void 0!==e&&e[1])return e[1].replace(/<[^>]*>/g,"").trim();const t=o.replace(/<[^>]*>/g," ").replace(/\s+/g," ").trim();if(t)return t.split(/[\n\r]/)[0].trim()}return null!==e&&void 0!==e&&e.fileName&&String(e.fileName).trim()?e.fileName.trim():null!==e&&void 0!==e&&e.isEncrypted?"[Encrypted Document]":"Untitled"}(e),r=ae===t,o="pdf"===e.viewerMode;return(0,H.jsx)("div",{className:"group",children:(0,H.jsxs)("button",{onClick:()=>{o?Zt(e.id):(e=>{const t=document.getElementById(e);t&&(t.scrollIntoView({behavior:"smooth",block:"start"}),window.innerWidth<1024&&he(!1))})(t)},className:"w-full flex items-center text-left px-2 py-1.5 rounded-md text-xs transition-colors ".concat(r?"bg-blue-50 text-blue-700 border-l-2 border-blue-500":"text-gray-600 hover:bg-white hover:text-gray-800"),title:o?"".concat(n," \u2014 open PDF viewer"):n,children:[(0,H.jsx)("span",{className:"w-5 inline-flex justify-center shrink-0",children:"image"===e.type||e.fileType&&e.fileType.startsWith("image/")?(0,H.jsx)(y.A,{className:"h-3.5 w-3.5"}):(0,H.jsx)(v.A,{className:"h-3.5 w-3.5"})}),(0,H.jsx)("span",{className:"ml-1.5 truncate flex-1",children:n}),o?(0,H.jsx)("span",{className:"ml-1.5 shrink-0 rounded border border-hairline bg-surface-muted px-1 py-px text-[10px] font-medium uppercase tracking-wide text-on-surface/70",children:"PDF"}):null]})},e.id)})})]},n)})})]}),(0,H.jsxs)("div",{className:"flex-1 bg-white pb-[calc(80px+env(safe-area-inset-bottom))] ".concat(en?"lg:ml-64":""),style:{paddingTop:"calc(var(--kb-header-h, 64px) + 1rem)"},children:[(0,H.jsx)("main",{className:"bg-white min-h-full",children:(0,H.jsx)("div",{className:"mx-auto max-w-[68ch] sm:max-w-3xl lg:max-w-5xl px-4 sm:px-6 lg:px-10 overflow-hidden",children:Object.entries($t).map(e=>{let t=(0,r.A)(e,2),n=t[0],o=t[1];const a="section-".concat(n.replace(/\s+/g,"-").toLowerCase()),s=Ge(n),i=Array.isArray(o)&&o.some(e=>e&&"pdf"===e.viewerMode),l=!I&&(!s||i),c=s?"Files":n;return(0,H.jsxs)("section",{id:a,"data-section":a,className:"mb-16",children:[l&&(0,H.jsx)("h2",{className:"text-[1.75rem] sm:text-3xl lg:text-4xl font-bold text-gray-900 border-b-2 border-gray-200 pb-4 mb-6",children:c}),o.map(e=>{(e=>{let t={};if(e.formattedContent&&"string"===typeof e.formattedContent)try{t=JSON.parse(e.formattedContent)}catch(n){console.error("Error parsing formattedContent:",n)}(0,u.A)({title:e.title||t.title,summary:e.summary||t.summary,keyPoints:e.keyPoints||t.keyPoints||[],relatedTopics:e.relatedTopics||t.relatedTopics||[],category:e.category||t.category,subcategory:e.subcategory||t.subcategory,textContent:e.textContent,formattedContent:e.formattedContent,procedures:e.procedures||t.procedures||{},dataStructure:e.data_structure_and_organization||t.data_structure_and_organization||{}},e)})(e);const t="doc-".concat(e.id),n="pdf"===e.viewerMode;
2return(0,H.jsx)("div",{id:t,"data-section":t,className:n?"mb-2":"mb-8",children:(0,H.jsx)("div",{className:n?"bg-white px-6 py-1":"bg-white p-6",children:(0,H.jsx)("div",{className:"prose max-w-none overflow-x-auto".concat(Oe?" comments-enabled":""),"data-document-content":!0,"data-document-id":e.id,children:(()=>{if(n){const t=(0,Ve.Od)(e,"PDF"),n=!!(e.sharedPdfSignedUrl||e.url||e.previewUrl);return(0,H.jsx)("div",{className:"not-prose",children:(0,H.jsxs)("button",{type:"button",disabled:!n,onClick:()=>{n&&Zt(e.id)},className:"group flex w-full items-center gap-4 rounded-brand-md border border-hairline bg-surface-muted px-4 py-3 text-left transition-colors hover:bg-white disabled:cursor-not-allowed disabled:opacity-60",children:[(0,H.jsx)("span",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-md bg-white border border-hairline",children:(0,H.jsx)(v.A,{className:"h-5 w-5 text-on-surface","aria-hidden":!0})}),(0,H.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,H.jsx)("span",{className:"block truncate text-sm font-medium text-on-surface",children:t}),(0,H.jsx)("span",{className:"block text-xs text-on-surface/70",children:n?"PDF document \u2014 click to open viewer":"PDF file unavailable on this link"})]}),n?(0,H.jsx)("span",{className:"shrink-0 rounded-md border border-hairline bg-white px-3 py-1 text-xs font-medium text-on-surface group-hover:bg-surface-muted",children:"Open"}):null]})})}var t;if((0,A.gg)("[shared-pay] doc",e.id,"paymentRevealAfterSignature:",e.paymentRevealAfterSignature,"paymentEnabled:",e.paymentEnabled),e.editorJson)return(0,H.jsx)($e,{json:e.editorJson,documentId:e.id,linkId:W,paymentRevealAfterSignature:!!e.paymentRevealAfterSignature,paymentEnabled:!!e.paymentEnabled,paymentAmountCents:null!==(t=e.paymentAmountCents)&&void 0!==t?t:null,formWizardMode:e.formWizardMode||"auto",hideTimeEntryTimestamps:Ne});if(e.textContent){const t=Ne?(0,X.cG)(e.textContent):e.textContent;return(0,H.jsx)("div",{className:"text-gray-700 whitespace-pre-wrap",children:t})}return e._lite||"lite"===(null===P||void 0===P?void 0:P._payloadMode)?(0,H.jsxs)("div",{className:"space-y-3 py-2","aria-busy":"true","aria-label":"Loading document",children:[(0,H.jsx)("div",{className:"h-4 w-2/3 rounded-brand-md bg-surface-muted animate-pulse"}),(0,H.jsx)("div",{className:"h-4 w-full rounded-brand-md bg-surface-muted animate-pulse"}),(0,H.jsx)("div",{className:"h-4 w-5/6 rounded-brand-md bg-surface-muted animate-pulse"})]}):(0,H.jsx)("div",{className:"text-gray-500",children:"No content available"})})()})})},e.id)})]},n)})})}),(0,H.jsx)("footer",{ref:At,className:"fixed bottom-0 left-0 right-0 bg-gray-50 border-t border-gray-200 px-6 lg:px-10 text-center text-gray-500 text-sm safe-left safe-right",style:{paddingTop:"0.75rem",paddingBottom:"calc(12px + env(safe-area-inset-bottom, 0px))"},children:(0,Se.BP)()&&(0,H.jsxs)("p",{children:["Powered by Based - ",(0,H.jsx)("a",{href:"https://trybased.com",target:"_blank",rel:"noopener noreferrer",className:"text-blue-500 hover:text-blue-600 hover:underline",children:"trybased.com"})]})})]})]}),Te&&V&&(0,H.jsx)(Ze,{workspaceId:V,config:Te,documents:_t,documentsForRag:Kt,knowledgeBaseTitle:(null===P||void 0===P?void 0:P.title)||"Knowledge Base",orgLogo:null!==M&&void 0!==M?M:rn.logo,orgName:rn.name,shareLinkId:W,viewerBaseOrigin:"undefined"!==typeof window?window.location.origin:null,onOpenSharedPdfDocument:Zt}),te?(0,H.jsx)("div",{className:"fixed inset-0 z-[100] flex flex-col bg-black/60 p-4 sm:p-6",role:"dialog","aria-modal":"true","aria-label":"PDF viewer",children:(0,H.jsxs)("div",{className:"mx-auto flex h-full w-full max-w-5xl flex-col overflow-hidden rounded-brand-md bg-white shadow-xl border border-hairline",children:[(0,H.jsxs)("div",{className:"flex shrink-0 items-center justify-between gap-3 border-b border-hairline px-4 py-3 bg-surface-muted",children:[(0,H.jsx)("p",{className:"min-w-0 truncate text-sm font-medium text-on-surface",children:(0,Ve.Od)(te,"PDF")}),(0,H.jsxs)("div",{className:"flex shrink-0 items-center gap-2",children:[(()=>{const e=te.sharedPdfSignedUrl||te.url||te.previewUrl||te.fileUrl||te.downloadUrl;return e?(0,H.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:"rounded-brand-md px-3 py-1.5 text-sm font-medium text-on-surface hover:bg-white border border-hairline",children:"Open in new tab"}):null})(),(0,H.jsx)("button",{type:"button",className:"rounded-brand-md px-3 py-1.5 text-sm font-medium text-on-surface hover:bg-white border border-hairline",onClick:()=>{Z.current="",ne(null)},children:"Close"})]})]}),(0,H.jsx)("div",{className:"min-h-0 flex-1 bg-surface-muted p-3 sm:p-4",children:(()=>{const e=te.sharedPdfSignedUrl,t=te.url||te.previewUrl||te.fileUrl||te.downloadUrl;return e||t?(0,H.jsx)(Je.yd,{signedUrl:e||void 0,downloadUrl:e?void 0:t,title:(0,Ve.Od)(te,"PDF"),className:"h-[min(85vh,720px)] w-full rounded-brand-md border border-hairline bg-white"},e||t):(0,H.jsx)("p",{className:"text-sm text-on-surface px-2",children:"PDF file is not available on this link."})})()})]})}):null,Oe&&Ye&&qe&&!ct&&(0,H.jsx)("div",{className:"comment-button fixed z-50",style:{to
2p:"".concat(nt.top,"px"),left:"".concat(nt.left,"px"),transform:"translateX(-50%)"},children:(0,H.jsxs)("button",{type:"button",onMouseDown:e=>{e.preventDefault(),e.stopPropagation()},onClick:e=>{if(e.stopPropagation(),e.preventDefault(),qe&&qe.container){const e=qe.container.closest("[data-document-id]"),t=e?e.getAttribute("data-document-id"):null;wt(t),dt(!0)}},className:"flex items-center gap-2 px-3 py-2 bg-blue-600 text-white rounded-lg shadow-lg hover:bg-blue-700 transition-colors",children:[(0,H.jsx)(b.A,{className:"w-4 h-4"}),(0,H.jsx)("span",{className:"text-sm font-medium",children:"Add Comment"})]})}),Oe&&ct&&qe&&(0,H.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-50",onClick:e=>{e.target===e.currentTarget&&jt()},children:(0,H.jsx)("div",{"data-comment-modal":!0,className:"bg-white rounded-lg shadow-xl max-w-2xl w-full mx-4 max-h-[90vh] overflow-y-auto",onClick:e=>{e.stopPropagation()},children:(0,H.jsxs)("div",{className:"p-6",children:[(0,H.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,H.jsx)("h3",{className:"text-lg font-semibold text-gray-900",children:"Add Comment"}),(0,H.jsx)("button",{type:"button",onClick:()=>jt(),className:"text-gray-400 hover:text-gray-600",children:(0,H.jsx)(d.A,{className:"w-5 h-5"})})]}),(0,H.jsx)("div",{className:"mb-4 p-3 bg-yellow-50 border-l-4 border-yellow-400 rounded",children:(0,H.jsxs)("div",{className:"text-sm text-gray-800 italic",children:['"',qe.text.length>200?qe.text.substring(0,200)+"...":qe.text,'"']})}),(0,H.jsxs)("div",{className:"mb-4",children:[(0,H.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Comment"}),(0,H.jsx)("textarea",{value:ht,onChange:e=>pt(e.target.value),onClick:e=>e.stopPropagation(),onFocus:e=>e.stopPropagation(),placeholder:"Write your comment...",className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",rows:4})]}),(0,H.jsxs)("div",{className:"mb-4",children:[(0,H.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Mention users (email addresses, comma-separated)"}),(0,H.jsx)("input",{type:"text",value:Dt.join(", "),onChange:e=>{const t=e.target.value.split(",").map(e=>e.trim()).filter(Boolean);yt(t)},onClick:e=>e.stopPropagation(),onFocus:e=>e.stopPropagation(),placeholder:"[email protected], [email protected]",className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),(0,H.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,H.jsx)("button",{type:"button",onClick:()=>jt(),className:"px-4 py-2 text-gray-700 bg-gray-100 rounded-md hover:bg-gray-200",children:"Cancel"}),(0,H.jsx)("button",{type:"button",onClick:async()=>{if(ht.trim()&&qe&&Ft)try{var e,t;let n=window.location.pathname.split("/shared/")[1];if(n&&(n=n.split("/")[0].split("?")[0].split("#")[0].trim()),!n)throw new Error("Link ID not found");const r=Nt.currentUser?await Nt.currentUser.getIdToken():null,o=await fetch("https://us-central1-aiknowledgebase-7427e.cloudfunctions.net/createDocumentComment",{method:"POST",headers:(0,u.A)({"Content-Type":"application/json"},r&&{Authorization:"Bearer ".concat(r)}),body:JSON.stringify({linkId:n,documentId:Ft,selectedText:qe.text,textRange:qe.range,comment:ht,mentionedUserEmails:Dt,authorEmail:(null===(e=Nt.currentUser)||void 0===e?void 0:e.email)||null,authorName:(null===(t=Nt.currentUser)||void 0===t?void 0:t.displayName)||"Anonymous"})});if(!o.ok){const e=await o.json();throw new Error(e.error||"Failed to create comment")}jt(),it(!0)}catch(n){console.error("Error creating comment:",n),alert("Failed to create comment: "+n.message)}},disabled:!ht.trim(),className:"px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed",children:"Post Comment"})]})]})})}),Oe&&(0,H.jsx)(J,{isOpen:st,onClose:()=>it(!1),documentId:Ft||(I?C:null),linkId:(()=>{let e=window.location.pathname.split("/shared/")[1];return e&&(e=e.split("/")[0].split("?")[0].split("#")[0].trim()),e})(),workspaceId:V,currentUserId:St,highlightCommentId:Gt}),Oe&&(0,H.jsx)("button",{onClick:()=>it(!st),className:"fixed bottom-20 z-40 p-3 bg-blue-600 text-white rounded-full shadow-lg hover:bg-blue-700 transition-colors",style:{right:28},title:"View Comments",children:(0,H.jsx)(b.A,{className:"w-5 h-5"})})]})};var tt=n(60230),nt=n(55800),rt=n(44919);n(55634),n(91462);function ot(e){const t=null===e||void 0===e?void 0:e.shareAsReport,n=!(null===e||void 0===e||!e.reportIntroduction||!String(e.reportIntroduction).trim());return!1!==t&&(!0===t||n)}var at=n(32228),st=n(46190),it=n(63370);const ut=e=>{let t=e.knowledgeBase,n=e.organizationLogo,a=e.coverPageLogo,s=void 0===a?null:a,i=e.chatbotLogo,d=void 0===i?null:i,m=e.organizationName,g=e.workspace,h=e.workspaceId,p=e.defaultView,f=void 0===p?"search":p,x=e.documentId,D=void 0===x?null:x,y=e.isDocumentShare,b=void 0!==y&&y,F=e.enabledViews,w=void 0===F?"both":F,C=e.linkId,E=void 0===C?null:C;const k=s||n,j=null!==d&&void 0!==d?d:n;(0,A.gg)("\ud83d\udd0d KnowledgeBaseViewSwitcher - enabledViews:",w,"type:",typeof w),(0,A.gg)("\ud83d\udd0d KnowledgeBaseViewSwitcher - defaultView:",f),(0,A.gg)("\ud83d\udd0d KnowledgeBaseViewSwitcher - isDocumentShare:",b);const N="traditional"===w||"search"===w||"both"===w?w:"both";(0,A.gg)("\ud83d\udd0d KnowledgeBaseViewSwitcher - normalizedEnabledViews:",N);const S="both"===N||"traditional"===N,B="both"===N||"search"===N,I=(0,o.useState)(()=>"traditional"===N?"traditional":"search"===N?"search":f),T=(0,r.A)(I,2),L=T[0],R=T[1],P=(0,o.useState)([]),O=(0,r.A)(P,2),z=O[0],M=O[1],U=(0,st.Y)({linkId:E,documentId:D,enabled:!(0,it.Ic)(t)}).recordEvent,V=(0,o.useRef)(!1),_=(0,o.useRef)(null),W=(0,o.useState)(!1),K=(0,r.A)(W,2),J=K[0],Y=K[1],G=(null===t||void 0===t?void 0:t.reportIntroduction)||"",X=!(!G||!String(G).trim()),Q=ot(t),Z=(0,o.useState)(Q),$=(0,r.A)(Z,2),ee=$[0],te=$[1],ne=(0,at.qw)(null===t||void 0===t?void 0:t.reportCoverButtonColor,at.O9),re=(0,at.ER)(ne),oe={"--theme-color":ne,"--theme-color-fg":re};(0,A.gg)("\ud83d\udd0d Share as report / intro:",{shareAsReport:Q,hasIntroText:X,reportIntroductionLen:(G||"").length,showReportIntroInitial:Q}),(0,o.useEffect)(()=>{te(!!Q)},[Q]),(0,o.useEffect)(()=>{Y(!1)},[k]),(0,o.useEffect)(()=>{const e=n&&(n.startsWith("http")||n.startsWith("data:"));if(!E||!e)return;
2document.querySelectorAll('link[rel*="icon"]').forEach(e=>e.remove());const t=document.createElement("link");t.rel="icon",t.href=n,document.head.appendChild(t);const r=document.createElement("link");return r.rel="apple-touch-icon",r.href=n,document.head.appendChild(r),()=>{document.querySelectorAll('link[rel*="icon"]').forEach(e=>e.remove());const e=document.createElement("link");e.rel="icon",e.type="image/png",e.href="/based-logo.png",document.head.appendChild(e)}},[n,E]),(0,o.useEffect)(()=>{(0,A.gg)("\ud83d\udd0d KnowledgeBaseViewSwitcher - normalizedEnabledViews changed:",N,"currentView:",L),"traditional"===N?R("traditional"):"search"===N?R("search"):"both"===N&&"search"!==L&&"traditional"!==L&&R(f)},[N,f]),(0,o.useEffect)(()=>{const e=(null===t||void 0===t?void 0:t.id)||(null===t||void 0===t?void 0:t.workspaceId);if(_.current!==e&&(V.current=!1,_.current=e),!B||V.current||"lite"===(null===t||void 0===t?void 0:t._payloadMode))return;(async()=>{var e;if(null===t||void 0===t||!t.documents)return;V.current=!0,(0,A.gg)("\ud83d\udd04 KnowledgeBaseViewSwitcher: Loading FAQs...");const n=!0===(null===t||void 0===t||null===(e=t.agentConfig)||void 0===e?void 0:e.visitorPdfAccessForChat),o=(()=>{const e=Array.isArray(t.documents)?t.documents:[];return(0,Ve.Oy)(e,{visitorPdfAccessForChat:n,isDocumentShare:b,documentId:D})})();if(0===o.length){const e=[{id:1,question:"How do I submit a new claim?",icon:v.A,category:"Claims"},{id:2,question:"What are our office hours?",icon:q.A,category:"General"},{id:3,question:"Who do I contact for technical support?",icon:rt.A,category:"Support"}];return void M(e)}const a=(e=>{const t=[],n={claims:v.A,general:q.A,support:rt.A,policy:v.A,contact:q.A,hours:q.A,default:v.A},o=e=>{const t=(e||"").toLowerCase();for(const a of Object.entries(n)){var o=(0,r.A)(a,2);const e=o[0],n=o[1];if(t.includes(e))return n}return n.default};null===e||void 0===e||e.forEach(e=>{if(e.editorJson)try{const n="string"===typeof e.editorJson?JSON.parse(e.editorJson):e.editorJson,r=function(n){let a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if("heading"===n.type&&a<=2&&n.content){const r=n.content.map(e=>e.text||"").join("").trim();var s,i;if(r.includes("?")||r.toLowerCase().startsWith("how")||r.toLowerCase().startsWith("what")||r.toLowerCase().startsWith("when")||r.toLowerCase().startsWith("where")||r.toLowerCase().startsWith("who")||r.toLowerCase().startsWith("why"))t.push({id:"faq_".concat(t.length+1),question:r,category:e.category||(null===(s=e.info)||void 0===s?void 0:s.category)||"General",icon:o(e.category||(null===(i=e.info)||void 0===i?void 0:i.category)),documentId:e.id,documentTitle:e.title})}n.content&&Array.isArray(n.content)&&n.content.forEach(e=>r(e,a+1))};r(n)}catch(n){console.error("Error parsing document for FAQs:",n)}});return[...t.filter(e=>e.question.includes("?")),...t.filter(e=>!e.question.includes("?"))].slice(0,3)})(o);if(a.length>=3)return M(a),void(0,A.gg)("\u2705 KnowledgeBaseViewSwitcher: Extracted FAQs from document headings:",a);if(h&&o.length>0){(0,A.gg)("\ud83e\udd16 KnowledgeBaseViewSwitcher: Attempting AI FAQ generation");try{const e=await(0,nt.nr)(h,o,3,!0);if(e&&e.length>0){const t={FileText:v.A,Clock:q.A,TrendingUp:rt.A},n=e.map(e=>(0,u.A)((0,u.A)({},e),{},{icon:t[e.iconName]||v.A}));return M(n),void(0,A.gg)("\u2705 KnowledgeBaseViewSwitcher: Using AI-generated FAQs:",n)}}catch(s){console.error("Error generating AI FAQs:",s)}}if(a.length>0)M(a),(0,A.gg)("\ud83d\udcdd KnowledgeBaseViewSwitcher: Using",a.length,"extracted FAQ(s)");else{const e=[{id:1,question:"How do I submit a new claim?",icon:v.A,category:"Claims"},{id:2,question:"What are our office hours?",icon:q.A,category:"General"},{id:3,question:"Who do I contact for technical support?",icon:rt.A,category:"Support"}];M(e),(0,A.gg)("\ud83d\udcdd KnowledgeBaseViewSwitcher: Using mock FAQs")}})()},[t,h,b,D,B]);const ae=()=>{if("both"!==N)return(0,A.gg)("\ud83d\udd0d ViewToggle - not showing because normalizedEnabledViews is:",N),null;(0,A.gg)("\ud83d\udd0d ViewToggle - showing toggle, currentView:",L);const e={backgroundColor:"color-mix(in srgb, var(--theme-color) 15%, white)",color:"var(--theme-color)"};return(0,H.jsxs)("div",{className:"fixed right-4 sm:right-6 z-50 flex items-center rounded-lg border border-gray-200 bg-white p-0.5 shadow-sm",style:{to
2p:"calc((var(--kb-header-h, 64px) - 2.5rem) / 2)"},role:"group","aria-label":"Choose layout",children:[(0,H.jsx)("button",{type:"button",onClick:()=>R("search"),className:"p-2 rounded-md transition-colors ".concat("search"===L?"":"text-gray-600 hover:bg-gray-100"),style:"search"===L?e:void 0,title:"Home \u2014 search and FAQs",children:(0,H.jsx)(l.A,{className:"w-5 h-5","aria-hidden":!0})}),(0,H.jsx)("button",{type:"button",onClick:()=>R("traditional"),className:"p-2 rounded-md transition-colors ".concat("traditional"===L?"":"text-gray-600 hover:bg-gray-100"),style:"traditional"===L?e:void 0,title:"Documents \u2014 browse all documents",children:(0,H.jsx)(v.A,{className:"w-5 h-5","aria-hidden":!0})})]})};return Q&&ee?((0,A.gg)("\ud83d\udd0d Rendering report intro page (first screen with introduction)"),(0,H.jsx)("div",{className:"visitor-theme-root",style:oe,children:(0,H.jsx)("div",{className:"min-h-screen bg-gradient-to-b from-slate-50 to-white flex flex-col items-center justify-center px-5 sm:px-6 py-20 sm:py-24",children:(0,H.jsxs)("div",{className:"max-w-2xl w-full text-center",children:[(0,H.jsx)("div",{className:"min-h-[7rem] sm:min-h-[8rem] flex items-center justify-center mb-6",children:k&&!J?(0,H.jsx)("img",{src:k,alt:m||"",className:"h-28 w-auto max-w-[400px] object-contain sm:h-32 sm:max-w-[480px]",crossOrigin:"anonymous",referrerPolicy:"no-referrer",onError:()=>Y(!0)}
2):m?(0,H.jsx)("span",{className:"text-3xl sm:text-4xl font-semibold text-gray-700",children:m}):null}),(0,H.jsx)("h1",{className:"text-2xl sm:text-3xl font-bold text-gray-900 mb-2",children:(null===t||void 0===t?void 0:t.title)||"Report"}),X?(0,H.jsx)("div",{className:"text-center mx-auto mb-10 px-5 sm:px-10",children:(0,H.jsx)("p",{className:"text-sm sm:text-base font-normal text-gray-500 whitespace-pre-wrap leading-snug",children:G.trim()})}):(0,H.jsx)("div",{className:"mb-10","aria-hidden":"true"}),(0,H.jsxs)("button",{type:"button",onClick:()=>te(!1),className:"inline-flex items-center gap-2 px-8 py-3.5 font-medium rounded-xl focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-[var(--tw-ring-color)] transition-[filter,box-shadow] shadow-sm hover:brightness-90 active:brightness-[0.85]",style:{backgroundColor:ne,color:re,"--tw-ring-color":ne},children:["View documents",(0,H.jsx)(c.A,{className:"w-5 h-5"})]})]})})})):S||B?"traditional"===N?((0,A.gg)("\ud83d\udd0d Showing traditional view only"),(0,H.jsx)("div",{className:"visitor-theme-root",style:oe,children:(0,H.jsx)(et,{knowledgeBase:t,organizationLogo:n,chatbotLogo:j,organizationName:m,workspace:g,workspaceId:h,documentId:D,isDocumentShare:b,linkId:E})})):"search"===N?((0,A.gg)("\ud83d\udd0d Showing search view only"),(0,H.jsx)("div",{className:"visitor-theme-root",style:oe,children:(0,H.jsx)(tt.A,{knowledgeBase:t,organizationLogo:n,organizationName:m,workspace:g,workspaceId:h,documentId:D,isDocumentShare:b,faqs:z,linkId:E,recordShareViewEvent:U})})):((0,A.gg)("\ud83d\udd0d Showing both views with toggle, currentView:",L),(0,H.jsxs)("div",{className:"visitor-theme-root",style:oe,children:["traditional"===L?(0,H.jsx)(ae,{}):null,"search"===L?(0,H.jsx)(tt.A,{knowledgeBase:t,organizationLogo:n,organizationName:m,workspace:g,workspaceId:h,documentId:D,isDocumentShare:b,faqs:z,linkId:E,recordShareViewEvent:U,dualViewToggle:{currentView:L,onViewChange:R}}):(0,H.jsx)(et,{knowledgeBase:t,organizationLogo:n,chatbotLogo:j,organizationName:m,workspace:g,workspaceId:h,documentId:D,isDocumentShare:b,linkId:E})]})):(0,H.jsx)("div",{className:"visitor-theme-root",style:oe,children:(0,H.jsx)(et,{knowledgeBase:t,organizationLogo:n,chatbotLogo:j,organizationName:m,workspace:g,workspaceId:h,documentId:D,isDocumentShare:b,linkId:E})})};var lt=n(65899);function ct(e,t){e&&"object"===typeof e&&(t(e),Array.isArray(e.content)&&e.content.forEach(e=>ct(e,t)))}function dt(e){if(!e||"object"!==typeof e)return!1;let t=!1;return ct(e,e=>{"formBlock"!==e.type&&"paymentButton"!==e.type||(t=!0)}),t}var mt=n(66630),gt=n(62266);const ht="based_anon_viewer_id";function pt(){let e=null;try{e=localStorage.getItem(ht)}catch(t){}if(!e){e=crypto.randomUUID?crypto.randomUUID():"".concat(Date.now(),"-").concat(Math.random().toString(36).slice(2));try{localStorage.setItem(ht,e)}catch(t){}}return e}const ft=()=>{var e,t;const n=(0,o.useState)(null),u=(0,r.A)(n,2),l=u[0],c=u[1],d=(0,o.useState)(!0),m=(0,r.A)(d,2),g=m[0],h=m[1],p=(0,o.useState)(null),f=(0,r.A)(p,2),x=f[0],D=f[1],y=(0,o.useState)(!1),v=(0,r.A)(y,2),b=v[0],F=v[1],w=(0,o.useState)(!1),C=(0,r.A)(w,2),E=C[0],k=C[1],j=(0,a.g)().kbId,N=(0,a.ok)(),S=(0,r.A)(N,1)[0],B=(0,a.Zp)(),I="success"===S.get("payment"),T=(0,s.xI)(),L=(0,i.getFunctions)(void 0,"us-central1"),R=(0,o.useCallback)(async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.idToken,n=void 0===t?null:t,r=e.lite,o=void 0!==r&&r;const a=(0,it.Hx)(j),s=await(0,gt.jW)(j,{idToken:n,unlockToken:a,lite:o});return s.shareAsReport=ot(s),c(s),s},[j]);(0,o.useEffect)(()=>{let e=!1;return(async()=>{try{var t,n;h(!0);try{const t=await R({lite:!0});if(e)return;if(h(!1),(0,it.Ic)(t))return;if(!(0,gt.EO)(t))return}catch(r){if(r instanceof gt.$K)return void(e||F(!0))}const o=T.currentUser?await T.currentUser.getIdToken():null,a=await R({idToken:o});if(e)return;(0,A.gg)("API Response:",a),(0,A.gg)("Organization in API response:",a.organization),(0,A.gg)("Logo URL in response:",null===(t=a.organization)||void 0===t?void 0:t.logoUrl),(0,A.gg)("Document ID in response:",a.documentId),(0,A.gg)("Documents count:",null===(n=a.documents)||void 0===n?void 0:n.length),(0,A.gg)("\ud83d\udd0d Share as report / intro from API:",{shareAsReport:a.shareAsReport,reportIntroductionLen:(a.reportIntroduction||"").length})}catch(o){if(e)return;if(o instanceof gt.$K)return void F(!0);D(o.message),console.error("Error fetching knowledge base:",o)}finally{e||h(!1)}})(),()=>{e=!0}},[j,R]);const P=async e=>{let t=e.firstName,n=e.lastName,r=e.email;k(!0);try{var o;const e=(0,i.httpsCallable)(L,"submitShareContactGate"),a=null===(o=(await e({linkId:j,firstName:t,lastName:n,email:r,anonId:pt()}
2)).data)||void 0===o?void 0:o.unlockToken;if(!a)throw new Error("Unlock failed. Please try again.");(0,it.Ch)(j,a);const s=T.currentUser?await T.currentUser.getIdToken():null;await R({idToken:s})}finally{k(!1)}};if(I)return(0,H.jsx)(be,{variant:"paymentSuccess",showConfetti:!0,onContinue:()=>B("/shared/".concat(j),{replace:!0}),continueLabel:"Return to document"});if(g)return(0,H.jsx)(mt.aZ,{subtitle:"Loading knowledge base..."});if(b)return(0,H.jsx)("div",{className:"flex items-center justify-center min-h-screen bg-gray-50",children:(0,H.jsxs)("div",{className:"max-w-md w-full space-y-8 p-6 bg-white rounded-lg shadow-md",children:[(0,H.jsxs)("div",{className:"text-center",children:[(0,H.jsx)("h2",{className:"text-xl font-semibold text-gray-800 mb-4",children:"Authentication Required"}),(0,H.jsx)("p",{className:"text-gray-600 mb-6",children:"This knowledge base requires authentication to access."})]}),(0,H.jsxs)("form",{onSubmit:e=>{e.preventDefault();(async(e,t)=>{try{h(!0),await(0,s.x9)(T,e,t);const n=await T.currentUser.getIdToken();await R({idToken:n}),F(!1)}catch(n){D(n.message),console.error("Login error:",n)}finally{h(!1)}})(e.target.email.value,e.target.password.value)},children:[(0,H.jsxs)("div",{className:"mb-4",children:[(0,H.jsx)("label",{htmlFor:"email",className:"block text-sm font-medium text-gray-700 mb-1",children:"Email"}),(0,H.jsx)("input",{id:"email",name:"email",type:"email",required:!0,className:"w-full p-2 border border-gray-300 rounded-md focus:outline-none focus:ring-blue-500 focus:border-blue-500"})]}),(0,H.jsxs)("div",{className:"mb-6",children:[(0,H.jsx)("label",{htmlFor:"password",className:"block text-sm font-medium text-gray-700 mb-1",children:"Password"}),(0,H.jsx)("input",{id:"password",name:"password",type:"password",required:!0,className:"w-full p-2 border border-gray-300 rounded-md focus:outline-none focus:ring-blue-500 focus:border-blue-500"})]}),(0,H.jsx)("button",{type:"submit",className:"w-full py-2 px-4 bg-blue-600 text-white font-medium rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500",children:"Sign In"})]})]})});if(x)return(0,H.jsx)("div",{className:"flex items-center justify-center min-h-screen bg-gray-50",children:(0,H.jsxs)("div",{className:"text-center max-w-md p-6 bg-white rounded-lg shadow-md",children:[(0,H.jsx)("svg",{className:"h-12 w-12 text-red-500 mx-auto mb-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,H.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}),(0,H.jsx)("h2",{className:"text-xl font-semibold text-gray-800 mb-2",children:"Unable to load knowledge base"}),(0,H.jsx)("p",{className:"text-gray-600",children:x})]})});if(!l)return null;const O="based-help-center"===j,z=function(e){var t;let n=(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).isHelpCenter;const r=void 0!==n&&n?
2"/based-logo.png":(null===e||void 0===e||null===(t=e.organization)||void 0===t?void 0:t.logoUrl)
2||"/based-logo.png",o=null===e||void 0===e?void 0:e.shareBranding,a=e=>"string"===typeof e&&e.trim()?e.trim():null;return{headerLogo:a(null===o||void 0===o?void 0:o.headerImageUrl)||r,coverLogo:a(null===o||void 0===o?void 0:o.coverImageUrl)||r,chatbotLogo:a(null===o||void 0===o?void 0:o.chatbotImageUrl)||r,orgFallback:r}}(l,{isHelpCenter:O}),M=z.headerLogo,U=z.coverLogo,q=z.chatbotLogo,V=M,_=(null===(e=l.organization)||void 0===e?void 0:e.name)||"Knowledge Base",W=((null===(t=l.shareBranding)||void 0===t?void 0:t.headerTitle)||"").trim(),K=O?"Help Center":W||_,J=!!l.documentId,Y=l.enabledViews||"both",G=ot(l),X=function(e){if(null===e||void 0===e||!e.documentId)return!1;const t=e.documents,n=Array.isArray(t)?t.find(t=>t.id===e.documentId)||t[0]:null;if(!n)return!1;if(n.paymentEnabled)return!0;let r=n.editorJson;if("string"===typeof r)try{r=JSON.parse(r)}catch(o){r=null}return dt(r)}(l),Q=G||X?"traditional":"search",Z=(0,it.Ic)(l),$=(l.reportIntroduction||"").trim();return(0,A.gg)("\ud83d\udd0d ShareableLinkPage - enabledViews:",Y),(0,A.gg)("\ud83d\udd0d ShareableLinkPage - knowledgeBase keys:",Object.keys(l)),(0,A.gg)("\ud83d\udd0d ShareableLinkPage - isDocumentShare:",J),(0,A.gg)("\ud83d\udd0d ShareableLinkPage - shareAsReport, defaultView:",G,Q),Z?(0,H.jsxs)("div",{className:"min-h-screen bg-surface-muted",children:[(0,H.jsx)("header",{className:"border-b border-hairline bg-white px-4 py-4",children:(0,H.jsxs)("div",{className:"max-w-3xl mx-auto flex items-center gap-3",children:[V?(0,H.jsx)("img",{src:V,alt:"",className:"h-8 w-auto object-contain"}):null,(0,H.jsx)("div",{className:"font-display text-lg text-on-surface",children:K})]})}),G&&$?(0,H.jsx)("div",{className:"max-w-3xl mx-auto px-4 pt-8 prose prose-sm text-on-surface",children:(0,H.jsx)("div",{className:"whitespace-pre-wrap",children:$})}):null,(0,H.jsx)(lt.A,{submitting:E,onSubmit:P,title:"Continue to ".concat(K)})]}):(0,H.jsx)("div",{className:"min-h-screen",children:(0,H.jsx)(ut,{knowledgeBase:l,organizationLogo:V,coverPageLogo:U,chatbotLogo:q,organizationName:K,workspaceId:l.workspaceId,currentUser:T.currentUser,defaultView:Q,documentId:l.documentId||null,isDocumentShare:J,enabledViews:Y,linkId:j})})}},77927(e,t,n){n.d(t,{N:()=>o,Z:()=>r});const r="I confirm that this is my legal signature and I consent to signing this document electronically.",o="/electronic-signatures"},46190(e,t,n){n.d(t,{Y:()=>u});var r=n(89379),o=n(65043),a=n(52395),s=n(1862);const i="based_anon_viewer_id";function u(e){let t=e.linkId,n=e.documentId,u=e.scrollContainerRef,l=e.enabled,c=void 0===l||l;const d=(0,o.useRef)(null),m=(0,o.useRef)(null),g=(0,o.useRef)(0),h=(0,o.useRef)(0),p=(0,o.useRef)(0),f=(0,o.useRef)(!0),x=(0,o.useRef)(n||null),D=(0,o.useRef)(null),y=(0,o.useRef)(!1),v=(0,o.useRef)(!1),b=(0,o.useCallback)(e=>{f.current=!0,e.current&&clearTimeout(e.current),e.current=setTimeout(()=>{f.current=!1},6e4)},[]),F=(0,o.useCallback)(()=>{const e=null===u||void 0===u?void 0:u.current;if(e){const t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return n<=r?100:Math.round((t+r)/n*100)}const t=document.documentElement,n=window.scrollY||t.scrollTop,r=t.scrollHeight,o=window.innerHeight;return r<=o?100:Math.round((n+o)/r*100)},[u]),w=(0,o.useCallback)(()=>({sessionId:d.current,linkDocId:m.current,activeMsDelta:g.current-p.current,maxScrollPct:h.current,currentDocumentId:x.current,currentDocumentTitle:D.current}),[]),A=(0,o.useCallback)(async function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(y.current)return void(0,s.gg)("[ViewTracker] skip: analytics disabled");if(!d.current||!m.current)return void(0,s.gg)("[ViewTracker] skip: no session yet (sessionRef=%s, linkDocIdRef=%s)",d.current,m.current);if(g.current-p.current<=0&&!e)return void(0,s.gg)("[ViewTracker] skip: no delta (activeMs=%d, lastFlush=%d)",g.current,p.current);const t=w();p.current=g.current;const n=(0,a.getFunctions)(void 0,"us-central1"),r=e?"endShareViewSession":"heartbeatShareViewSession",o=(0,a.httpsCallable)(n,r);(0,s.gg)("[ViewTracker] calling %s with:",r,t);try{const e=await o(t);(0,s.gg)("[ViewTracker] %s OK, server returned:",r,e.data)}catch(i){(0,s.gg)("[ViewTracker] %s FAILED:",r,i.code,i.message,i)}},[w]),C=(0,o.useCallback)(function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(y.current)return;if(!d.current||!m.current)return;if(g.current-p.current<=0&&!e)return;const t=w();p.current=g.current,function(e,t){try{fetch("".concat("https://us-central1-aiknowledgebase-7427e.cloudfunctions.net","/").concat(e),{method:"POST",mode:"cors",credentials:"omit",keepalive:!0,headers:{"Content-Type":"application/json"},body:JSON.stringify({data:t})}).catch(()=>{})}catch(n){}}(e?"endShareViewSession":"heartbeatShareViewSession",t)},[w]),E=(0,o.useCallback)((e,t)=>{e!==x.current&&(A(!1),x.current=e,D.current=t||null,h.current=0)},[A]),k=(0,o.useCallback)(async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.type,n=e.text,o=e.chatId;if(y.current)return;if(!d.current||!m.current)return void(0,s.gg)("[ViewTracker] recordEvent skipped: no session yet (type=%s)",t);const i="string"===typeof n?n.trim():"";if(!t||!i)return;const u="string"===typeof o&&o.trim()?o.trim():void 0;try{const e=(0,a.getFunctions)(void 0,"us-central1"),n=(0,a.httpsCallable)(e,"recordShareViewEvent");await n((0,r.A)({sessionId:d.current,linkDocId:m.current,type:t,text:i},u?{chatId:u}:{})),(0,s.gg)("[ViewTracker] recordEvent OK",{type:t,text:i,chatId:u||void 0})}catch(l){(0,s.gg)("[ViewTracker] recordEvent FAILED:",l.code,l.message)}},[]);return(0,o.useEffect)(()=>
2{if(!c||!t||v.current)return;v.current=!0;const e=(0,a.getFunctions)(void 0,"us-central1"),r=(0,a.httpsCallable)(e,"startShareViewSession"),o=function(){let e=null;try{e=localStorage.getItem(i)}catch(t){}if(!e){e=crypto.randomUUID?crypto.randomUUID():"".concat(Date.now(),"-").concat(Math.random().toString(36).slice(2));try{localStorage.setItem(i,e)}catch(t){}}return e}();r({linkId:t,documentId:n||null,anonId:o,referrer:document.referrer||null,ua:navigator.userAgent}).then(e=>{var t,n,r;null!==(t=e.data)&&void 0!==t&&t.analyticsDisabled?y.current=!0:(d.current=null===(n=e.data)||void 0===n?void 0:n.sessionId,m.current=null===(r=e.data)||void 0===r?void 0:r.linkDocId,(0,s.gg)("View session started:",d.current))}).catch(e=>{(0,s.gg)("Failed to start view session:",e.message)})},[t,n,c]),(0,o.useEffect)(()=>{if(!c||!t)return;const e={current:null},n=()=>b(e),r=["mousemove","keydown","scroll","touchstart","click"];r.forEach(e=>window.addEventListener(e,n,{passive:!0})),b(e),(0,s.gg)("[ViewTracker] intervals effect mounted, linkId:",t);let o=Date.now(),a=0;const i=setInterval(()=>{const e=Date.now(),t=e-o;o=e,f.current&&"visible"===document.visibilityState&&(g.current+=t);const n=F();n>h.current&&(h.current=n),a++,(a<=3||a%10===0)&&(0,s.gg)("[ViewTracker] tick #%d: activeMs=%d scrollMax=%d isActive=%s visible=%s session=%s",a,g.current,h.current,f.current,document.visibilityState,d.current)},1e3),u=setTimeout(()=>{(0,s.gg)("[ViewTracker] first heartbeat firing at %dms",5e3),A(!1)},5e3),l=setInterval(()=>{A(!1)},3e4),m=()=>{"hidden"===document.visibilityState&&C(!1)};document.addEventListener("visibilitychange",m);const p=()=>{C(!0)};return window.addEventListener("pagehide",p),()=>{r.forEach(e=>window.removeEventListener(e,n)),document.removeEventListener("visibilitychange",m),window.removeEventListener("pagehide",p),e.current&&clearTimeout(e.current),clearInterval(i),clearTimeout(u),clearInterval(l),A(!0)}},[t,c,F,b,A,C]),{setActiveDocument:E,recordEvent:k}}},82378(e,t,n){function r(e){var t,n;const o=[],a=[];if(!e)return{fields:o,signatureBlocks:a};if(Array.isArray(e.marks))for(const r of e.marks){var s;"fillableField"===r.type&&null!==(s=r.attrs)&&void 0!==s&&s.fieldId&&o.push({id:r.attrs.fieldId,type:r.attrs.fieldType||"text",label:r.attrs.label||""})}if("fillableFieldPlaceholder"===e.type&&null!==(t=e.attrs)&&void 0!==t&&t.fieldId&&o.push({id:e.attrs.fieldId,type:e.attrs.fieldType||"text",label:e.attrs.label||""}),"signatureBlock"===e.type&&null!==(n=e.attrs)&&void 0!==n&&n.blockId){var i;const t=e.attrs.assigneeType;let n="me";n="someone_else"===t||"me"===t?t:e.attrs.assigneeEmail&&String(e.attrs.assigneeEmail).trim()?"someone_else":"me",a.push({id:e.attrs.blockId,label:e.attrs.label||"Sign here",assigneeEmail:e.attrs.assigneeEmail||"",assigneeType:n,signingOrderIndex:null!==(i=e.attrs.signingOrderIndex)&&void 0!==i?i:null,signatureAlign:"left"===e.attrs.signatureAlign||"right"===e.attrs.signatureAlign?e.attrs.signatureAlign:"full",defaultSignature:e.attrs.defaultSignature||"",defaultSignerName:e.attrs.defaultSignerName||"",defaultSignerEmail:e.attrs.defaultSignerEmail||"",defaultSignedAt:e.attrs.defaultSignedAt||""})}if(Array.isArray(e.content))for(const u of e.content){const e=r(u);o.push(...e.fields),a.push(...e.signatureBlocks)}return{fields:o,signatureBlocks:a}}function o(e){const t=new Map,n=new Map;if(!e||!e.content)return{fields:[],signatureBlocks:[]};for(const o of e.content){const e=r(o),a=e.fields,s=e.signatureBlocks;for(const n of a)t.has(n.id)||t.set(n.id,n);for(const t of s)n.has(t.id)||n.set(t.id,t)}return{fields:Array.from(t.values()),signatureBlocks:Array.from(n.values())}}n.d(t,{HQ:()=>o})},62266(e,t,n){n.d(t,{$K:()=>o,EO:()=>i,jW:()=>s});var r=n(89379);class o extends Error{constructor(){super(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Authentication required to access this knowledge base"),this.name="SharedKnowledgeBaseAuthError"}}async function a(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const n=(r=!!t.lite,"undefined"===typeof window?null:window[r?"__BASED_SHARED_KB_PREFETCH_LITE":"__BASED_SHARED_KB_PREFETCH_FULL"]||null);var r;if(!function(e,t){var n;let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return!(!e||e.consumed||"function"!==typeof(null===(n=e.promise)||void 0===n?void 0:n.then))&&(String(e.kbId||"")===String(t)&&((r.unlockToken?String(r.unlockToken):"")===(e.unlockToken?String(e.unlockToken):"")&&!(r.idToken&&!e.hasAuth)))}(n,e,t))return null;n.consumed=!0;try{const e=await n.promise;return e&&e.ok?await e.json():null}catch(o){return null}}async function s(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!e)throw new Error("Invalid knowledge base link");const n=t.idToken,s=void 0===n?null:n,i=t.signal,u=t.unlockToken,l=void 0===u?null:u,c=t.lite,d=void 0!==c&&c,m=await a(e,{idToken:s,unlockToken:l,lite:d});if(m)return m;const g=new URLSearchParams({kbId:String(e)});d&&g.set("lite","1"),l&&g.set("unlockToken",String(l));const h="".concat("https://us-central1-aiknowledgebase-7427e.cloudfunctions.net/getSharedKnowledgeBase","?").concat(g.toString()),p={};s&&(p.Authorization="Bearer ".concat(s)),l&&(p["X-Share-Unlock-Token"]=String(l));const f=await fetch(h,(0,r.A)({method:"GET",headers:p},i?{signal:i}:{}));if(401===f.status)throw new o;
2if(!f.ok){let e="Failed to load knowledge base";try{const t=await f.json();null!==t&&void 0!==t&&t.error&&(e=t.error)}catch(x){}throw new Error(e)}return f.json()}function i(e){return!(!e||"lite"!==e._payloadMode)}},21949(e,t,n){n.d(t,{Vl:()=>l,_b:()=>u,bF:()=>c});var r=n(89379),o=n(81452);function a(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";if(null!=e&&e>=50)return(0,o.yP)(e).replace(/^Pay\s*/i,"Paid ");const n=String(t||"").trim();return n?n.replace(/^Pay\s*/i,"Paid "):"Paid"}const s={background:"rgba(34, 197, 94, 0.15)",border:"1px solid rgba(34, 197, 94, 0.4)",color:"rgb(22, 163, 74)",fontWeight:"500",cursor:"default"},i={background:"rgba(59, 130, 246, 0.15)",border:"1px solid rgba(59, 130, 246, 0.4)",color:"rgb(37, 99, 235)",fontWeight:"500",cursor:"pointer"};function u(e,t){let n=t.paymentComplete,o=void 0!==n&&n,u=t.paidLinkIds,l=void 0===u?null:u,c=t.paymentAmountCents,d=void 0===c?null:c,m=t.onPaymentClick,g=void 0===m?null:m;if(!e)return()=>{};const h=l instanceof Set?l:Array.isArray(l)?new Set(l):null,p=[];return e.querySelectorAll("[data-payment-button]").forEach(e=>{const t=e.getAttribute("data-payment-link-id")||null,n=e.getAttribute("data-payment-amount-cents"),u=null!=n&&""!==n?Number(n):null;if(!!o||h&&t&&h.has(t)){const t=e.getAttribute("data-payment-label")||e.textContent||"",n=a(null!==u&&void 0!==u?u:d,t);return e.textContent=n,e.setAttribute("data-payment-label",n),e.setAttribute("data-payment-paid","true"),Object.assign(e.style,(0,r.A)({display:"inline-flex",alignItems:"center",justifyContent:"center",padding:"2px 8px",borderRadius:"4px",lineHeight:"1",verticalAlign:"middle"},s)),e.removeAttribute("role"),void e.removeAttribute("tabindex")}if(e.removeAttribute("data-payment-paid"),Object.assign(e.style,(0,r.A)({display:"inline-flex",alignItems:"center",justifyContent:"center",padding:"2px 8px",borderRadius:"4px",lineHeight:"1",verticalAlign:"middle"},i)),e.setAttribute("role","button"),e.hasAttribute("tabindex")||e.setAttribute("tabindex","0"),"function"===typeof g){if("true"===e.dataset.paymentClickWired)return;e.dataset.paymentClickWired="true";const n=n=>{n.preventDefault(),n.stopPropagation();const r=e.getAttribute("data-payment-amount-cents"),o=null!=r&&""!==r?Number(r):null;g({paymentLinkId:t,amountCents:o})};e.addEventListener("click",n),p.push({el:e,handler:n})}}),()=>{p.forEach(e=>{let t=e.el,n=e.handler;t.removeEventListener("click",n),delete t.dataset.paymentClickWired})}}function l(e,t){let n=t.paymentComplete,r=void 0!==n&&n,o=t.paidLinkIds,s=void 0===o?null:o,i=t.paymentAmountCents,u=void 0===i?null:i,l=t.paymentButtonUrl,c=void 0===l?null:l;if(!e||"function"!==typeof e.querySelectorAll)return;const d=s instanceof Set?s:Array.isArray(s)?new Set(s):null;e.querySelectorAll("[data-payment-button]").forEach(e=>{const t=e.getAttribute("data-payment-link-id")||null,n=e.getAttribute("data-payment-amount-cents"),o=null!=n&&""!==n?Number(n):null;if(!!r||d&&t&&d.has(t)){const t=e.getAttribute("data-payment-label")||e.textContent||"",n=a(null!==o&&void 0!==o?o:u,t);return e.textContent=n,e.style.color="rgb(22, 163, 74)",e.style.fontWeight="600",void(e.style.textDecoration="none")}if(c&&"string"===typeof c){const n=e.getAttribute("data-payment-label")||e.textContent||"Click to Pay",r=t?"".concat(c).concat(c.includes("?")?"&":"?","paymentLinkId=").concat(encodeURIComponent(t)):c,o=document.createElement("a");o.href=r,o.textContent=n,o.style.color="rgb(37, 99, 235)",o.style.textDecoration="underline",e.innerHTML="",e.appendChild(o)}})}function c(e){if(!e)return"";try{const t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString(void 0,{dateStyle:"long",timeStyle:"short"})}catch(t){return e}}},63370(e,t,n){n.d(t,{Ch:()=>a,Hx:()=>o,Ic:()=>s,Se:()=>i});function r(e){return"".concat("based_share_contact_unlock:").concat(String(e||"").trim())}function o(e){if("undefined"===typeof window||!e)return null;try{const t=window.localStorage.getItem(r(e));return t&&String(t).trim()?String(t).trim():null}catch(t){return null}}function a(e,t){if("undefined"!==typeof window&&e&&t)try{window.localStorage.setItem(r(e),String(t).trim())}catch(n){}}function s(e){var t;if(!e||"object"!==typeof e)return!1;if(e.contactGate&&"object"===typeof e.contactGate){if(!0===e.contactGate.unlocked)return!1;if(!0===e.contactGate.required)return!0}return!0===e.requireContactBeforeView&&!0!==(null===(t=e.contactGate)||void 0===t?void 0:t.unlocked)}function i(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const t=String(e.firstName||"").trim(),n=String(e.lastName||"").trim(),r
2=String(e.email||"").trim();return t?n?r?/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(r)?{ok:!0,firstName:t,lastName:n,email:r}:{ok:!1,error:"Enter a valid email address"}:{ok:!1,error:"Email is required"}:{ok:!1,error:"Last name is required"}:{ok:!1,error:"First name is required"}}},76031(e,t,n){n.d(t,{VP:()=>o,sM:()=>a,zI:()=>s});const r="based.savedSignature.v1";function o(e){let t=e.uid,n=e.signerEmail;if(t)return"".concat(r,":uid:").concat(t);const o=(a=n)&&"string"===typeof a?a.trim().toLowerCase():"";var a;return o?"".concat(r,":email:").concat(o):null}function a(e){if(!e||"undefined"===typeof window)return null;try{const t=window.localStorage.getItem(e);if(!t)return null;const n=JSON.parse(t);if(n&&("type"===n.mode||"draw"===n.mode)&&"string"===typeof n.value&&n.value.length>0)return{mode:n.mode,value:n.value}}catch(t){}return null}function s(e,t){if(e&&"undefined"!==typeof window)try{window.localStorage.setItem(e,JSON.stringify(t))}catch(n){}}},65469(e,t,n){n.d(t,{A:()=>r});const r=(0,n(77784).A)("arrow-left",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]])},22633(e,t,n){n.d(t,{A:()=>r});const r=(0,n(77784).A)("arrow-up",[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]])},9463(e,t,n){n.d(t,{A:()=>r});const r=(0,n(77784).A)("chevron-left",[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]])},38326(e,t,n){n.d(t,{A:()=>r});const r=(0,n(77784).A)("chevron-right",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]])},82054(e,t,n){n.d(t,{A:()=>r});const r=(0,n(77784).A)("circle-check-big",[["path",{d:"M21.801 10A10 10 0 1 1 17 3.335",key:"yps3ct"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]])},5379(e,t,n){n.d(t,{A:()=>r});const r=(0,n(77784).A)("ellipsis",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]])},70067(e,t,n){n.d(t,{A:()=>r});const r=(0,n(77784).A)("image",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]])},28969(e,t,n){n.d(t,{A:()=>r});const r=(0,n(77784).A)("maximize-2",[["polyline",{points:"15 3 21 3 21 9",key:"mznyad"}],["polyline",{points:"9 21 3 21 3 15",key:"1avn1i"}],["line",{x1:"21",x2:"14",y1:"3",y2:"10",key:"ota7mn"}],["line",{x1:"3",x2:"10",y1:"21",y2:"14",key:"1atl0r"}]])},42983(e,t,n){n.d(t,{A:()=>r});const r=(0,n(77784).A)("menu",[["path",{d:"M4 12h16",key:"1lakjw"}],["path",{d:"M4 18h16",key:"19g7jn"}],["path",{d:"M4 6h16",key:"1o0s65"}]])},42574(e,t,n){n.d(t,{A:()=>r});const r=(0,n(77784).A)("message-circle",[["path",{d:"M7.9 20A9 9 0 1 0 4 16.1L2 22Z",key:"vv11sd"}]])},84669(e,t,n){n.d(t,{A:()=>r});const r=(0,n(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"}]])},1523(e,t,n){n.d(t,{A:()=>r});const r=(0,n(77784).A)("minimize-2",[["polyline",{points:"4 14 10 14 10 20",key:"11kfnr"}],["polyline",{points:"20 10 14 10 14 4",key:"rlmsce"}],["line",{x1:"14",x2:"21",y1:"10",y2:"3",key:"o5lafz"}],["line",{x1:"3",x2:"10",y1:"21",y2:"14",key:"1atl0r"}]])},14459(e,t,n){n.d(t,{A:()=>r});const r=(0,n(77784).A)("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"}]])}}]);
3//# sourceMappingURL=4373.f57f0bb9.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.