import{bb as R,r as d,ba as e,bc as q}from"../chunks/createLucideIcon-BcINIXoS.js";import{M as z,m as B}from"../chunks/Lightbox-0egOu1U6.js";import{P as V}from"../chunks/plus-DX1_xhE5.js";import{D as H,d as A,T as K}from"../chunks/index-B736NozD.js";import"../chunks/EyeOutlined-B40DaD3_.js";import"../chunks/addEventListener-DSPI5EF0.js";import"../chunks/LeftOutlined-Ci58k6gc.js";import"../chunks/SearchOutlined-B5_bI2oW.js";/**
 * @license lucide-react v1.24.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const G=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],Q=R("arrow-up",G);/**
 * @license lucide-react v1.24.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Z=[["path",{d:"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z",key:"18887p"}]],ee=R("message-square",Z);/**
 * @license lucide-react v1.24.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const ae=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],te=R("x",ae);function ie(t=""){const i=t?`replyan_ai_session_id_${t}`:"replyan_ai_session_id";let r=localStorage.getItem(i);return r||(r="cai_"+Math.random().toString(36).slice(2)+Date.now().toString(36),localStorage.setItem(i,r)),r}const se=({config:t,inline:i})=>{const r=d.useRef(ie(t.agent)),[w,D]=d.useState(i||!!t.autoOpen),[S,k]=d.useState(()=>t.welcomeMessage?[{role:"assistant",content:t.welcomeMessage}]:[]),[c,g]=d.useState(""),[p,P]=d.useState(!1),[u,$]=d.useState(!1),[b,j]=d.useState([]),[F,U]=d.useState(!1),E=d.useRef(null),x=()=>{t.enableUserSound&&t.userSoundFile&&new Audio(`${t.pluginUrl}assets/sounds/notification/${t.userSoundFile}`).play().catch(v=>{console.log("Audio autoplay blocked by browser",v)})};d.useEffect(()=>{E.current&&(E.current.scrollTop=E.current.scrollHeight)},[S,p]),d.useEffect(()=>{if(!w)return;const o=setInterval(async()=>{try{const m=await(await fetch(t.restUrl+"poll",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":t.restNonce},body:JSON.stringify({nonce:t.nonce,session_id:r.current})})).json();m.success&&(typeof m.data.is_manual<"u"&&U(m.data.is_manual),m.data.messages&&m.data.messages.length>0&&k(N=>{const a=[...N];let s=!1;return m.data.messages.forEach(y=>{let h=a.some(l=>l.created_at&&l.created_at===y.created_at);if(!h){const l=a.findIndex(n=>!n.created_at&&n.role===y.role&&n.content===y.content);l!==-1&&(a[l].created_at=y.created_at,h=!0,s=!0)}h||(y.role==="assistant"&&x(),a.push(y),s=!0)}),a}))}catch{}},4e3);return()=>clearInterval(o)},[w,t.ajaxUrl,t.nonce,t.welcomeMessage]);async function f(o){var N;if(!o||p)return;const v={role:"user",content:o},m=[...S,v];k(m),P(!0);try{const s=await(await fetch(t.restUrl+"chat",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":t.restNonce},body:JSON.stringify({nonce:t.nonce,message:o,session_id:r.current,history:JSON.stringify(m.slice(-8)),agent_id:t.agent||"",source:i?"pages":"default",page_title:document.title,page_url:window.location.href})})).json();if(!s.success)throw new Error(((N=s.data)==null?void 0:N.message)||t.i18n.error);s.success&&(typeof s.data.is_manual<"u"&&U(s.data.is_manual),s.data.reply&&(x(),k(y=>y.length>m.length?y:[...y,{role:"assistant",content:s.data.reply}])))}catch(a){k(s=>[...s,{role:"error",content:a.message||t.i18n.error}])}finally{P(!1)}}async function _(o){o&&o.preventDefault&&o.preventDefault();const v=c.trim();if(!v&&b.length===0)return;let m=v;if(b.length>0){const N=b.map(a=>`![image](${a})`).join(`
`);m=m?`${m}
${N}`:N}g(""),j([]),await f(m)}function L(o){var v;o.key==="Enter"&&!o.shiftKey&&(o.preventDefault(),(v=o.currentTarget.form)==null||v.requestSubmit())}async function O(o){var v,m;$(!0);try{const N=new FormData;N.append("nonce",t.nonce),N.append("session_id",r.current),N.append("image",o);const s=await(await fetch(t.restUrl+"upload",{method:"POST",headers:{"X-WP-Nonce":t.restNonce},body:N})).json();s.success&&((v=s.data)!=null&&v.url)?j(y=>[...y,s.data.url]):alert(((m=s.data)==null?void 0:m.message)||s.message||t.i18n.error)}catch(N){console.error("Upload error:",N),alert(t.i18n.error)}finally{$(!1)}}return{open:w,setOpen:D,messages:S,input:c,setInput:g,loading:p,isManual:F,sessionId:r.current,messagesRef:E,sendMessage:_,sendRawMessage:f,handleUploadImage:O,uploadingImage:u,attachments:b,setAttachments:j,onKeyDown:L}};function ce({open:t,setOpen:i}){return e.jsx("button",{className:"cai-flex cai-h-[58px] cai-w-[58px] cai-items-center cai-justify-center cai-rounded-full cai-border-0 cai-bg-[var(--replyan-ai-primary)] cai-p-0 cai-text-sm cai-font-extrabold cai-text-white cai-shadow-2xl hover:cai-brightness-95 focus:cai-outline focus:cai-outline-2 focus:cai-outline-offset-4",type:"button","aria-expanded":t,onClick:()=>i(r=>!r),children:t?e.jsx(te,{size:28,strokeWidth:2}):e.jsx(ee,{size:28,strokeWidth:2})})}function re({config:t,inline:i,setOpen:r}){return e.jsxs("header",{className:"cai-flex cai-min-h-16 cai-items-center cai-justify-between cai-bg-[var(--replyan-ai-primary)] cai-px-4 cai-py-3 cai-text-white",children:[e.jsxs("div",{children:[e.jsx("strong",{className:"cai-block cai-text-base cai-font-bold cai-leading-tight",children:t.title}),e.jsx("span",{className:"cai-block cai-text-xs cai-opacity-85",children:"Online"})]}),!i&&e.jsx("button",{className:"cai-close-chat cai-flex cai-h-8 cai-w-8 cai-items-center cai-justify-center cai-rounded-full cai-border-0 cai-bg-white/15 cai-p-0 cai-text-2xl cai-leading-none cai-text-white hover:cai-bg-white/25",type:"button","aria-label":t.i18n.close,onClick:()=>r(!1),children:"x"})]})}function ne({messagesRef:t,messages:i,loading:r,isManual:w,config:D,sessionId:S}){const k=c=>{try{const g=c.trim();if(g.startsWith("{")&&g.endsWith("}")){const p=JSON.parse(g);if(p.action==="show_form"&&p.form_id)return p}}catch{}return null};return e.jsxs("div",{ref:t,className:"cai-flex cai-flex-1 cai-flex-col cai-gap-2.5 cai-overflow-y-auto cai-bg-slate-50 cai-p-4",role:"log","aria-live":"polite",children:[i.map((c,g)=>{const p=c.role==="assistant"?k(c.content):null;if(p){const $=`${(D.homeUrl||window.location.origin).replace(/\/$/,"")}/rai/${p.form_id}/${S}`;return e.jsxs("div",{className:"cai-max-w-[86%] cai-self-start cai-border cai-border-slate-200 cai-bg-white cai-text-slate-900 cai-rounded-lg cai-px-3 cai-py-2 cai-text-sm cai-leading-relaxed cai-mb-2",children:[p.reply&&e.jsx("div",{className:"replyan-markdown-preview cai-mb-3",children:e.jsx(z,{components:B,children:p.reply})}),p.internal_description&&e.jsx("div",{className:"cai-mb-3 cai-whitespace-pre-wrap",children:p.internal_description}),e.jsxs("a",{href:$,target:"_blank",rel:"noopener noreferrer",className:"cai-inline-flex cai-w-full cai-items-center cai-justify-center cai-px-4 cai-py-2 cai-bg-[var(--replyan-ai-primary)] cai-text-white cai-text-sm cai-font-medium cai-rounded-lg hover:cai-opacity-90 cai-transition-opacity cai-shadow-sm cai-no-underline",children:[e.jsx("svg",{className:"cai-w-4 cai-h-4 cai-mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})}),p.form_name||"Open Form"]})]},`${c.role}-${g}`)}return e.jsx("div",{className:["chat-bubble cai-max-w-[86%] cai-whitespace-pre-wrap cai-break-words cai-rounded-lg cai-px-3 cai-py-2 cai-text-sm cai-leading-relaxed",c.role==="user"?"cai-self-end cai-bg-[var(--replyan-ai-primary)] cai-text-white":"",c.role==="assistant"?"cai-self-start cai-border cai-border-slate-200 cai-bg-white cai-text-slate-900":"",c.role==="error"?"cai-self-center cai-border cai-border-red-200 cai-bg-red-50 cai-text-red-800":""].join(" "),children:c.role==="assistant"||c.role==="user"?e.jsx("div",{className:"replyan-markdown-preview",children:e.jsx(z,{components:B,children:c.content})}):c.content},`${c.role}-${g}`)}),r&&!w&&e.jsx("div",{className:"cai-max-w-[86%] cai-self-start cai-rounded-lg cai-border cai-border-slate-200 cai-bg-white cai-px-4 cai-py-3 cai-text-sm cai-text-slate-600",children:e.jsxs("div",{className:"replyan-typing-indicator",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]})})]})}function oe({sendMessage:t,config:i,input:r,loading:w,setInput:D,onKeyDown:S,handleUploadImage:k,uploadingImage:c,attachments:g,setAttachments:p}){const P=d.useRef(null),[u,$]=d.useState(!1),b=x=>{var _;const f=(_=x.clipboardData)==null?void 0:_.items;if(f){for(let L=0;L<f.length;L++)if(f[L].type.indexOf("image")!==-1){const O=f[L].getAsFile();if(O){k(O),x.preventDefault();break}}}},j=x=>{x.preventDefault(),$(!0)},F=()=>{$(!1)},U=x=>{var _;x.preventDefault(),$(!1);const f=(_=x.dataTransfer)==null?void 0:_.files;f&&f[0]&&f[0].type.startsWith("image/")&&k(f[0])},E=x=>{var _;const f=(_=x.target.files)==null?void 0:_[0];f&&(k(f),x.target.value="")};return e.jsxs("form",{className:`cai-flex cai-flex-col cai-gap-2 cai-border cai-border-solid cai-rounded-2xl cai-bg-slate-100/70 cai-p-2.5 cai-mx-3 cai-mb-3 cai-shadow-sm cai-transition-all ${u?"cai-border-[var(--replyan-ai-primary)] cai-border-dashed cai-bg-[var(--replyan-ai-primary)]/5":"cai-border-slate-200/80"}`,onSubmit:t,onDragOver:j,onDragLeave:F,onDrop:U,children:[(g.length>0||c)&&e.jsxs("div",{className:"cai-grid cai-grid-cols-3 cai-gap-2 cai-w-fit cai-mb-1",children:[g.map((x,f)=>e.jsxs("div",{className:"cai-relative cai-w-16 cai-h-16 cai-rounded-xl cai-overflow-hidden cai-border cai-border-solid cai-border-slate-300 cai-bg-white",children:[e.jsx("img",{src:x,className:"cai-w-full cai-h-full cai-object-cover",alt:"upload preview"}),e.jsx("button",{type:"button",onClick:()=>p(_=>_.filter((L,O)=>O!==f)),className:"cai-absolute cai-top-1 cai-right-1 cai-flex cai-w-5 cai-h-5 !cai-p-0 !cai-m-0 cai-shrink-0 cai-items-center cai-justify-center cai-rounded-full cai-bg-slate-900/60 cai-text-white cai-text-[10px] hover:cai-bg-slate-900 cai-border-0 cai-cursor-pointer",children:"✕"})]},f)),c&&e.jsx("div",{className:"cai-flex cai-w-16 cai-h-16 cai-items-center cai-justify-center cai-rounded-xl cai-border cai-border-dashed cai-border-slate-400 cai-bg-slate-50",children:e.jsxs("div",{className:"replyan-typing-indicator !cai-m-0",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]})})]}),e.jsxs("div",{className:"cai-flex cai-items-center cai-gap-2.5",children:[e.jsx("input",{type:"file",accept:"image/*",ref:P,style:{display:"none"},onChange:E}),e.jsx("button",{type:"button",className:"cai-flex cai-h-8 cai-w-8 !cai-p-0 !cai-m-0 cai-shrink-0 cai-items-center cai-justify-center cai-rounded-full cai-border-0 cai-bg-slate-200/80 cai-text-slate-600 hover:cai-bg-slate-300/80 disabled:cai-cursor-wait disabled:cai-opacity-70 cai-cursor-pointer cai-transition-colors",disabled:w||c,onClick:()=>{var x;return(x=P.current)==null?void 0:x.click()},title:"Upload Image",children:e.jsx(V,{size:16,strokeWidth:2.5})}),e.jsx("textarea",{className:"cai-flex-1 cai-resize-none cai-border-0 cai-bg-transparent !cai-p-0 !cai-m-0 cai-text-sm cai-leading-normal cai-overflow-hidden cai-text-slate-900 focus:cai-outline-none focus:cai-ring-0 focus:cai-shadow-none",rows:1,maxLength:1500,placeholder:i.placeholder||"Ask anything...",value:r,disabled:w,onChange:x=>D(x.target.value),onKeyDown:S,onPaste:b}),e.jsx("button",{className:"cai-flex cai-h-8 cai-w-8 !cai-p-0 !cai-m-0 cai-shrink-0 cai-items-center cai-justify-center cai-rounded-full cai-border-0 cai-bg-[var(--replyan-ai-primary)] cai-text-white hover:cai-brightness-95 disabled:cai-opacity-50 disabled:cai-cursor-not-allowed cai-cursor-pointer cai-transition-all",type:"submit",disabled:w||c||!r.trim()&&g.length===0,children:e.jsx(Q,{size:16,strokeWidth:2.5})})]})]})}function le({formSlug:t,config:i,sessionId:r}){const[w,D]=d.useState(!0),[S,k]=d.useState(!1),[c,g]=d.useState(null),[p,P]=d.useState([]),[u,$]=d.useState({}),[b,j]=d.useState({}),[F,U]=d.useState(""),[E,x]=d.useState(!1),[f,_]=d.useState([]),[L,O]=d.useState(!1);d.useEffect(()=>{(async()=>{try{const s=new URLSearchParams;s.append("action","replyan_ai_get_dynamic_form"),i.nonce&&s.append("nonce",i.nonce),s.append("slug",t);const h=await(await fetch(i.ajaxUrl,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:s})).json();h.success?(g(h.data.form),P(h.data.fields||[])):U("Form not found.")}catch{U("Failed to load form.")}finally{D(!1)}})()},[t,i.ajaxUrl,i.nonce]);const o=(a,s)=>{$(y=>({...y,[a]:s}))},v=p.find(a=>a.type==="appointment"),m=v?u[`${v.field_key}_date`]:null;d.useEffect(()=>{if(!m||!c||!c.id){_([]);return}(async()=>{O(!0);try{const s=new URLSearchParams;s.append("action","replyan_ai_get_available_slots"),i.nonce&&s.append("nonce",i.nonce),s.append("form_id",c.id),s.append("date",m),s.append("session_id",r);const h=await(await fetch(i.ajaxUrl,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:s})).json();h.success?_(h.data.slots||[]):_(null)}catch{_(null)}finally{O(!1)}})()},[m,c,i.ajaxUrl,i.nonce,r]);const N=async a=>{var s,y;a.preventDefault(),k(!0),U(""),j({});try{let h=!1,l={};for(const C of p)(C.is_required==="1"||C.is_required===1||C.is_required===!0)&&(C.type==="appointment"?(!u[`${C.field_key}_date`]||!u[`${C.field_key}_time`])&&(l[C.field_key]=`Please complete the ${C.label} field (both date and time).`,h=!0):u[C.field_key]||(l[C.field_key]="Please fill in this field.",h=!0));if(h){j(l),k(!1);return}const n=new URLSearchParams;n.append("action","replyan_ai_submit_dynamic_form"),i.nonce&&n.append("nonce",i.nonce),n.append("form_id",c.id),n.append("session_id",r||""),n.append("values",JSON.stringify(u));const T=await(await fetch(i.ajaxUrl,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:n})).json();if(!T.success)throw new Error(((s=T.data)==null?void 0:s.message)||"Submission failed.");let Y=[`Form Submitted: ${c.name}`];p.forEach(C=>{const X=u[C.field_key]||"N/A";Y.push(`- ${C.label}: ${X}`)});const J=Y.join(`
`),W=await(await fetch(i.restUrl+"chat",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":i.restNonce},body:JSON.stringify({nonce:i.nonce,message:J,session_id:r,history:"[]",agent_id:i.agent||"",source:"standalone_form",page_title:document.title,page_url:window.location.href,skip_ai:!0})})).json();if(W.success)x(!0);else throw new Error(((y=W.data)==null?void 0:y.message)||"Submission failed during chat sync.")}catch(h){U(h.message)}finally{k(!1)}};return w?e.jsx("div",{className:"cai-flex cai-items-center cai-justify-center cai-min-h-[400px]",children:e.jsx("div",{className:"cai-animate-spin cai-rounded-full cai-h-12 cai-w-12 cai-border-b-2 cai-border-[var(--replyan-ai-primary)]"})}):F&&!c?e.jsxs("div",{className:"cai-p-6 cai-max-w-md cai-mx-auto cai-bg-red-50 cai-text-red-600 cai-rounded-xl cai-shadow-sm cai-text-center",children:[e.jsx("svg",{className:"cai-w-12 cai-h-12 cai-mx-auto cai-mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsx("h3",{className:"cai-text-lg cai-font-bold cai-mb-2",children:"Error Loading Form"}),e.jsx("p",{className:"cai-text-sm",children:F})]}):E?e.jsxs("div",{className:"cai-max-w-xl cai-mx-auto cai-bg-white cai-rounded-2xl cai-shadow-xl cai-p-8 cai-text-center cai-animate-in cai-zoom-in-95",children:[e.jsx("div",{className:"cai-w-16 cai-h-16 cai-bg-green-100 cai-rounded-full cai-flex cai-items-center cai-justify-center cai-mx-auto cai-mb-6",children:e.jsx("svg",{className:"cai-w-8 cai-h-8 cai-text-green-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M5 13l4 4L19 7"})})}),e.jsx("h2",{className:"cai-text-2xl cai-font-bold cai-text-slate-800 cai-mb-2",children:"Thank You!"}),e.jsx("p",{className:"cai-text-slate-600 cai-mb-6",children:"Your form has been successfully submitted. You can now close this tab and return to the chat."}),e.jsx("button",{onClick:()=>window.close(),className:"cai-px-6 cai-py-2.5 cai-bg-slate-100 hover:cai-bg-slate-200 cai-text-slate-700 cai-font-medium cai-rounded-lg cai-transition-colors",children:"Close Window"})]}):e.jsxs("div",{className:"cai-max-w-2xl cai-w-full cai-mx-auto cai-bg-white cai-rounded-2xl cai-shadow-xl cai-overflow-hidden cai-animate-in cai-fade-in cai-slide-in-from-bottom-8",children:[e.jsxs("div",{className:"cai-bg-slate-50 cai-p-6 sm:cai-p-8 cai-border-b cai-border-slate-100",children:[e.jsx("h1",{className:"cai-text-2xl cai-font-bold cai-text-slate-800 cai-mb-2",children:c.name}),c.description&&e.jsx("p",{className:"cai-text-slate-600 cai-mb-0",children:c.description})]}),e.jsx("div",{className:"cai-p-6 sm:cai-p-8",children:e.jsxs("form",{id:`dynamic-form-${c.id}`,onSubmit:N,noValidate:!0,className:"cai-flex cai-flex-col cai-gap-6",children:[p.map(a=>{const s=a.is_required==="1"||a.is_required===1||a.is_required===!0,h=`cai-w-full cai-px-4 cai-py-3 cai-text-base cai-border cai-rounded-xl focus:cai-outline-none focus:cai-ring-2 cai-bg-white cai-text-slate-900 cai-shadow-sm cai-transition-all ${!!b[a.field_key]?"cai-border-red-300 focus:cai-border-red-500 focus:cai-ring-red-500/20":"cai-border-slate-300 focus:cai-border-blue-500 focus:cai-ring-blue-500/20"}`;return e.jsxs("div",{className:"cai-flex cai-flex-col cai-gap-2",children:[e.jsxs("label",{className:"cai-text-sm cai-font-semibold cai-text-slate-700",children:[a.label," ",s&&e.jsx("span",{className:"cai-text-red-500",children:"*"})]}),a.type==="textarea"?e.jsx("textarea",{placeholder:a.placeholder||a.label,rows:4,className:`${h} cai-resize-y cai-min-h-[100px]`,value:u[a.field_key]||"",onChange:l=>{o(a.field_key,l.target.value),b[a.field_key]&&j(n=>({...n,[a.field_key]:null}))}}):a.type==="select"?e.jsxs("select",{className:h,value:u[a.field_key]||"",onChange:l=>{o(a.field_key,l.target.value),b[a.field_key]&&j(n=>({...n,[a.field_key]:null}))},children:[e.jsx("option",{value:"",disabled:!0,children:"Select an option"}),a.options&&(()=>{try{return JSON.parse(a.options).map((n,M)=>e.jsx("option",{value:n,children:n},M))}catch{return(typeof a.options=="string"?a.options.split(",").map(M=>M.trim()):[]).map((M,T)=>e.jsx("option",{value:M,children:M},T))}})()]}):a.type==="date"?e.jsx(H,{className:h,format:"YYYY-MM-DD",value:u[a.field_key]?A(u[a.field_key],"YYYY-MM-DD"):null,onChange:(l,n)=>{o(a.field_key,n),b[a.field_key]&&j(M=>({...M,[a.field_key]:null}))},placeholder:a.placeholder||"Select Date"}):a.type==="appointment"?e.jsxs("div",{className:"cai-flex cai-flex-col cai-gap-3",children:[e.jsx(H,{className:h,format:"YYYY-MM-DD",value:u[`${a.field_key}_date`]?A(u[`${a.field_key}_date`],"YYYY-MM-DD"):null,onChange:(l,n)=>{o(`${a.field_key}_date`,n),o(`${a.field_key}_time`,null),b[a.field_key]&&j(M=>({...M,[a.field_key]:null}))},placeholder:"Select Date"}),Array.isArray(f)&&m?L?e.jsx("div",{className:"cai-text-sm cai-text-slate-500 cai-py-1",children:"Loading available times..."}):f.length>0?e.jsx("div",{className:"cai-grid cai-grid-cols-3 sm:cai-grid-cols-4 cai-gap-2 cai-mt-1",children:f.map(l=>e.jsx("button",{type:"button",onClick:()=>{o(`${a.field_key}_time`,l),b[a.field_key]&&j(n=>({...n,[a.field_key]:null}))},className:`cai-px-4 cai-py-3 cai-text-sm cai-rounded-xl cai-border cai-transition-colors ${u[`${a.field_key}_time`]===l?"cai-bg-[var(--replyan-ai-primary)] cai-text-white cai-border-[var(--replyan-ai-primary)]":"cai-bg-white cai-text-slate-700 cai-border-slate-300 hover:cai-border-[var(--replyan-ai-primary)] hover:cai-text-[var(--replyan-ai-primary)]"}`,children:A(`2024-01-01T${l}:00`).format("hh:mm A")},l))}):e.jsx("div",{className:"cai-text-sm cai-text-red-500 cai-py-1",children:"No available times on this date."}):e.jsx("div",{className:"cai-text-sm cai-text-slate-500 cai-py-1 cai-italic",children:"Please select an appointment date first."})]}):a.type==="time"?e.jsx(K,{className:h,format:"HH:mm",value:u[a.field_key]?A(u[a.field_key],"HH:mm"):null,onChange:(l,n)=>{o(a.field_key,n),b[a.field_key]&&j(M=>({...M,[a.field_key]:null}))},placeholder:a.placeholder||"Select Time"}):e.jsx("input",{type:["email","number"].includes(a.type)?a.type:"text",placeholder:a.placeholder||a.label,className:h,value:u[a.field_key]||"",onChange:l=>{o(a.field_key,l.target.value),b[a.field_key]&&j(n=>({...n,[a.field_key]:null}))}}),b[a.field_key]&&e.jsxs("div",{className:"cai-text-red-500 cai-text-sm cai-mt-1 cai-flex cai-items-center cai-gap-1.5",children:[e.jsx("svg",{className:"cai-w-4 cai-h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),b[a.field_key]]}),a.help_text&&e.jsx("span",{className:"cai-text-sm cai-text-slate-500",children:a.help_text})]},a.id)}),F&&e.jsx("div",{className:"cai-text-sm cai-text-red-600 cai-p-4 cai-bg-red-50 cai-rounded-xl cai-border cai-border-red-100",children:F}),e.jsx("div",{className:"cai-pt-4",children:e.jsx("button",{type:"submit",disabled:S,className:"cai-w-full cai-py-4 cai-px-6 cai-bg-[var(--replyan-ai-primary)] cai-text-white cai-text-lg cai-font-bold cai-rounded-xl hover:cai-opacity-90 disabled:cai-opacity-70 disabled:cai-cursor-not-allowed cai-transition-all cai-shadow-md hover:cai-shadow-lg",children:S?"Submitting...":c.button_text||"Submit Form"})})]})})]})}function de({config:t,inline:i=!1}){const{open:r,setOpen:w,messages:D,input:S,setInput:k,loading:c,isManual:g,sessionId:p,messagesRef:P,sendMessage:u,sendRawMessage:$,handleUploadImage:b,uploadingImage:j,attachments:F,setAttachments:U,onKeyDown:E}=se({config:t,inline:i});return e.jsxs(e.Fragment,{children:[!i&&e.jsx(ce,{open:r,setOpen:w}),e.jsxs("section",{className:["replyan-ai-panel cai-flex cai-flex-col cai-overflow-hidden cai-rounded-lg cai-border cai-border-slate-200 cai-bg-white",i?"cai-relative cai-h-[560px] cai-w-full":"cai-absolute cai-bottom-[74px] cai-h-[min(620px,calc(100vh-112px))] cai-w-[min(380px,calc(100vw-32px))] cai-transition cai-duration-150",!i&&(r?"cai-pointer-events-auto cai-translate-y-0 cai-opacity-100":"cai-pointer-events-none cai-translate-y-3 cai-opacity-0"),!i&&t.position==="bottom-left"?"cai-left-0":"",!i&&t.position!=="bottom-left"?"cai-right-0":""].join(" "),"aria-label":t.title,children:[e.jsx(re,{config:t,inline:i,setOpen:w}),e.jsx(ne,{messagesRef:P,messages:D,loading:c,isManual:g,config:t,sessionId:p,sendRawMessage:$}),e.jsx(oe,{sendMessage:u,config:t,input:S,loading:c,setInput:k,onKeyDown:E,handleUploadImage:b,uploadingImage:j,attachments:F,setAttachments:U})]})]})}const I=document.getElementById("replyan-ai-standalone-form");if(I){const t=window.replyan_ai_frontend||{},i=I.dataset.form,r=I.dataset.session;q.createRoot(I).render(e.jsx(le,{formSlug:i,sessionId:r,config:t}))}else document.querySelectorAll(".replyan-ai-root").forEach(t=>{var w,D,S;const i={...window.replyan_ai_frontend||{},position:t.dataset.position||"bottom-right",agent:t.dataset.agent||"",title:t.dataset.title||((w=window.replyan_ai_frontend)==null?void 0:w.title)||"AI Assistant",placeholder:((D=window.replyan_ai_frontend)==null?void 0:D.placeholder)||"Type your question...",i18n:((S=window.replyan_ai_frontend)==null?void 0:S.i18n)||{}},r=t.dataset.mode==="inline";q.createRoot(t).render(e.jsx(de,{config:i,inline:r}))});
