1(function(){try{var e=typeof window<`u`?window:typeof global<`u`?global:typeof globalThis<`u`?globalThis:typeof self<`u`?self:{};e.SENTRY_RELEASE={id:`release-202609241050`};var t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]=`340a30c6-8ace-4926-9cee-423aebc35ca7`,e._sentryDebugIdIdentifier=`sentry-dbid-340a30c6-8ace-4926-9cee-423aebc35ca7`)}catch{}})();import{a as e}from"./rolldown-runtime-BI-OUt3b.js";import{O as t,Ot as n,d as r}from"./vendor-vue-core-B0avW4A6.js";import{Ct as i}from"./utils-01hI5-7X.js";import{A as a,G as o,f as s,q as c,t as l}from"./user-1VcPMvca.js";import{o as u}from"./vendor-utils-PJ_f0V92.js";import{t as d}from"./toast-nz9AHFzD.js";import{t as f}from"./conversation-shwc8LpF.js";var p=e(u());function m(e,t){return{id:e.message_id,sort_number:String(e.message_sort_number),parent_id:null,content:e.message_content,conversation_id:t,chat_contact_id:``,agent_id:``,urls:e.message_urls,is_system_message:!1,created_at:e.message_created_at,updated_at:e.message_created_at,agent_name:``,translations:[],agent_resized_profile_photo_url:``}}function h(){return{id:``,user_id:0,team_id:0,name:``,email:``,status:``,joined_at:``,profile_pic_url:``,online_status:``,last_active_at:``,created_at:``,updated_at:``,deleted_at:``}}function g(e){return{type:`conversation_messages`,id:e.message_id,attributes:{is_system_message:!1,message_type:``,message_body:e.message_content,is_parent_message_deleted:!1,echo_id:``,message_sender:h(),message_urls:e.message_urls||[],is_sender_agent:!1,is_read_by_visitor:!1,message_created_at:e.message_created_at,remind_at:void 0,sort_number:Number(e.message_sort_number),message_link_previews:[],message_meta:{note_html:``},is_chat_init_details:0,notified_via_email:!1,message_language:``,translations:[]}}}function _(e){return{type:`agent`,id:e.id,attributes:{team_id:null,email:``,name:e.name,status:``,online_status:``,last_active_at:``,join_date:``,profile_photo_url:``,resized_profile_photo_url:``,sent_at:``,widgets:[],role:``,online_availability:``,visibility_hour_timezone:``}}}function v(e){return{id:e||``,contact_name:`Unknown`,name:`Unknown`,contact_email:``,email:``,bgcolor:`#9CA3AF`,src:``,profile:{avatar:``},page_visited:[],conversations:[]}}var y={message_id:``,message_content:``,message_urls:null,message_sort_number:0,message_created_at:``};function b(e){let t=e.conversation_id,n=[...e.messages||[]].sort((e,t)=>t.message_sort_number-e.message_sort_number),r=n[0]??y,i=e.contact?{id:e.contact.id||``,contact_name:e.contact.name||`Unknown`,name:e.contact.name||`Unknown`,contact_email:e.contact.email||``,email:e.contact.email||``,bgcolor:e.contact.bg_color||`#9CA3AF`,src:``,profile:{avatar:e.contact.profile_avatar||``},page_visited:[],conversations:[]}:v(),a=n.map(g);return{type:`conversations`,id:t,attributes:{is_resolved:e.is_resolved,is_read:!1,has_unread_reminders:!1,resolved_at:void 0,contact_id:e.contact?.id||``,contact:i,custom_data:[],tags:[],total_messages_count:n.length,latest_message:m(r,t),is_ended:!1,message_urls:null,is_bookmarked:!1,agents:[],widget:{id:0,identifier:``},agent_read_till:``,chat_contact_read_till:null,unread_messages:0,unread_notes:0,latest_active_agent:e.latest_agent_name?_({id:``,name:e.latest_agent_name}):null,has_unread_note_tags:!1,translation_setting:!1,has_month_old_messages:!1,origin:e.origin_url||``,marketplace_id:null,current_translation:``,total_unread_conversation_count:0},messages:a,notVisible:!1}}function x(){let{uiFlags:e,searchHistory:u,searchResults:m,customFields:h,hasPerformedSearch:g,searchQuery:_,selectedTags:v,selectedAgents:y,selectedCountries:x,selectedContacts:S,selectedCustomData:C,selectedPageCondition:w,selectedPageUrl:T,selectedFromDate:E,selectedToDate:D,showTagsDropdown:O,showAgentsDropdown:k,showCountriesDropdown:A,showContactsDropdown:j,showCustomDataDropdown:ee,showPageVisitedDropdown:te,showCreatedDropdown:ne,customDataCurrentView:re,customDataSelectedFieldId:M,customDataSelectedFieldName:N}=r(a()),P=a(),F=l(),I=n([]),L=n({total:0,count:0,per_page:50,current_page:0,total_pages:0}),R=n(!1),z=n(!1),B=n(``),V=t(()=>v.value.length),H=t(()=>y.value.length),U=t(()=>x.value.length),W=t(()=>S.value.length),G=t(()=>Object.keys(C.value).reduce((e,t)=>
1e+C.value[t].length,0)),K=t(()=>w.value&&T.value&&T.value.trim()?1:0),q=t(()=>E.value||D.value?1:0),J=t(()=>_.value.trim().length>0||v.value.length>0||y.value.length>0||x.value.length>0||S.value.length>0||Object.keys(C.value).length>0||w.value&&T.value||E.value||D.value),Y=t(()=>M.value&&h.value.find(e=>e.id===M.value)||null),X=t(()=>L.value.current_page<L.value.total_pages);async function ie(){e.value.isFetchingSearchHistory=!0;try{let{data:t}=await new s().getSearchHistory();P.searchHistory=t,e.value.isFetchingSearchHistory=!1}catch(t){e.value.isFetchingSearchHistory=!1,i(t)}}async function ae(){if(!F.isProUserOrTrial){P.setCustomFields([]);return}e.value.isFetchingCustomFields=!0;try{let{data:e}=await new s().getCustomFields(),t=e.map(e=>({id:e.id,name:e.attributes.name,values:[],values_count:e.attributes.values_count}));P.setCustomFields(t)}catch(e){i(e)}finally{e.value.isFetchingCustomFields=!1,P.uiFlags.shouldRefreshCustomFields=!1}}async function Z({reset:e=!0,searchTerm:t}={}){if(M.value){if(!F.isProUserOrTrial){e&&(I.value=[]),L.value={total:0,count:0,per_page:50,current_page:0,total_pages:0};return}e?R.value=!0:X.value&&!z.value&&(z.value=!0);try{let n=e?1:L.value.current_page+1,{data:r,meta:i}=await new s().getCustomFieldValues({custom_field_id:M.value,search:t??B.value,page:n,limit:50}),a=(r||[]).map(e=>({id:e.id,value:e.attributes.value}));e?I.value=a:I.value=[...I.value,...a];let o=i?.pagination;o&&(L.value={total:o.total,count:o.count,per_page:o.per_page,current_page:o.current_page,total_pages:o.total_pages})}catch(e){i(e)}finally{R.value=!1,z.value=!1}}}function oe(e){B.value=e,Z({reset:!0,searchTerm:e})}function se(){X.value&&!R.value&&!z.value&&Z({reset:!1})}async function ce(t){if(J.value){e.value.isSearching=!0,g.value=!0;try{if(P.searchResults=((await new s().search(t)).data?.conversations||[]).map(b),e.value.isSearching=!1,t.query&&t.query.trim()){let e=t.query.trim(),n=P.searchHistory.filter(t=>t.attributes.search_term.toLowerCase()!==e.toLowerCase());P.searchHistory=[{type:`search_history`,id:`local_${Date.now()}`,attributes:{user_id:``,search_term:t.query,created_at:new Date().toISOString(),updated_at:new Date().toISOString()}},...n].slice(0,10)}}catch(t){e.value.isSearching=!1,i(t)}}}async function le(t){e.value.isDeletingSearchHistory=!0;try{await new s().deleteSearchHistory(t),P.searchHistory=P.searchHistory.filter(e=>e.id!==t),e.value.isDeletingSearchHistory=!1,d().set({message:`Search history deleted successfully`,type:`success`})}catch(t){e.value.isDeletingSearchHistory=!1,i(t)}}function ue(){P.toggleSearchModal()}function de(){P.closeSearchModal()}function fe(){P.openSearchModal()}function pe(){P.clearAllFilters()}function me(){P.clearPageVisitedFilter()}function he(){P.clearCreatedFilter()}function ge(){P.clearCustomDataFilter()}function _e(){P.toggleTagsDropdown()}function ve(){P.toggleAgentsDropdown()}function ye(){P.toggleCountriesDropdown()}function be(){P.toggleContactsDropdown()}function xe(){P.toggleCustomDataDropdown()}function Se(){P.togglePageVisitedDropdown()}function Ce(){P.toggleCreatedDropdown()}function we(){P.closeAllDropdowns()}function Te(e){P.setCustomDataView(e)}function Ee(e,t){P.selectCustomDataField(e,t),I.value=[],L.value={total:0,count:0,per_page:50,current_page:0,total_pages:0},B.value=``,Z({reset:!0})}function De(){P.goBackToCustomDataFields(),I.value=[],L.value={total:0,count:0,per_page:50,current_page:0,total_pages:0},B.value=``}function Oe(e,t){P.toggleCustomDataValue(e,t)}function Q(){P.clearSearchResults()}function ke(){g.value=!1,P.clearSearchResults()}function $(e,t,n={}){if(!n.ignoreQuery){let n=(_.value||``).trim().toLowerCase(),r=(t?.attributes?.message_body||e?.latest_message?.message_body||``).toLowerCase();if(n&&!r.includes(n))return!1}if(v.value?.length){let t=(e?.tags||[]).map(e=>e.id);if(!v.value.some(e=>t.includes(e)))return!1}if(y.value?.length){let t=(e?.agents||[]).map(e=>e.id);if(!y.value.some(e=>t.includes(e)))return!1}if(x.value?.length){let t=(e?.contact?.country_details?.code||e?.contact?.country||``).toString().toUpperCase(),n=x.value.map(e=>e.toString().toUpperCase());if(!t||!n.includes(t))return!1}if(S.value?.length){let t=e?.contact?.id;if(!S.value.includes(t))return!1}let r=C.value||{};for(let t in r){let n=r[t];if(!n?.length)continue;let i=(e?.custom_data||[]).find(e=>e.name===t);if(!i||!n.includes(i.value))return!1}if(w.value&&T.value){let t=e?.contact?.page_visited||[],n=T.value;if(w.value===`specific`&&!t.some(e=>e.page===n)||w.value===`contains`&&!t.some(e=>(e.page||``).includes(n)))return!1}if(E.value||D.value){let t=e?.created_at||e?.latest_message?.message_created_at||e?.latest_message?.created_at;if(!t)return!0;let n=(0,p.default)(t).format(`YYYY-MM-DD`);if(E.value&&n<E.value||D.value&&n>D.value)return!1}return!0}function Ae(e){P.removeSearchResult(e)}function je(e,t){if(!m.value.length||!e?.length)return;let n=!1;m.value.forEach(r=>{e.includes(r.id)&&r.attributes?.contact&&(r.attributes.contact.name=t,r.attributes.contact.contact_name=t,n=!0)}),n&&(P.searchResults=[...P.searchResults])}function Me(e,t){let n=m.value.findIndex(t=>t.id===e);if(n===-1)return;let r=m.value[n].messages||[],i=r.findIndex(e=>e.id===t);i!==-1&&r.splice(i,1),r.length===0?P.removeSearchResult(e):P.searchResults=[...P.searchResults]}function Ne(e,t,n){if(!P.uiFlags.showSearchResultsInConversation||!g.value)return;let r=c().selectedSegment.id?o(e,{id:e,attributes:t}):!0,i=m.value.findIndex(t=>t.id===e),a=(_.value||``).trim()&&i>-1?$(t,n,{ignoreQuery:!0}):$(t,n),s=()=>{P.searchResults=[...P.searchResults]};if(r&&a){let t=f().allConversations.find(t=>
1t.id===e);if(!t)return;if(i===-1)P.searchResults.unshift({...t,messages:t.messages?[...t.messages]:[]});else{let e=P.searchResults[i].messages;P.searchResults[i]={...t,messages:e}}s();return}i>-1&&(P.searchResults.splice(i,1),s())}return{searchHistory:u,searchResults:m,customFields:h,uiFlags:e,hasPerformedSearch:g,searchQuery:_,selectedTags:v,selectedAgents:y,selectedCountries:x,selectedContacts:S,selectedCustomData:C,selectedPageCondition:w,selectedPageUrl:T,selectedFromDate:E,selectedToDate:D,showTagsDropdown:O,showAgentsDropdown:k,showCountriesDropdown:A,showContactsDropdown:j,showCustomDataDropdown:ee,showPageVisitedDropdown:te,showCreatedDropdown:ne,customDataCurrentView:re,customDataSelectedFieldId:M,customDataSelectedFieldName:N,currentCustomDataField:Y,customFieldValues:I,customFieldValuesSearchTerm:B,selectedTagsCount:V,selectedAgentsCount:H,selectedCountriesCount:U,selectedContactsCount:W,selectedCustomDataCount:G,selectedPageVisitedCount:K,selectedCreatedCount:q,canSearch:J,canLoadMoreCustomFieldValues:X,isFetchingCustomFieldValues:R,isLoadingMoreCustomFieldValues:z,getSearchHistory:ie,getCustomFields:ae,performSearch:ce,deleteSearchHistory:le,toggleSearchModal:ue,closeSearchModal:de,openSearchModal:fe,clearAllFilters:pe,clearPageVisitedFilter:me,clearCreatedFilter:he,clearCustomDataFilter:ge,toggleTagsDropdown:_e,toggleAgentsDropdown:ve,toggleCountriesDropdown:ye,toggleContactsDropdown:be,toggleCustomDataDropdown:xe,togglePageVisitedDropdown:Se,toggleCreatedDropdown:Ce,closeAllDropdowns:we,setCustomDataView:Te,selectCustomDataField:Ee,goBackToCustomDataFields:De,toggleCustomDataValue:Oe,fetchCustomFieldValues:Z,searchCustomFieldValues:oe,loadMoreCustomFieldValues:se,clearSearchResults:Q,resetSearchState:ke,handleRealtimeSearchPlacement:Ne,handleSearchResultMessageDeleted:Me,handleSearchResultConversationDeleted:Ae,handleSearchResultContactUpdated:je}}export{x as t}; 2//# sourceMappingURL=useSearch-zg2-QcqR.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.