import{ay as e,k as t}from"./vendor-element-plus.js?ver=3.1.8";import{aQ as i,a6 as s,W as a,X as n,Z as l,J as d,az as r,aa as o,ab as c,a5 as m,a9 as h,a8 as _}from"./vendor.js?ver=3.1.8";import u from"./v3app/src/Modules/Contacts/RichFilters/Filters.js?ver=3.1.8";import{_ as f,I as g}from"./fc-bits-ui.js?ver=3.1.8";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=f({name:"customSegmentEditor",props:["modelValue","segment_id"],emits:["update:modelValue","loaded","updateSegment"],components:{Icons:g,RichFilter:u},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(u,f,g,S,z,I){const M=i("rich-filter"),q=i("Icons"),w=t,A=e;return s((a(),n("div",p,[l("div",v,[l("div",b,[(a(!0),n(d,null,r(z.filters,(e,t)=>(a(),n("div",{key:t},[l("div",y,[l("div",C,[l("div",$,o(u.$t("And")),1),c(M,{add_label:z.FilterLabel,button_text:u.$t("Add Property"),onMaybeRemove:e=>I.maybeRemoveGroup(t),items:e,canDeleteGroup:z.filters.length>1},null,8,["add_label","button_text","onMaybeRemove","items","canDeleteGroup"])])]),t<z.filters.length-1?(a(),n("div",E,[f[2]||(f[2]=l("div",{class:"fcrm_or_divider_line"},null,-1)),c(w,{size:"small",onClick:f[0]||(f[0]=e=>I.addConditionGroup())},{default:m(()=>[l("span",F,[c(q,{"icon-name":"plus"})]),h(" "+o(u.$t("OR")),1)],void 0),_:1}),f[3]||(f[3]=l("div",{class:"fcrm_or_divider_line"},null,-1))])):_("",!0)]))),128))]),l("div",R,[f[4]||(f[4]=l("div",{class:"fcrm_or_divider_line"},null,-1)),c(w,{size:"small",onClick:f[1]||(f[1]=e=>I.addConditionGroup())},{default:m(()=>[l("span",G,[c(q,{"icon-name":"plus"})]),h(" "+o(u.$t("OR")),1)],void 0),_:1}),f[5]||(f[5]=l("div",{class:"fcrm_or_divider_line"},null,-1))])]),""!==z.estimated_count?s((a(),n("div",k,[l("span",V,o(u.$t("Estimated Contacts Based on your Selection")),1),l("div",j,[l("span",x,o(z.estimated_count),1)])])),[[A,z.estimating]]):_("",!0)])),[[A,z.loading]])}]]);export{S as C};
