import{f as Ke}from"./chunk-MZH7I7UK.js";import{a as z}from"./chunk-7CAH5JY2.js";import{a as Je}from"./chunk-2C3QPSQO.js";import{a as ce}from"./chunk-R6EOTM56.js";import{a as de}from"./chunk-NOQGKTKU.js";import{h as We,i as je,k as Ze}from"./chunk-7ZRO5KWR.js";import{a as H}from"./chunk-UACQJK7R.js";import{N as ne,W as b,X as Ve,Y as qe,_ as Ue,da as Qe,ea as se,ja as F,v as A}from"./chunk-Q232IBQN.js";import{c as Be,d as $e,g as De,h as re,i as le,j as _e}from"./chunk-LGT7QKWT.js";import{Aa as oe,B as xe,Ba as ae,Q as ye}from"./chunk-E4UUPK46.js";import{F as ze,L as Xe,c as we,i as Le,j as Ge,l as ke,p as Ye,q as Fe}from"./chunk-WWNBTMQ7.js";import{$c as B,Ac as I,Ad as ie,Da as M,Dd as $,Ea as N,Ec as g,Ed as v,Fc as Ae,Fd as ve,Gc as Ee,H as J,Ic as h,Ja as ee,Kc as c,Ob as L,Pa as p,Q as ue,Sa as ge,Sc as Me,Tb as fe,Tc as Ne,Uc as G,Wc as te,X as y,Zc as P,_c as U,cd as be,dd as Re,e as j,ed as Ie,ga as K,ha as Se,hc as Te,j as Z,ja as me,jc as u,ke as He,lc as S,mc as Oe,oc as D,pc as w,qc as f,rc as o,rd as k,sa as he,sc as r,tc as C,td as Y,wb as _,xa as T,zd as Pe}from"./chunk-O7RN3KYY.js";import{a as x}from"./chunk-ZE2KCNEA.js";import{a as Q,b as W}from"./chunk-CEWFFWI2.js";x();x();function nt(t,l){t&1&&(o(0,"p"),g(1,6),r())}function ot(t,l){if(t&1&&(o(0,"p"),g(1,7),r()),t&2){let e=c(2);_(),Ae(e.maxLength),Ee(1)}}function at(t,l){if(t&1&&(o(0,"div",22),u(1,nt,2,0,"p")(2,ot,2,1,"p"),r()),t&2){c();let e=G(10);_(),S(e.errors!=null&&e.errors.required?1:e.errors!=null&&e.errors.maxLength?2:-1)}}var rt=50,Ce=(()=>{class t{constructor(){this.dialogRef=T(Be),this.data=T($e),this.maxLength=rt,this.title=this.data.initialTitle}submit(){let e=this.title.trim();!e||e.length>this.maxLength||this.dialogRef.close(e)}cancel(){this.dialogRef.close()}static{this.\u0275fac=function(n){return new(n||t)}}static{this.\u0275cmp=L({type:t,selectors:[["rename-conversation-dialog"]],decls:23,vars:6,consts:()=>{let e;e=$localize`Rename Chat`;let n;n=$localize`Chat name`;let i;i=$localize`Cancel`;let a;a=$localize`Save`;let s;s=$localize`Chat name is required`;let m;return m=$localize`Chat name must be ${"\uFFFD0\uFFFD"}:INTERPOLATION: characters or fewer`,[["form","ngForm"],["titleControl","ngModel"],e,n,i,a,s,m,[1,"flex-no-shrink","d-flex","pa-8"],[1,"h2","pt-16","px-16","flex-grow"],[3,"clicked"],[1,"dialog-content","mt-24"],[1,"px-24","pb-24",3,"ngSubmit"],["for","rename-chat-title",1,"form-label","required"],["type","text","id","rename-chat-title","name","title","autocomplete","off","required","","cdkFocusInitial","",1,"form-control","w-100",3,"ngModelChange","lazyMaxlength","ngModel"],[1,"d-flex","flex-wrap","form-text","mt-4"],["class","is-invalid",4,"ifInvalid"],[1,"ml-auto",3,"maxLength","string"],[1,"d-flex","flex-no-shrink","mt-24"],[1,"d-flex","ml-auto"],["type","button",1,"btn","md","secondary","mr-12",3,"click"],["type","submit",1,"btn","md","primary",3,"disabled"],[1,"is-invalid"]]},template:function(n,i){if(n&1){let a=I();o(0,"div",8)(1,"h2",9),g(2,2),r(),o(3,"close-button",10),h("clicked",function(){return i.cancel()}),r()(),o(4,"div",11)(5,"form",12,0),h("ngSubmit",function(){return i.submit()}),o(7,"label",13),g(8,3),r(),o(9,"input",14,1),Ie("ngModelChange",function(m){return M(a),Re(i.title,m)||(i.title=m),N(m)}),r(),o(11,"div",15)(12,"div"),fe(13,at,3,1,"div",16),r(),C(14,"characters-left",17),r(),o(15,"div",18)(16,"div",19)(17,"button",20),h("click",function(){return i.cancel()}),o(18,"span"),g(19,4),r()(),o(20,"button",21)(21,"span"),g(22,5),r()()()()()()}if(n&2){let a=G(6),s=G(10);_(9),f("lazyMaxlength",i.maxLength),be("ngModel",i.title),_(4),f("ifInvalid",s),_(),f("maxLength",i.maxLength)("string",i.title),_(6),f("disabled",a.invalid||!i.title.trim())}},dependencies:[De,Xe,Fe,we,Le,Ge,ze,Ye,ke,qe,Ve,Je],encapsulation:2,changeDetection:0})}}return t})();var lt=(t,l)=>l.public_id;function _t(t,l){if(t&1){let e=I();o(0,"button",22),h("click",function(){M(e);let i=c();return N(i.close())}),C(1,"icon",23),r()}}function st(t,l){t&1&&C(0,"loader",20)}function ct(t,l){t&1&&C(0,"no-item",21)}function dt(t,l){t&1&&C(0,"icon",29)}function Ct(t,l){t&1&&C(0,"loader",31),t&2&&f("size",16)}function mt(t,l){t&1&&C(0,"icon",32)}function Tt(t,l){t&1&&(C(0,"icon",35),o(1,"span"),g(2,5),r())}function pt(t,l){t&1&&(C(0,"icon",36),o(1,"span"),g(2,6),r())}function ut(t,l){if(t&1){let e=I();o(0,"div",26)(1,"button",27),h("click",function(){let i=M(e),a=i.$implicit,s=i.$index,m=c(2);return N(m.selectConversation(a,s))}),o(2,"span",28),P(3),r(),u(4,dt,1,0,"icon",29),r(),o(5,"button",30),u(6,Ct,1,1,"loader",31)(7,mt,1,0,"icon",32),r(),o(8,"pfy-menu",null,0)(10,"button",33),h("click",function(){let i=M(e).$implicit,a=c(2);return N(a.togglePin(i,"sidebar"))}),u(11,Tt,3,0)(12,pt,3,0),r(),o(13,"button",33),h("click",function(){let i=M(e).$implicit,a=c(2);return N(a.renameChat(i,"sidebar"))}),C(14,"icon",34),o(15,"span"),g(16,4),r()()()()}if(t&2){let e=l.$implicit,n=G(9),i=c(2);te("active",e.public_id===i.currentPublicId()),_(),te("text-normal",e.public_id!==i.currentPublicId()),f("title",e.title||i.resumeChatLabel),Te("aria-current",e.public_id===i.currentPublicId()?"true":null),_(2),B(" ",e.title||i.newChatLabel," "),_(),S(e.pinned_at?4:-1),_(),f("pfyMenuTriggerFor",n),_(),S(i.isPinning(e.public_id)?6:7),_(5),S(e.pinned_at?11:12)}}function St(t,l){t&1&&C(0,"loader",20)}function ht(t,l){if(t&1&&(o(0,"div",24),D(1,ut,17,11,"div",25,lt),r(),u(3,St,1,0,"loader",20)),t&2){let e=c();_(),w(e.conversations()),_(2),S(e.loadingMore()?3:-1)}}var Mi=(()=>{class t{constructor(){this.chatbotService=T(z),this.usersService=T(se),this.analyticsService=T(F),this.liveAnnouncer=T(xe),this.dialogService=T(re),this.snackbarService=T(ne),this.destroyRef=T(ee),this.currentPublicId=v(null),this.chatbotAvatar=v(null),this.chatbotName=v.required(),this.fallbackIcon=v("common-chatbot"),this.isMobile=v(!1),this.closable=v(!0),this.searchActive=v(!1),this.selected=$(),this.conversationUpdated=$(),this.newChatRequested=$(),this.closeRequested=$(),this.searchToggled=$(),this.conversations=p([]),this.loadingConversations=p(!0),this.nextOffset=p(0),this.loadingMore=p(!1),this.resumeChatLabel=$localize`:Tooltip on a sidebar conversation row that has not yet had a title generated:Resume chat`,this.newChatLabel=$localize`:Default placeholder for an untitled conversation:New Chat`,this.pinningPublicIds=p(new Set),this.cancelMessagesFetch=new j}static{this.PAGE_SIZE=30}ngOnInit(){this.usersService.isAuthenticated()?this.refresh():this.loadingConversations.set(!1)}refresh(){this.fetchPage(0,!0)}applyConversationUpdate(e){this.conversations.update(n=>n.map(i=>i.public_id===e.public_id?e:i))}fetchMore(){let e=this.nextOffset();e!==null&&this.fetchPage(e,!1)}fetchPage(e,n){this.loadingMore()||(this.loadingMore.set(!0),this.chatbotService.listConversations({limit:t.PAGE_SIZE,offset:e},{user:this.usersService.userData().id,has_messages:!0}).pipe(H(this.destroyRef)).subscribe(({results:i,next:a})=>{this.conversations.update(s=>n?i:[...s,...i]),this.loadingConversations.set(!1),this.loadingMore.set(!1),this.nextOffset.set(a?e+i.length:null)}))}selectConversation(e,n){this.cancelMessagesFetch.next(),this.chatbotService.getConversationMessages({conversation:e.id,pagination_method:"cursor"}).pipe(H(this.destroyRef),Se(this.cancelMessagesFetch)).subscribe(({results:a,next:s})=>{let m=[...a].reverse();this.selected.emit({conversation:e,messages:m,nextOlderUrl:s??null});let d=e.title||this.newChatLabel;this.liveAnnouncer.announce($localize`:Live announcement when a sidebar conversation is opened:Opened conversation: ${d}:title:`)});let i=Math.floor(A.now().diff(A.from(e.conversation_start),"days"));this.analyticsService.analyticsEvent({type:b.CHATBOT_HISTORY_ITEM_SELECTED,properties:{days_since_creation:i,list_position:n,is_pinned:!1,view_type:this.isMobile()?"mobile_drawer":"desktop_sidebar"}})}newChat(){this.newChatRequested.emit()}toggleSearch(){this.searchToggled.emit()}close(){this.closeRequested.emit()}isPinning(e){return this.pinningPublicIds().has(e)}togglePin(e,n){if(this.isPinning(e.public_id))return;let i=e.pinned_at===null,a=et(e.conversation_start,A.now()),s=e.pinned_at!==null?et(e.pinned_at,A.now()):0;this.pinningPublicIds.update(d=>new Set(d).add(e.public_id)),(i?this.chatbotService.pinConversation(e.public_id):this.chatbotService.unpinConversation(e.public_id)).pipe(y(()=>this.pinningPublicIds.update(d=>{let O=new Set(d);return O.delete(e.public_id),O})),H(this.destroyRef)).subscribe(d=>{this.conversationUpdated.emit(d),this.refresh(),this.snackbarService.success(i?$localize`:Snackbar after pinning a chat:Chat pinned`:$localize`:Snackbar after unpinning a chat:Chat unpinned`),this.analyticsService.analyticsEvent(i?{type:b.CHATBOT_HISTORY_ITEM_PINNED,properties:{location:n,days_since_creation:a}}:{type:b.CHATBOT_HISTORY_ITEM_UNPINNED,properties:{location:n,time_spent_pinned_days:s}})})}renameChat(e,n){let i=!!e.title&&e.title_is_autogenerated,a=e.title||this.newChatLabel;this.dialogService.smallDialog(Ce,{data:{initialTitle:a}}).closed.pipe(J(s=>!!s&&s!==e.title),H(this.destroyRef)).subscribe(s=>{this.chatbotService.renameConversation(e.public_id,s).pipe(H(this.destroyRef)).subscribe(m=>{this.conversationUpdated.emit(m),this.conversations.update(d=>d.map(O=>O.public_id===m.public_id?m:O)),this.snackbarService.success($localize`:Snackbar after renaming a chat:Chat has been renamed`),this.analyticsService.analyticsEvent({type:b.CHATBOT_HISTORY_ITEM_RENAMED,properties:{location:n,new_title_length:s.length,was_auto_generated:i}})})})}static{this.\u0275fac=function(n){return new(n||t)}}static{this.\u0275cmp=L({type:t,selectors:[["chatbot-history-sidebar"]],inputs:{currentPublicId:[1,"currentPublicId"],chatbotAvatar:[1,"chatbotAvatar"],chatbotName:[1,"chatbotName"],fallbackIcon:[1,"fallbackIcon"],isMobile:[1,"isMobile"],closable:[1,"closable"],searchActive:[1,"searchActive"]},outputs:{selected:"selected",conversationUpdated:"conversationUpdated",newChatRequested:"newChatRequested",closeRequested:"closeRequested",searchToggled:"searchToggled"},decls:22,vars:11,consts:()=>{let e;e=$localize`Close chat menu`;let n;n=$localize`Close`;let i;i=$localize`Start a new chat to see it here.`;let a;a=$localize`New Chat`;let s;s=$localize`Search`;let m;m=$localize`Chats`;let d;d=$localize`Pinned`;let O;O=$localize`Chat options`;let X;X=$localize`Rename`;let V;V=$localize`Unpin`;let q;return q=$localize`:verb:Pin`,[["sidebarChatMenu",""],a,s,m,X,V,q,[1,"d-flex","align-items-center","gap-4","pl-12","pr-8","py-8","py-lg-12"],[1,"d-flex","align-items-center","gap-12","flex-grow","minw-0"],[1,"avatar","size-32"],[3,"fallbackIcon","manualOverrideSrc"],[1,"text-bold","text-truncate"],["type","button","aria-label",e,"tooltip",n,"cdkFocusInitial","",1,"btn","md","borderless"],[1,"pa-8","d-flex","flex-column","gap-4"],["type","button",1,"btn","md","borderless","w-100","justify-content-start",3,"click"],["name","common-comment-plus","aria-hidden","true",1,"size-20"],[1,"text-lg","text-base","text-normal","pl-4"],["name","common-search","aria-hidden","true",1,"size-20"],["scrollFade","","scrollFadeDistance","3%","infiniteScroll","",1,"flex-grow","minh-0","scroll-y","pa-8","pb-40","d-flex","flex-column",3,"scrolled","scrollWindow","infiniteScrollDisabled","fetchUntilScrollable"],[1,"px-12","py-8","mb-0","text-bold"],["padding","icon"],["message",i,1,"d-block","px-12","py-8","text-md"],["type","button","aria-label",e,"tooltip",n,"cdkFocusInitial","",1,"btn","md","borderless",3,"click"],["name","internal-chevron-left"],["role","list",1,"flex-grow"],["role","listitem",1,"chat-row","d-flex","align-items-center","gap-4","pr-8","pr-md-4","flex-no-shrink",3,"active"],["role","listitem",1,"chat-row","d-flex","align-items-center","gap-4","pr-8","pr-md-4","flex-no-shrink"],["type","button",1,"btn","borderless","flex-grow","justify-content-start","chat-row-main","minw-0","pl-8","pr-12","py-8",3,"click","title"],[1,"flex-grow","text-truncate","minw-0","text-lg","text-base"],["name","common-pin-outline","aria-label",d,1,"size-16","flex-no-shrink","text-quiet"],["type","button","tooltip",O,1,"btn","sm","borderless","chat-options-trigger","flex-no-shrink",3,"pfyMenuTriggerFor"],["padding","none",3,"size"],["name","internal-more"],["pfy-menu-item","","type","button",3,"click"],["name","internal-edit"],["name","common-pin-off"],["name","common-pin-outline"]]},template:function(n,i){n&1&&(o(0,"div",7)(1,"div",8)(2,"div",9),C(3,"profile-pic",10),r(),o(4,"h3",11),P(5),r()(),u(6,_t,2,0,"button",12),r(),o(7,"div",13)(8,"button",14),h("click",function(){return i.newChat()}),C(9,"icon",15),o(10,"span",16),g(11,1),r()(),o(12,"button",14),h("click",function(){return i.toggleSearch()}),C(13,"icon",17),o(14,"span",16),g(15,2),r()()(),o(16,"div",18),h("scrolled",function(){return i.fetchMore()}),o(17,"h4",19),g(18,3),r(),u(19,st,1,0,"loader",20)(20,ct,1,0,"no-item",21)(21,ht,4,1),r()),n&2&&(_(3),f("fallbackIcon",i.fallbackIcon())("manualOverrideSrc",i.chatbotAvatar()),_(2),U(i.chatbotName()),_(),S(i.closable()?6:-1),_(6),te("pressed",i.searchActive()),Te("aria-pressed",i.searchActive()),_(4),f("scrollWindow",!1)("infiniteScrollDisabled",i.loadingMore()||i.nextOffset()===null)("fetchUntilScrollable",i.conversations().length),_(3),S(i.loadingConversations()?19:i.conversations().length===0?20:21))},dependencies:[ce,ae,de,_e,le,je,We,Ze,Qe,oe,Ke],styles:["[_nghost-%COMP%]{display:flex;flex-direction:column;flex:1 1 0;min-height:0}.chat-row[_ngcontent-%COMP%]{border-radius:var(--border-radius-base)}@media(max-width:879px){.chat-row[_ngcontent-%COMP%]{height:48px}}.chat-row[_ngcontent-%COMP%]:hover, .chat-row[_ngcontent-%COMP%]:focus-within, .chat-row[_ngcontent-%COMP%]:has(.chat-options-trigger[aria-expanded=true]){background:var(--n1-transp)}.chat-row.active[_ngcontent-%COMP%]{background:var(--n2-transp)}.chat-row[_ngcontent-%COMP%] .chat-row-main[_ngcontent-%COMP%]:hover, .chat-row[_ngcontent-%COMP%] .chat-row-main[_ngcontent-%COMP%]:active, .chat-row[_ngcontent-%COMP%] .chat-row-main.pressed[_ngcontent-%COMP%]{background:transparent!important}.chat-row[_ngcontent-%COMP%] .chat-row-main.btn[_ngcontent-%COMP%]{padding-right:0}@media(min-width:880px){.chat-options-trigger[_ngcontent-%COMP%]{display:none}.chat-row[_ngcontent-%COMP%]:hover .chat-options-trigger[_ngcontent-%COMP%], .chat-row[_ngcontent-%COMP%]:focus-within .chat-options-trigger[_ngcontent-%COMP%], .chat-row.active[_ngcontent-%COMP%] .chat-options-trigger[_ngcontent-%COMP%], .chat-row[_ngcontent-%COMP%]:has(.chat-options-trigger[aria-expanded=true]) .chat-options-trigger[_ngcontent-%COMP%]{display:inline-flex}}"],changeDetection:0})}}return t})();function et(t,l){return Math.floor(l.diff(A.from(t),"days"))}x();var gt=["searchInput"],tt=(t,l)=>l.public_id,ft=(t,l)=>l.label;function Ot(t,l){t&1&&(o(0,"div",5),C(1,"loader",12),r())}function At(t,l){t&1&&C(0,"no-item",10)}function Et(t,l){if(t&1&&(o(0,"mark",20),P(1),r()),t&2){let e=c().$implicit;_(),U(e.text)}}function Mt(t,l){if(t&1&&(o(0,"span",21),P(1),r()),t&2){let e=c().$implicit;_(),U(e.text)}}function Nt(t,l){if(t&1&&u(0,Et,2,1,"mark",20)(1,Mt,2,1,"span",21),t&2){let e=l.$implicit;S(e.isMatch?0:1)}}function bt(t,l){if(t&1&&(o(0,"div",17),P(1),k(2,"i18nPlural"),r()),t&2){let e=c().$implicit,n=c(3);_(),B(" ",Y(2,1,e.match_count,n.contentMatchesPluralMap)," ")}}function Rt(t,l){t&1&&C(0,"icon",18)}function It(t,l){if(t&1){let e=I();o(0,"button",15),h("click",function(){let i=M(e).$implicit,a=c(3);return N(a.selectConversation(i))}),o(1,"span",16)(2,"div"),D(3,Nt,2,1,null,null,Oe),r(),u(5,bt,3,4,"div",17),r(),u(6,Rt,1,0,"icon",18),o(7,"span",19),k(8,"dateFormat"),P(9),k(10,"dateFormat"),r()()}if(t&2){let e=l.$implicit,n=c(3);_(3),w(n.titleSegments(e.title||n.newChatLabel)),_(2),S(e.match_count>0?5:-1),_(),S(e.pinned_at?6:-1),_(),f("tooltip",Y(8,4,e.latest_message_timestamp,"MMM D, YYYY h:mm a")),_(2),B(" ",Y(10,7,e.latest_message_timestamp,"MMM D")," ")}}function Pt(t,l){t&1&&C(0,"loader",12)}function vt(t,l){if(t&1){let e=I();o(0,"div",13),h("scrolled",function(){M(e);let i=c(2);return N(i.fetchMoreFilter())}),D(1,It,11,10,"button",14,tt),u(3,Pt,1,0,"loader",12),r()}if(t&2){let e=c(2);f("scrollWindow",!1)("infiniteScrollDisabled",e.filterLoadingMore()||e.filterLoading()||e.filterNextOffset()===null)("fetchUntilScrollable",e.filterResults().length),_(),w(e.filterResults()),_(2),S(e.filterLoadingMore()?3:-1)}}function Ht(t,l){if(t&1&&u(0,Ot,2,0,"div",5)(1,At,1,0,"no-item",10)(2,vt,4,4,"div",11),t&2){let e=c();S(e.filterLoading()?0:e.filterResults().length===0?1:2)}}function xt(t,l){t&1&&(o(0,"div",22),C(1,"loader",12),r())}function yt(t,l){if(t&1){let e=I();o(0,"no-item",23)(1,"button",25),h("click",function(){M(e);let i=c(2);return N(i.chatbotService.requestNewChat())}),C(2,"icon",26),o(3,"span"),g(4,3),r()()()}}function Bt(t,l){t&1&&C(0,"icon",31)}function $t(t,l){if(t&1){let e=I();o(0,"button",15),h("click",function(){let i=M(e).$implicit,a=c(4);return N(a.selectConversation(i))}),o(1,"span",30),P(2),r(),u(3,Bt,1,0,"icon",31),o(4,"span",19),k(5,"dateFormat"),P(6),k(7,"dateFormat"),r()()}if(t&2){let e=l.$implicit,n=c(4);_(2),B(" ",e.title||n.newChatLabel," "),_(),S(e.pinned_at?3:-1),_(),f("tooltip",Y(5,4,e.latest_message_timestamp,"MMM D, YYYY h:mm a")),_(2),B(" ",Y(7,7,e.latest_message_timestamp,"MMM D")," ")}}function Dt(t,l){if(t&1&&(o(0,"div")(1,"h3",28),P(2),r(),o(3,"div",29),D(4,$t,8,10,"button",14,tt),r()()),t&2){let e=l.$implicit,n=c(3);_(2),B(" ",n.timeBucketLabel(e.label)," "),_(2),w(e.conversations)}}function wt(t,l){t&1&&C(0,"loader",12)}function Lt(t,l){if(t&1){let e=I();o(0,"div",27),h("scrolled",function(){M(e);let i=c(2);return N(i.fetchMore())}),D(1,Dt,6,1,"div",null,ft),u(3,wt,1,0,"loader",12),r()}if(t&2){let e=c(2);f("scrollWindow",!1)("infiniteScrollDisabled",e.loadingMore()||e.nextOffset()===null)("fetchUntilScrollable",e.conversations().length),_(),w(e.groups()),_(2),S(e.loadingMore()?3:-1)}}function Gt(t,l){if(t&1&&u(0,xt,2,0,"div",22)(1,yt,5,0,"no-item",23)(2,Lt,4,4,"div",24),t&2){let e=c();S(e.loadingInitial()?0:e.conversations().length===0?1:2)}}var Ui=(()=>{class t{static{this.PAGE_SIZE=30}static{this.MIN_QUERY_LENGTH=3}constructor(){this.chatbotService=T(z),this.usersService=T(se),this.analyticsService=T(F),this.destroyRef=T(ee),this.active=v(!1),this.conversationSelected=$(),this.conversations=p([]),this.loadingInitial=p(!1),this.loadingMore=p(!1),this.nextOffset=p(0),this.query=p(""),this.trimmedQuery=ie(()=>this.query().trim()),this.committedQuery=p(""),this.filterMode=ie(()=>this.trimmedQuery().length>=t.MIN_QUERY_LENGTH&&this.committedQuery().length>=t.MIN_QUERY_LENGTH),this.filterResults=p([]),this.filterLoading=p(!1),this.filterLoadingMore=p(!1),this.filterNextOffset=p(null),this.searchRequestParams={user:this.usersService.userData().id,has_messages:!0,ordering:"-title_matches,-match_count,-latest_message_timestamp"},this.newChatLabel=$localize`:Default placeholder for an untitled conversation:New Chat`,this.groups=ie(()=>this.chatbotService.groupConversationsByTime(this.conversations(),A.now())),this.searchInput=ve("searchInput"),this.queryDebounced$=new j,this.contentMatchesPluralMap={"=1":$localize`1 content match`,other:$localize`:>1 content matches:# content matches`},ge(()=>{this.active()&&Pe(()=>{this.trimmedQuery().length===0&&this.fetchBrowsePage(0,!0),this.searchInput().nativeElement.focus()})}),this.queryDebounced$.pipe(ue(300),K(e=>{let n=e.trim();return n.lengththis.filterLoading.set(!1))))}),H(this.destroyRef)).subscribe(({results:e,next:n,count:i})=>{this.filterResults.set(e),this.filterNextOffset.set(n?e.length:null),this.analyticsService.analyticsEvent({type:b.CHATBOT_SEARCH_QUERY_SUBMITTED,properties:{query_length:this.committedQuery().length,results_count:i}})})}onQueryInput(e){this.query.set(e),this.queryDebounced$.next(e)}titleSegments(e){return ye(e,this.committedQuery()).segments}fetchMore(){let e=this.nextOffset();e!==null&&this.fetchBrowsePage(e,!1)}fetchBrowsePage(e,n){this.loadingMore()||this.loadingInitial()||(n&&this.conversations().length===0?this.loadingInitial.set(!0):n||this.loadingMore.set(!0),this.chatbotService.listConversations({limit:t.PAGE_SIZE,offset:e},{user:this.usersService.userData().id,has_messages:!0,ordering:"-latest_message_timestamp"}).pipe(H(this.destroyRef),y(()=>{this.loadingInitial.set(!1),this.loadingMore.set(!1)})).subscribe(({results:i,next:a})=>{this.conversations.update(s=>n?i:[...s,...i]),this.nextOffset.set(a?e+i.length:null)}))}fetchMoreFilter(){let e=this.filterNextOffset();if(e===null||this.filterLoadingMore()||this.filterLoading())return;let n=this.trimmedQuery();n.lengththis.filterLoadingMore.set(!1))).subscribe(({results:i,next:a})=>{this.trimmedQuery()===n&&(this.filterResults.update(s=>[...s,...i]),this.filterNextOffset.set(a?e+i.length:null))}))}selectConversation(e){let i=(this.filterMode()?this.filterResults():this.conversations()).findIndex(a=>a.public_id===e.public_id);this.analyticsService.analyticsEvent({type:b.CHATBOT_SEARCH_RESULT_SELECTED,properties:{days_since_creation:Math.floor(A.now().diff(A.from(e.conversation_start),"days")),title_match:e.title_matches,content_matches:e.match_count,result_position:i}}),this.conversationSelected.emit(e)}applyConversationUpdate(e){let n=i=>i.map(a=>a.public_id===e.public_id?W(Q({},e),{title_matches:a.title_matches,match_count:a.match_count}):a);this.conversations.update(n),this.filterResults.update(n)}timeBucketLabel(e){switch(e){case"last_7_days":return $localize`:Time bucket heading in AI Agent search browse view:Last 7 days`;case"last_30_days":return $localize`:Time bucket heading in AI Agent search browse view:Last 30 days`;case"this_year":return $localize`:Time bucket heading in AI Agent search browse view:This year`;case"older":return $localize`:Time bucket heading in AI Agent search browse view:Older`}}static{this.\u0275fac=function(n){return new(n||t)}}static{this.\u0275cmp=L({type:t,selectors:[["chatbot-search"]],viewQuery:function(n,i){n&1&&Me(i.searchInput,gt,5),n&2&&Ne()},inputs:{active:[1,"active"]},outputs:{conversationSelected:"conversationSelected"},decls:11,vars:2,consts:()=>{let e;e=$localize`Search for chats`;let n;n=$localize`Search`;let i;i=$localize`Search for chats`;let a;a=$localize`No matches`;let s;s=$localize`No conversations contain that phrase.`;let m;m=$localize`Pinned`;let d;d=$localize`Conversation is pinned`;let O;O=$localize`No Chats`;let X;X=$localize`Start a new chat to see it here.`;let V;V=$localize`New Chat`;let q;q=$localize`Pinned`;let E;return E=$localize`Conversation is pinned`,[["searchInput",""],n,i,V,[1,"d-flex","flex-column","flex-grow","minh-0","pt-16","pt-lg-80"],[1,"px-24"],[1,"h1","mb-12"],[1,"d-flex","align-items-center","gap-8","mb-8"],["for","chatbotSearchInput",1,"visually-hidden"],["id","chatbotSearchInput","type","search","autocomplete","off","maxlength","80","placeholder",e,1,"form-control","flex-grow",3,"input","value"],["logo","common-search","title",a,"message",s,1,"d-block","pa-40"],["infiniteScroll","",1,"flex-grow","minh-0","scroll-y","px-24","pb-40","pt-8","d-flex","flex-column","gap-4",3,"scrollWindow","infiniteScrollDisabled","fetchUntilScrollable"],["padding","icon"],["infiniteScroll","",1,"flex-grow","minh-0","scroll-y","px-24","pb-40","pt-8","d-flex","flex-column","gap-4",3,"scrolled","scrollWindow","infiniteScrollDisabled","fetchUntilScrollable"],["type","button",1,"btn","px-16","py-12","bg-n1","w-100","rounded-double","hoverable","align-items-center","gap-8","browse-row"],["type","button",1,"btn","px-16","py-12","bg-n1","w-100","rounded-double","hoverable","align-items-center","gap-8","browse-row",3,"click"],[1,"flex-grow","text-truncate","text-left","d-block"],[1,"text-sm","text-quiet"],["name","common-pin-outline","tooltip",m,"aria-label",d,1,"size-16","flex-no-shrink","text-quiet"],[1,"flex-no-shrink","text-quiet","text-sm",3,"tooltip"],[1,"mark-bold"],[1,"mx-0"],[1,"flex-grow","d-grid","place-content-center"],["logo","common-search","title",O,"message",X,1,"d-block","pa-40"],["infiniteScroll","",1,"flex-grow","minw-0","minh-0","scroll-y","px-24","pb-40","pt-8","d-flex","flex-column","gap-16",3,"scrollWindow","infiniteScrollDisabled","fetchUntilScrollable"],["type","button",1,"btn","primary","md","mt-12",3,"click"],["name","common-comment-plus","aria-hidden","true"],["infiniteScroll","",1,"flex-grow","minw-0","minh-0","scroll-y","px-24","pb-40","pt-8","d-flex","flex-column","gap-16",3,"scrolled","scrollWindow","infiniteScrollDisabled","fetchUntilScrollable"],[1,"py-8","text-md","text-quiet"],[1,"d-flex","flex-column","gap-4"],[1,"flex-grow","text-truncate","text-left"],["name","common-pin-outline","tooltip",q,"aria-label",E,1,"size-16","flex-no-shrink","text-quiet"]]},template:function(n,i){n&1&&(o(0,"div",4)(1,"div",5)(2,"h2",6),g(3,1),r(),o(4,"div",7)(5,"label",8),g(6,2),r(),o(7,"input",9,0),h("input",function(s){return i.onQueryInput(s.target.value)}),r()()(),u(9,Ht,3,1)(10,Gt,3,1),r()),n&2&&(_(7),f("value",i.query()),_(2),S(i.filterMode()?9:10))},dependencies:[de,ce,ae,_e,le,oe,Ue,He],styles:[".browse-row[_ngcontent-%COMP%]{transition:none}.browse-row[_ngcontent-%COMP%]:hover, .browse-row[_ngcontent-%COMP%]:focus-visible{box-shadow:inset 0 0 0 1px var(--border-color-base)}.is-tabbing[_nghost-%COMP%] .browse-row[_ngcontent-%COMP%]:hover, .is-tabbing [_nghost-%COMP%] .browse-row[_ngcontent-%COMP%]:hover, .is-tabbing[_nghost-%COMP%] .browse-row[_ngcontent-%COMP%]:focus-visible, .is-tabbing [_nghost-%COMP%] .browse-row[_ngcontent-%COMP%]:focus-visible{box-shadow:0 0 0 2px var(--white),0 0 0 4px var(--focus-outline-color)!important}"],changeDetection:0})}}return t})();x();var sn=(()=>{class t{constructor(){this.chatbotService=T(z),this.dialogService=T(re),this.snackbarService=T(ne),this.analyticsService=T(F),this.newChatLabel=$localize`:Default placeholder for an untitled conversation:New Chat`,this.pinningPublicIds=p(new Set)}isPinning(e){return this.pinningPublicIds().has(e)}togglePin(e,n){if(this.isPinning(e.public_id))return Z;let i=e.pinned_at===null,a=it(e.conversation_start,A.now()),s=e.pinned_at!==null?it(e.pinned_at,A.now()):0;return this.pinningPublicIds.update(d=>new Set(d).add(e.public_id)),(i?this.chatbotService.pinConversation(e.public_id):this.chatbotService.unpinConversation(e.public_id)).pipe(y(()=>this.pinningPublicIds.update(d=>{let O=new Set(d);return O.delete(e.public_id),O})),me(()=>{this.snackbarService.success(i?$localize`:Snackbar after pinning a chat:Chat pinned`:$localize`:Snackbar after unpinning a chat:Chat unpinned`),this.analyticsService.analyticsEvent(i?{type:b.CHATBOT_HISTORY_ITEM_PINNED,properties:{location:n,days_since_creation:a}}:{type:b.CHATBOT_HISTORY_ITEM_UNPINNED,properties:{location:n,time_spent_pinned_days:s}})}))}renameChat(e,n){let i=!!e.title&&e.title_is_autogenerated,a=e.title||this.newChatLabel;return this.dialogService.smallDialog(Ce,{data:{initialTitle:a}}).closed.pipe(J(s=>!!s&&s!==e.title),K(s=>this.chatbotService.renameConversation(e.public_id,s).pipe(me(()=>{this.snackbarService.success($localize`:Snackbar after renaming a chat:Chat has been renamed`),this.analyticsService.analyticsEvent({type:b.CHATBOT_HISTORY_ITEM_RENAMED,properties:{location:n,new_title_length:s.length,was_auto_generated:i}})}))))}static{this.\u0275fac=function(n){return new(n||t)}}static{this.\u0275prov=he({token:t,factory:t.\u0275fac,providedIn:"root"})}}return t})();function it(t,l){return Math.floor(l.diff(A.from(t),"days"))}export{Mi as a,Ui as b,sn as c};