import{bt as e,a6 as t,A as r,a4 as s,e7 as a,F as n,bK as i,ai as o,o as p,Y as l,l as u,L as c,y as d,cx as m,aM as g,ea as y,p as h,bH as f,z as v,E as _,by as b,K as I,ab as x,h as T,bn as w,aK as k,f as M,bl as S,j as U}from"./3.BctvFFo8.chunk.js";import{o as q,q as j}from"./4.DsIPCrft.chunk.js";import{h as V,g as C,d as B,t as F,c as A}from"./6.CoSZoCaB.chunk.js";const E=e=>{let{id:t,authorId:r,timestamp:s,serverId:a=t,threadId:n=null,seen:i=!1}=e;return{id:t,serverId:a,thread:n,author:r,timestamp:s,seen:i}},D=e=>{let{id:t,customId:r,authorId:s,timestamp:a,threadId:n,properties:i,seen:o,serverId:p,type:l,text:u,urlDetails:c,...d}=e;return d},O=e=>q("bb9e5b2f1ab480e4a715977b7b1b4279",e.properties)?{reaction:t("bb9e5b2f1ab480e4a715977b7b1b4279.message_reaction",e.properties)}:null,z=e=>q("aa8151b317737a3e79d8e3384e6082de",e.properties)?{useFixedAnswers:t("aa8151b317737a3e79d8e3384e6082de.use_fixed_answers",e.properties)}:null,L=t=>{if(t.urlDetails){const{urlDetails:e}=t;return{...E(t),type:"url_preview",properties:{serverType:t.type,title:e.title,description:e.description,image:{url:e.imageUrl,link:e.url}}}}if(e(t.text)){return{...E(t),type:"emoji",properties:{serverType:t.type,text:t.text,...D(t)}}}return{...E(t),type:"message",properties:{serverType:t.type,text:t.text,...D(t)}}},N=e=>{switch(e.type){case"url":return V(e.value)?null:e;case"webview":{if(V(e.value))return null;const r=C(e.value);if(!r)return e;if(/chatbot\.com$/.test(r)){const r=B(F(A(e.value)));if(r.p)try{const t=JSON.parse(atob(r.p));if(t.url)return{...e,proxiedValue:t.url}}catch(t){return e}}return e}default:return e}},H=e=>{const t={};return"string"==typeof e.title&&(t.title=e.title),"string"==typeof e.subtitle&&(t.subtitle=e.subtitle),e.image&&(t.image={...e.image,link:e.image.url}),e.buttons&&(t.buttons=e.buttons.map(N).filter(Boolean)),t},R=e=>{switch(e.template){case"quick_replies":{const t=e.elements[0];return{...E(e),type:"message",properties:{serverType:e.type,text:t.title,quickReplies:t.buttons.map(e=>({type:e.type,text:e.text,value:e.value,postbackId:e.postbackId})),...O(e),...z(e)}}}case"sticker":{const t=e.elements[0].image;return{...E(e),type:"sticker",properties:{serverType:e.type,url:t.url,name:t.name,...O(e),...z(e)}}}default:{if(e.elements.length>1){return{...E(e),type:"carousel",properties:{serverType:e.type,cards:e.elements.map(H)}}}const t=e.elements[0];if(1===Object.keys(t).length&&t.image){const{image:r}=t;return{...E(e),type:"image_preview",properties:{name:r.name,serverType:e.type,url:r.url,...r.alternativeText&&{alternativeText:r.alternativeText},...O(e),...z(e)}}}return{...E(e),type:"rich_message",properties:{serverType:e.type,card:H(t),...O(e),...z(e)}}}}},G=e=>{const t={...E(e),type:"system_message",properties:{serverType:e.type,systemMessageType:e.systemMessageType,defaultText:e.text}};return e.textVars&&(t.properties.textVariables=e.textVars),t},P={question:{type:"text"},checkbox_for_email:{type:"checkbox",meta:"confirm_subscription"},header:{type:"information"},skill:{type:"group_select"}},K=e=>e.map((e,t)=>{const r={};return q("label",e)&&(r.label=e.label),q("checked",e)&&(r.checked=e.checked),r.value=String(t),q("skill_id",e)&&(r.value=String(e.skill_id)),q("embedded_chat_hide_when_offline",e)&&(r.ticketFormDisabled=Boolean(e.embedded_chat_hide_when_offline)),q("queue_template",e)&&(r.queueTemplate=e.queue_template),r}),J=e=>{let t=!1;const r={fields:e.fields.sort((e,t)=>e.order-t.order).map((e,r)=>{const s={};if("facebookConnect"===e.type)return t=!0,!1;e.id?s.name=e.id:-1===["header","information"].indexOf(e.type)&&(s.name=String(r)),q("value",e)&&(s.value=e.value),q("label",e)&&(s.label=e.label),q("required",e)&&(s.required=e.required),"rating"===e.type&&(s.commentLabel=e.options[0]),e.skills&&e.skills.length>0?s.options=K(e.skills):e.options&&e.options.length>0&&(e.options_data?s.options=K(e.options_data):o(e.options[0])?s.options=e.options.map((e,t)=>{let{label:r}=e;return{label:r,value:String(t)}}):s.options=e.options.map((e,t)=>({label:e,value:String(t)}))),e.serverType&&(s.serverType=e.serverType);const{type:a,meta:n}=(e=>({type:P[e]&&P[e].type||e,meta:P[e]&&P[e].meta||!1}))(e.type);return s.type=a,n&&(s.meta=n),s}).filter(Boolean)};return e.id&&(r.id=e.id),t&&(r.facebookConnect=!0),r},Q=e=>({...e,fields:e.fields.map(e=>{switch(e.type){case"name":case"subject":return{...e,maxLength:1024};case"email":case"textarea":return{...e,required:!0};default:return e}})}),Y=e=>{let{license:t,group:o,pageUrl:p,form:l,answers:u}=e;const c=((e,t)=>{const o=s(e=>"message"===e?"textarea":e,e);return t.fields.map(e=>{if("information"===e.type)return null;const t={type:e.type,text:"undefined"!=typeof document?a(e.label):e.label,serverType:e.serverType};return(e.name in o||e.type in o)&&("options"in e?t.value=n(o[e.name]).map(t=>r(e=>e.value===t,e.options).label).join(", "):e.name in o?t.value=o[e.name]:t.value=o[e.type],t.value=i(t.value),t.text=t.text+" "+t.value),t}).filter(Boolean)})(u,l),d=r(e=>"email"===e.type||"email"===e.serverType,c),m=r(e=>"name"===e.type||"name"===e.serverType,c);if(!d)throw new Error("Missing email");if(!r(e=>"textarea"===e.type,c))throw new Error("Missing message");const g=r(e=>"subject"===e.type||"subject"===e.serverType,c),y=c.filter(e=>{let{type:t,serverType:r}=e;return-1===["name","email","subject"].indexOf(r||t)}).map(e=>{let{text:t}=e;return t}).join("\n");return{...g&&g.value&&{subject:g.value},message:{text:y},requester:{email:d.value,...m&&m.value&&{name:m.value}},integration:{type:"livechat",ID:String(t),teamID:String(o),...p&&{referenceURL:p}}}},$=(e,t)=>{const{requester:r,message:s,subject:a}=t,{text:n}=s,{name:i,email:o}=r;return{id:e,text:n,...a&&{subject:a},visitor:{name:i||null,email:o||null}}},W={group_chooser:"select",header:"information",name:"text",question:"text",subject:"text",checkbox_for_email:"checkbox"},X=(e,t)=>e.getSessionUser().serverId===t.authorId,Z=(e,t)=>X(e,t)?e.getSessionUser().id:t.authorId,ee=(e,t)=>{if("file"===t.type)return t.id;if(X(e,t))return"customId"in t&&e.hasEvent(c,t.customId)?t.customId:t.id;const r=e.getEventByServerId(c,t.id);return r?r.id:t.id},te=e=>null!=e&&e.groupIds?e.groupIds[0]:null,re=(e,t)=>{const r=e.getSessionUser().serverId,s=d(t.filter(e=>e.present&&e.id!==r));return s?s.id:null},se=(e,t)=>{let{chat:r,chat:{thread:s,users:a}}=t;return{id:r.id,active:s.active,agent:re(e,a),events:s.events.map(t=>ce(e,{...t,seen:!1})).filter(Boolean),group:te(r.access),thread:s.id,properties:ve(s)}},ae=(e,t)=>({...t,type:e,fields:t.fields.reduce((e,t)=>{let{id:r,...s}=t;const a={...s,type:W[s.type]||s.type,serverName:r,serverType:s.type};if("information"===a.type)a.value=a.label.replace(//gi,"\n");else if("checkbox_for_email"===s.type)a.meta="confirm_subscription",a.label="",a.options=[{label:s.label,checked:s.checked,value:"index0_0",originalValue:"0"}],s.checked&&(a.defaultValue=[a.options[0].value]);else if(s.options){const e="group_chooser"===s.type;e&&(a.meta="groupSelect"),a.options=a.options.map((t,r)=>{const s=e?t.groupId:t.id;return{...p(["id","checked"],t),value:"index"+r+"_"+s,originalValue:String(s)}})}return a.name=l(s.type,["name","email","rating"])?s.type:u()+"_"+r,"rating"===s.type?[].concat(e,[a,{name:"rateComment",type:"textarea",label:a.commentLabel,required:!1,dependOn:"rating"}]):[].concat(e,[a])},[])}),ne=e=>Q(ae("ticket",e)),ie=(e,t)=>{const r=e.getSessionUser().serverId,{[r]:s,...a}=t;return{sessionUserSeenUpTo:s,latestOtherUserSeenUpTo:d(g(a).filter(Boolean).sort())}},oe=e=>{const t=y(e=>"systemMessageType"in e&&"rating.chat_commented"===e.systemMessageType,e),r=y(e=>"systemMessageType"in e&&"rating.chat_rated"===e.systemMessageType,e),s=y(e=>"systemMessageType"in e&&"rating.chat_rating_canceled"===e.systemMessageType,e);return e.filter((e,a)=>{const n="systemMessageType"in e&&["rating.chat_rated","rating.chat_commented","rating.chat_rating_canceled"].includes(e.systemMessageType),i="filled_form"===e.type&&!e.fields.some(e=>"answer"in e&&Boolean(e.answer));return!n&&!i||a===t||a===r||a===s&&s>r})},pe=e=>{if(!e)return!1;const{events:t,active:r}=e;if(r)return!0;if(!t.length)return!1;const s=t[0],a=d(t);return 2!==t.length||"filled_form"!==s.type||"system_message"!==a.type||"manual_archived_customer"!==a.systemMessageType||s.fields.some(e=>"answer"in e&&Boolean(e.answer))},le=(e,t)=>{let{thread:r,users:s,eventsSeenUpToMap:a}=t;const n=e.getSessionUser().serverId,i=re(e,s),{sessionUserSeenUpTo:o,latestOtherUserSeenUpTo:p}=ie(e,a);if(!pe(r))return{thread:null,eventsSeenUpToMap:a};const{id:l,active:u,events:c,access:d}=r;return{thread:{id:l,active:u,agent:u?i:null,events:(u?c:oe(c)).map(t=>{const r=t.authorId===n?p>=t.createdAt:o>=t.createdAt;return ce(e,{...t,seen:r})}).filter(Boolean),group:te(d),properties:ve(r)},eventsSeenUpToMap:a}},ue=e=>{let{properties:t,...r}=e;if("lc2"in t){const e=t.lc2;if("greeting_unique_id"in e)return((e,t)=>{const r=L({...e});return r.properties={...r.properties,invitation:!0,subtype:e.subtype,id:t.greeting_id,uniqueId:t.greeting_unique_id},r})(r,e);if(e.welcome_message)return((e,t)=>{var r;return L({...e,welcomeMessage:!0,...(null==(r=t.chats)?void 0:r.formatting)&&{formatting:t.chats.formatting},..."bb9e5b2f1ab480e4a715977b7b1b4279"in t&&{reaction:t.bb9e5b2f1ab480e4a715977b7b1b4279.message_reaction},..."aa8151b317737a3e79d8e3384e6082de"in t&&{useFixedAnswers:t.aa8151b317737a3e79d8e3384e6082de.use_fixed_answers}})})(r,t)}return((e,t)=>{var r;return L({...e,...t.url_details&&{urlDetails:t.url_details},...t.translation&&{translation:xe(t.translation)},...(null==(r=t.chats)?void 0:r.formatting)&&{formatting:t.chats.formatting},..."bb9e5b2f1ab480e4a715977b7b1b4279"in t&&{reaction:t.bb9e5b2f1ab480e4a715977b7b1b4279.message_reaction},..."aa8151b317737a3e79d8e3384e6082de"in t&&{useFixedAnswers:t.aa8151b317737a3e79d8e3384e6082de.use_fixed_answers}})})(r,t)},ce=(e,t)=>{const r={...t,id:ee(e,t),serverId:t.id,authorId:Z(e,t),timestamp:new Date(t.createdAt).getTime()};switch(r.type){case"form":return me(r);case"filled_form":return ge(r);case"message":return ue(r);case"rich_message":return(e=>{if("lc2"in e.properties&&"greeting_unique_id"in e.properties.lc2){const t=R(e);return t.properties={...t.properties,invitation:!0,subtype:e.subtype,id:e.properties.lc2.greeting_id,uniqueId:e.properties.lc2.greeting_unique_id,..."bb9e5b2f1ab480e4a715977b7b1b4279"in e.properties&&{reaction:e.properties.bb9e5b2f1ab480e4a715977b7b1b4279.message_reaction}},t}const t=R(e);return"aa8151b317737a3e79d8e3384e6082de"in e.properties&&(t.properties={...t.properties,useFixedAnswers:e.properties.aa8151b317737a3e79d8e3384e6082de.use_fixed_answers}),t})(r);case"file":return(e=>{if(e.thumbnails){const{thumbnails:t}=e,r={...E(e),type:"image_preview",properties:{name:e.name,serverType:e.type,...t.default,link:e.url,srcSet:t.default.url+" 1x, "+t.high.url+" 2x",...O(e),...z(e)}};return e.alternativeText&&(r.properties.alternativeText=e.alternativeText),r}return{...E(e),type:"message",properties:{serverType:e.type,text:e.name,url:e.url,...e.alternativeText&&{alternativeText:e.alternativeText},...O(e),...z(e)}}})(r);case"system_message":return ye(r);case"custom":return de(r);default:return null}},de=e=>{const{properties:t,customId:r}=e;return{...E(e),type:"custom",properties:{...t,customId:r}}},me=e=>{var t;const r={...e,fields:e.fields.map(e=>e.id?e:{...e,id:u()})};return{...E(r),type:"form",properties:{answered:!1,formType:(null==(t=r.properties.lc2)?void 0:t.form_type)||null,fields:ae("",r).fields,formId:r.formId.replace(/_[0-9]+/,"")}}},ge=e=>{var t;return{...E(e),type:"form",properties:{answered:!0,formId:e.formId,formType:(null==(t=e.properties.lc2)?void 0:t.form_type)||null,fields:e.fields.filter(e=>"answer"in e||"answers"in e&&0!==e.answers.length).map(e=>{if("string"==typeof e.answer)return e;if("answers"in e){const{answers:t,...r}=e;return{...r,answer:t.map(e=>{let{label:t}=e;return t})}}return{...e,answer:e.answer.label}})}}},ye=e=>{switch(e.systemMessageType){case"archived_customer_disconnected":case"routing.archived_inactive":return G({...e,systemMessageType:"client_inactive"});case"manual_archived_agent":return G({...e,systemMessageType:"operator_closed_session",textVars:{operator:e.textVars.agent}});case"manual_archived_customer":return G({...e,systemMessageType:"chat_closed_by_customer"});case"system_archived":case"customer_banned":case"routing.archived_deleted":case"routing.archived_disconnected":case"routing.archived_offline":case"routing.archived_other":case"routing.archived_remotely_signed_out":case"routing.archived_signed_out":return G({...e,systemMessageType:"chat_session_closed"});case"routing.assigned_other":return G({...e,systemMessageType:"user_transfer",textVars:{operator:e.textVars.agent}});case"routing.assigned_deleted":case"routing.assigned_disconnected":case"routing.assigned_inactive":case"routing.assigned_remotely_signed_out":case"routing.assigned_signed_out":return G({...e,systemMessageType:"user_transfer",textVars:{operator:e.textVars.agent_added}});case"chat_transferred":return G({...e,systemMessageType:"user_transfer",textVars:{operator:e.textVars.targets}});case"agent_joined":case"agent_added":return G({...e,systemMessageType:"operator_joined_conference",textVars:{operator:e.textVars.agent}});case"agent_left":case"agent_removed":return G({...e,systemMessageType:"operator_left_conference",textVars:{operator:e.textVars.agent}});case"rating.chat_rated":return G({...e,systemMessageType:"rate_me_confirmation_"+e.textVars.score});case"rating.chat_commented":return G({...e,systemMessageType:"rate_me_comment_added",textVars:{comment:e.textVars.comment}});case"rating.chat_rating_canceled":return G({...e,systemMessageType:"rate_me_cancel"});case"custom":{const{systemMessageType:t,...r}=e;return G(r)}default:return null}},he=e=>{const{score:t,comment:r}=e;return{..."number"==typeof t&&{rate:1===t?"good":"bad"},..."string"==typeof r&&{rateComment:r}}},fe=e=>({position:e.position,waitingTime:e.waitTime}),ve=e=>({..."rating"in e.properties&&he(e.properties.rating),...e.queue&&{queue:fe(e.queue)},timestamp:new Date(e.createdAt).getTime()}),_e=(e,t)=>{const r={event:ce(e,t.event),author:{...t.agent,type:"agent"}};var s;return r.event.properties={...r.event.properties,invitation:!0,id:t.id,addon:t.addon,uniqueId:t.uniqueId,accepted:t.accepted,type:(s=r.event,s.properties.quickReplies?"quick_replies":"rich_message"===s.type?"card":"plain_text"),subtype:t.subtype,receivedFirstTime:t.displayedFirstTime,isExitIntent:t.isExitIntent},r},be=(e,t)=>{const{type:r,id:s}=t;switch(r){case"filled_form":{const{formId:e,...r}=t;return{customId:r.customId,formId:e,...r}}case"emoji":case"message":case"message_draft":case"url_preview":{const{text:r,triggeredBy:a}=t.properties,n={type:"message",customId:s,text:r};if(a){const t=e.getEvent(c,a.event);t&&t.thread&&t.serverId?n.postback={id:a.button.postbackId,type:"message",value:a.button.value,eventId:t.serverId,threadId:t.thread}:n.properties={c5e4f61e1a6c3b1521b541bc5c5a2ac5:{postback_id:a.button.postbackId}}}return n}case"custom_system_message":{const{recipients:e,text:r}=t.properties;return{type:"system_message",customId:s,text:r,recipients:e,systemMessageType:"custom"}}default:return}},Ie=(e,t)=>{if(t.id===e.getSessionUser().serverId||"customer"===t.type){const e={id:t.id,type:"customer"};return t.name&&"Customer"!==t.name&&(e.name=t.name),t.email&&(e.email=t.email),t.sessionFields&&(e.properties=t.sessionFields),e}return{id:t.id,type:t.type,name:t.name,avatar:t.avatar?"https://"+m(t.avatar):"",properties:{jobTitle:t.jobTitle,isBot:t.isBot||!1}}},xe=e=>({sourceLangCode:e.source_lang_code,targetLangCode:e.target_lang_code,targetMessage:e.target_message}),Te=(e,t)=>{const r=S(e,c);return r?{...t,events:t.events.map(e=>e.properties.welcomeMessage||e.properties.invitation?{...e,id:r.id}:e)}:t},we=e=>({...e,properties:{...e.properties,accepted:!0}}),ke=(e,t)=>{let{sdk:r}=e;const{uniqueId:s,id:a}=t.event.properties;return r.acceptGreeting({greetingId:a,uniqueId:s}).then(()=>we(t),e=>{if("INTERNAL"===e.code)return we(t);throw e})},Me=function(e,t){var s;let{sdk:a,store:n}=e,{group:i,customerStartingEvent:o,agentFakeEvent:p}=void 0===t?{}:t;const l={chat:{thread:{properties:{}},properties:{}}};h(n)&&(l.continuous=!0,l.chat.properties.routing={email_follow_up:!0}),"number"==typeof i&&(l.chat.access={groupIds:[i]});let u={};if("filled_form"===(null==o?void 0:o.type)){var d,m;u={...f(Boolean,{name:null==(d=r(e=>"name"===e.type,o.fields))?void 0:d.answer,email:null==(m=r(e=>"email"===e.type,o.fields))?void 0:m.answer})}}const g=n.getSessionUser();g.name&&"Customer"!==g.name||(u.name=n.localize("client"));const y=v(u)?Promise.resolve():a.updateCustomer(u).catch(e=>_("update_customer_request_failed",e));if("ticket"===(null==o||null==(s=o.properties.lc2)?void 0:s.form_type))l.active=!1,l.chat.thread.properties.routing={offline_message:!0},l.chat.thread.events=[be(n,o)];else{const e=n.getEvents(c).filter(e=>e.type===b&&null===e.serverId);if(v(e)||(l.chat.thread.events=e.map(e=>be(n,e))),o){const e=be(n,o);j(l.chat.thread.events)?l.chat.thread.events.push(e):l.chat.thread.events=[e]}p&&(l.chat.thread.properties=(e=>({lc2:{welcome_author_id:e.author,...e.properties.invitation?{greeting_id:e.properties.id,greeting_unique_id:e.properties.uniqueId}:{welcome_text:e.properties.originalText}}}))(p))}const I=n.getChat(c).serverId;return I?y.then(()=>a.resumeChat({...l,chat:{...l.chat,id:I}})).then(e=>Te(n,se(n,e))):y.then(()=>a.startChat(l)).then(e=>Te(n,se(n,e)))},Se=e=>{let{sdk:t}=e;return t.listChats().then(e=>{let{chatsSummary:t}=e;const r=d(t);return r?(e=>{let{id:t,active:r,access:s,lastThreadId:a}=e;return{id:t,active:r,lastThreadId:a,group:te(s)}})(r):null})},Ue=(e,t)=>{let{sdk:r}=e,{groupIds:s}=t;return r.listGroupStatuses({groupIds:s}).then(e=>s.reduce((t,r)=>{const s=e[r];return t[r]=s?(e=>"offline"===e?"offline":"online")(s):"not_found",t},{}))},qe=(e,t)=>{let{groupId:r}=t;return Ue(e,{groupIds:[r]}).then(e=>{let{[r]:t}=e;return t})},je=(e,t)=>{let{store:r}=e;return U({organizationId:t.organizationId,licenseId:r.getApplicationState().license,groupId:t.groupId,region:t.region,version:t.localizationVersion,language:t.language})},Ve=function(e,t,r){let{sdk:s}=e;return void 0===r&&(r=ae),s.getForm(t).then(e=>e.enabled?{enabled:!0,form:r(t.type,e.form)}:e).catch(e=>(_("get_form_request_failed",e),{enabled:!1}))},Ce=e=>{let{sdk:t,store:r}=e;return t.getPredictedAgent().then(e=>{let{agent:t,queue:s}=e;const a=r.localize("welcome_to_chat");return{agent:t,groupHasQueue:s,message:L((n={id:I(r.getIndexedEvents(c)),type:"message",authorId:t.id,text:x(r,a,{agent:t.name}),originalText:a,welcomeMessage:!0},{...n,serverId:null,timestamp:Date.now(),seen:!0,properties:n.properties||{}}))};var n})},Be=(e,t)=>Ve(e,{groupId:t,type:"postchat"}),Fe=(e,t)=>Ve(e,{groupId:t,type:"ticket"},(e,t)=>ne(t)),Ae=(e,t)=>{let{store:r}=e,{groupId:s}=t;const{license:a,region:n,organizationId:i}=r.getApplicationState();return T({organizationId:i,licenseId:a,groupId:s,region:n,version:"tfm"}).then(e=>e.__unsafeProperties.ticketFormMode||w(e))},Ee=(e,t)=>{let{sdk:r}=e,{chatId:s}=t;return r.getChat({chatId:s}).then(e=>{let{users:t,eventsSeenUpToMap:r}=e;return{users:t,eventsSeenUpToMap:r}})},De=(e,t)=>{let{sdk:r,store:s}=e,{chatId:a,threadId:n}=t;return r.getChat({chatId:a,threadId:n}).then(e=>le(s,{thread:e.thread,users:e.users,eventsSeenUpToMap:e.eventsSeenUpToMap}))},Oe=(e,t)=>t.next().then(t=>{let{value:r,done:s}=t;return r?{value:r.threads.map(t=>((e,t)=>{let{thread:r}=t;const{id:s,active:a,events:n,access:i}=r,{eventsSeenUpToMap:o}=e.getChat(c).properties,p=e.getSessionUser().serverId,{sessionUserSeenUpTo:l,latestOtherUserSeenUpTo:u}=ie(e,o);return pe(r)?{id:s,active:a,events:oe(n).map(t=>{const r=t.authorId===p?u>=t.createdAt:l>=t.createdAt;return ce(e,{...t,seen:r})}).filter(Boolean),group:te(i),properties:ve(r)}:null})(e,{thread:t})),done:s}:{value:r,done:s}}).catch(e=>{if("NOT_FOUND"===e.code)return{value:[],done:!0};throw e}),ze=(e,t)=>{let{sdk:r,store:s}=e;const a=r.getChatHistory({chatId:t});return{next:()=>Oe(s,a)}},Le=(e,t)=>{let{sdk:r,store:s}=e;const a=r.getChatHistory({chatId:t});return Promise.all([a.next(),Ee({sdk:r,store:s},{chatId:t})]).then(e=>{let[{value:t,done:r},{users:n,eventsSeenUpToMap:i}]=e;const o=k("id",n);if(t&&t.threads.some(e=>e.events.some(e=>"system"!==e.authorId&&!(e.authorId in o)))){const e=new Error;throw e.code="MISSING_USER",e}return{threads:t&&t.threads.map(e=>le(s,{thread:e,users:n,eventsSeenUpToMap:i}).thread).filter(Boolean),eventsSeenUpToMap:i,hasMore:!r,iterator:{next:()=>Oe(s,a)}}}).catch(e=>{if("NOT_FOUND"===e.code)return{threads:[],hasMore:!1};throw e})},Ne=async(e,t)=>{const r=await M("https://api.helpdesk.com/v1/contactForms/formSettings?lcLicenseID="+e+"&lcGroupID="+t);if(!r.ok)throw new Error("Failed to fetch HelpDesk ticket form configuration");return r.json()};export{Ue as A,be as B,ne as a,he as b,fe as c,xe as d,_e as e,Ne as f,se as g,Y as h,qe as i,Fe as j,Ae as k,Se as l,ce as m,Me as n,Ce as o,ae as p,Le as q,Q as r,ze as s,J as t,Be as u,ke as v,Ie as w,je as x,De as y,$ as z};