import{ay as e,k as t}from"./vendor-element-plus.js?ver=3.1.0";import i from"./v3app/src/Modules/Contacts/RichFilters/Filters.js?ver=3.1.0";import{_ as s,I as a}from"./fc-bits-ui.js?ver=3.1.0";import{r as n,K as l,c as d,o as r,b as o,L as c,Q as m,as as h,d as _,P as u,w as f,O as g}from"./vendor.js?ver=3.1.0";const p={class:"fcrm_segment_fields"},v={class:"fcrm_rich_container"},b={class:"fcrm_rich_wrap"},y={class:"fcrm_rich_filter"},C={class:"fcrm_filter_group_header"},$={class:"fcrm_and_label"},E={key:0,class:"fcrm_cond_or"},F={class:"icon","aria-hidden":"true"},R={class:"fcrm_cond_or"},G={class:"icon","aria-hidden":"true"},k={key:0,class:"fcrm_estimated_count"},V={class:"fcrm_estimated_label"},j={class:"fcrm_estimated_badge"},x={class:"fcrm_estimated_badge_text"};const S=s({name:"customSegmentEditor",props:["modelValue","segment_id"],emits:["update:modelValue","loaded","updateSegment"],components:{Icons:a,RichFilter:i},data(){return{fields:{},loading:!1,filters:this.modelValue,estimated_count:"",estimating:!1,require_estimating:!1,FilterLabel:this.$t("Filters.instruction")}},watch:{filters:{deep:!0,handler(){this.$emit("update:modelValue",this.filters),this.require_estimating=!0,this.estimating?this.changed_in_time||(this.changed_in_time=!0):this.getEstimatedCount()}},modelValue(e){this.filters=e}},methods:{fetchFields(){this.loading=!0,this.$get("dynamic-segments/custom-fields").then(e=>{this.fields=e.fields,this.segment_id||(this.settings=e.settings_defaults),this.$emit("loaded")}).catch(e=>{this.handleError(e)}).finally(()=>{this.loading=!1})},getEstimatedCount(){this.estimating=!0,this.$post("dynamic-segments/estimated-contacts",{filters:this.filters}).then(e=>{this.estimated_count=e.count,this.changed_in_time&&(this.changed_in_time=!1,this.getEstimatedCount())}).catch(e=>{this.handleError(e)}).finally(()=>{this.estimating=!1})},addConditionGroup(){this.filters.push([])},maybeRemoveGroup(e){this.filters.length>1&&this.filters.splice(e,1)},fetch(){this.$emit("updateSegment"),this.getEstimatedCount()}},mounted(){this.fetchFields()}},[["render",function(i,s,a,S,w,I){const L=n("rich-filter"),M=n("Icons"),O=t,q=e;return l((r(),d("div",p,[o("div",v,[o("div",b,[(r(!0),d(m,null,h(w.filters,(e,t)=>(r(),d("div",{key:t},[o("div",y,[o("div",C,[o("div",$,u(i.$t("And")),1),_(L,{add_label:w.FilterLabel,button_text:i.$t("Add Property"),onMaybeRemove:e=>I.maybeRemoveGroup(t),items:e,canDeleteGroup:w.filters.length>1},null,8,["add_label","button_text","onMaybeRemove","items","canDeleteGroup"])])]),t<w.filters.length-1?(r(),d("div",E,[s[2]||(s[2]=o("div",{class:"fcrm_or_divider_line"},null,-1)),_(O,{size:"small",onClick:s[0]||(s[0]=e=>I.addConditionGroup())},{default:f(()=>[o("span",F,[_(M,{"icon-name":"plus"})]),g(" "+u(i.$t("OR")),1)],void 0),_:1}),s[3]||(s[3]=o("div",{class:"fcrm_or_divider_line"},null,-1))])):c("",!0)]))),128))]),o("div",R,[s[4]||(s[4]=o("div",{class:"fcrm_or_divider_line"},null,-1)),_(O,{size:"small",onClick:s[1]||(s[1]=e=>I.addConditionGroup())},{default:f(()=>[o("span",G,[_(M,{"icon-name":"plus"})]),g(" "+u(i.$t("OR")),1)],void 0),_:1}),s[5]||(s[5]=o("div",{class:"fcrm_or_divider_line"},null,-1))])]),""!==w.estimated_count?l((r(),d("div",k,[o("span",V,u(i.$t("Estimated Contacts Based on your Selection")),1),o("div",j,[o("span",x,u(w.estimated_count),1)])])),[[q,w.estimating]]):c("",!0)])),[[q,w.loading]])}]]);export{S as C};
