1import{r as i,q as S,C as Y,D as q,bm as G,bn as K,p as a,L as v,T as D,w as p,bh as f,B as c,y as H,v as J,bE as W,z as X,N as b,x as Z}from"./index-C9IH3k-2.js";import{a7 as ee,a8 as te,g as ae,ah as se}from"./TemplateUtil-D1DzmWLm.js";import{u as ne}from"./HelperMethods-C-ewwU_x.js";import{P as oe}from"./PageDescription-BrOUsEZE.js";import{R as le}from"./ContactUtil-CNNd5h8z.js";import{C as re}from"./ContactFilterSampleModal-DRXMFp1P.js";import{F as ie}from"./Table-isZ0WXp4.js";import{P as ce}from"./index-C0dhduHx.js";import{p as de,f as me}from"./parseMongoDB-D5M9WvAm.js";import"./Wrapper-ChjuDa3w.js";import"./index-BOwvFOZJ.js";import"./Pagination-D1z-xPUv.js";import"./HolderOutlined-YOHjCGKZ.js";import"./immer-D9GuDFqv.js";const ve=()=>{const[N,T]=i.useState([]),[k,d]=i.useState(!1),[m,A]=i.useState({current:1,pageSize:10}),[I,x]=i.useState(!1),[L,E]=i.useState(null),[M,R]=i.useState(""),[C,y]=i.useState({loading:!1,id:null}),u=S(e=>e.contactLabel||[]),h=S(e=>e.contactAttributes||[]),l=ne(),_=l("export_contacts"),w=Y(),F=q(),g=async(e=1,t=10)=>{d(!0);const r={search:[],pagination:{current:e,pageSize:t}};try{const n=await H("/api/v1/contact/filter/list",r);n&&(T(n.data.results),A({...m,current:e,pageSize:t,total:n.data.total}))}catch(n){console.error("Failed to fetch filters:",n)}finally{d(!1)}},U=async e=>{y(t=>({...t,loading:!0,id:e.id}));try{const t=await Z(`/api/v1/contact/filter/${e.id}/download`,!1),r=`contacts_filter_${e?.name?.replace(/\s+/g,"_")?.toLowerCase()}_${e.id}.csv`,n=new Blob([t.data],{type:"text/csv"}),o=window.URL.createObjectURL(n),s=document.createElement("a");s.setAttribute("href",o),s.setAttribute("download",r),s.click()}catch{b.error("Failed to initiate contact download.")}finally{y(t=>t.id===e.id?{loading:!1,id:null}:t)}},P=async e=>{d(!0);try{await X(`/api/v1/contact/filter/${e.id}`),b.success("Filter deleted successfully"),g(m.current,m.pageSize)}catch(t){console.error("Failed to delete filter:",t),b.error("Failed to delete filter")}finally{d(!1)}},$=e=>{E(e.id),R(e.name),x(!0)};i.useEffect(()=>{g(),u.length===0&&ee().then(e=>F(G(e.data.results))),h.length===0&&te().then(e=>F(K(e.data.results)))},[]);const z=e=>{g(e.current,e.pageSize)},B=e=>{if(h.length===0||u.length===0)return null;const t=[...h.map(o=>({value:`attributes.${o.id}`,label:o.name})),...u.map(o=>({value:`labels.${o.id}`,label:o.name}))],r=de(e),n=o=>o.map(s=>{if(s.rules)return{...s,rules:n(s.rules)};if(s.field==="labels"){const j=u.find(Q=>Q.id===s.value),V=j?j.name:s.value;return{...s,field:"labels",operator:s.operator==="="?"has":"doesn't have",value:V}}return s});return r.rules&&(r.rules=n(r.rules)),le(me(r,{format:"natural_language",parseNumbers:!0,fields:t}))},O=[{title:"Name",dataIndex:"name",key:"name",render:(e,t)=>a.jsx(p,{title:l("manage_contact_related")?"Click to edit":f,children:a.jsx(c,{type:"link",onClick:()=>w("/Contact/ContactFilters/Update",{state:{filter:t}}),disabled:!l("manage_contact_related"),children:e})})},{title:"Description",dataIndex:"filter",key:"filter",render:e=>B(e)},{title:"Last Update Time",dataIndex:"lastUpdateTime",key:"lastUpdateTime",sorter:(e,t)=>!0,render:(e,t)=>a.jsx(D.Text,{children:ae(t.lastUpdateTime)})},{title:"Actions",key:"actions",render:(e,t)=>a.jsxs(J,{size:"middle",children:[a.jsx(c,{onClick:()=>$(t),children:"View Count & Samples"}),a.jsx(ce,{title:"Are you sure you want to delete this filter?",onConfirm:()=>P(t),okText:"Yes",cancelText:"No",disabled:!l("manage_contact_related"),children:a.jsx(p,{title:l("manage_contact_related")?"":f,children:a.jsx(c,{disabled:!l("manage_contact_related"),children:a.jsx(W,{})})})}),a.jsx(p,{title:_?"Download Contacts matching this filter":f,children:a.jsx(c,{variant:"outlined",color:"primary",onClick:()=>U(t),loading:C.loading&&C.id===t.id,icon:a.jsx(se,{}),disabled:!_,children:"Contacts"})})]})}];return a.jsxs(a.Fragment,{children:[a.jsxs(v,{vertical:!0,gap:"large",children:[a.jsxs(v,{justify:"space-between",wrap:!0,children:[a.jsx(D.Title,{level:4,style:{margin:0},children:"Contact Filters"}),a.jsx(p,{title:l("manage_contact_related")?"":f,children:a.jsx(c,{type:"primary",onClick:()=>w("/Contact/ContactFilters/Create"),disabled:!l("manage_contact_related"),
1children:"Create Contact Filter"})})]}),a.jsx(oe,{children:"Contact filters allow you to create dynamic groups of contacts based on multiple conditions like attributes, labels, or other properties. You can use these filters to target specific audience segments when sending bulk messages. Create complex filtering rules to narrow down your audience based on their characteristics and preferences for more personalized communication."}),a.jsx(ie,{dataSource:N,columns:O,loading:k,pagination:m,onChange:z,rowKey:"id",scroll:{x:"max-content"}})]}),a.jsx(re,{isVisible:I,onCancel:()=>x(!1),filterId:L,filterName:M})]})};export{ve as default};
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.