import{aE as e,aF as s,aQ as t,ay as i,k as n,g as d}from"./vendor-element-plus.js?ver=3.1.0";import{a,o as l,w as c,K as u,c as r,b as o,d as p,P as h,Q as f,as as S,n as b,O as m,L as v}from"./vendor.js?ver=3.1.0";import{_}from"./fc-bits-ui.js?ver=3.1.0";const q={class:"fc_step_picker"},g={class:"fc_step_picker_hint"},y={class:"dialog-footer"};const $=_({name:"StepPicker",props:{funnelSubscriber:{type:Object,required:!0},sequences:{type:Array,default:null},funnelId:{type:[Number,String],required:!0}},emits:["close","advanced"],data:()=>({visible:!0,selectedStepId:null,advancing:!1,loadingSequences:!1,fetchedSequences:[]}),computed:{resolvedSequences(){return this.sequences||this.fetchedSequences},advancableSequences(){return this.resolvedSequences.filter(e=>"conditional"!==e.type)},currentSequence(){return this.resolvedSequences.find(e=>e.id==this.funnelSubscriber.next_sequence_id)}},methods:{isCurrent(e){return e.id==this.funnelSubscriber.next_sequence_id},getDefaultStepId(){return this.funnelSubscriber.next_sequence_id||null},isCompletedStep(e){const s=this.currentSequence;return!!s&&e.sequence<s.sequence},fetchSequences(){this.loadingSequences=!0,this.$get(`funnels/${this.funnelId}/subscribers/${this.funnelSubscriber.subscriber_id}`).then(e=>{this.fetchedSequences=e.sequences||[],this.selectedStepId=this.getDefaultStepId()}).catch(e=>{this.handleError(e)}).finally(()=>{this.loadingSequences=!1})},executeAdvance(){this.selectedStepId&&(this.advancing=!0,this.$post(`funnels/${this.funnelId}/subscribers/${this.funnelSubscriber.subscriber_id}/advance`,{sequence_id:this.selectedStepId}).then(e=>{this.$notify.success(e.message),this.$emit("advanced")}).catch(e=>{this.handleError(e)}).finally(()=>{this.advancing=!1}))}},mounted(){this.sequences?this.selectedStepId=this.getDefaultStepId():this.fetchSequences()}},[["render",function(_,$,I,k,C,x){const V=t,A=s,j=e,w=n,D=d,E=i;return l(),a(D,{modelValue:C.visible,"onUpdate:modelValue":$[3]||($[3]=e=>C.visible=e),title:_.$t("Advance to Step"),width:"520px","append-to-body":!0,class:"fc_step_picker_dialog",onClose:$[4]||($[4]=e=>_.$emit("close"))},{footer:c(()=>[o("span",y,[p(w,{onClick:$[1]||($[1]=e=>_.$emit("close"))},{default:c(()=>[m(h(_.$t("Cancel")),1)],void 0,!0),_:1}),p(w,{type:"primary",loading:C.advancing,disabled:!C.selectedStepId,onClick:$[2]||($[2]=e=>x.executeAdvance())},{default:c(()=>[m(h(_.$t("Advance")),1)],void 0,!0),_:1},8,["loading","disabled"])])]),default:c(()=>[u((l(),r("div",q,[o("p",g,h(_.$t("Select the step to advance this subscriber to. The selected step will be executed immediately.")),1),p(j,{modelValue:C.selectedStepId,"onUpdate:modelValue":$[0]||($[0]=e=>C.selectedStepId=e),class:"fluentcrm_line_items"},{default:c(()=>[(l(!0),r(f,null,S(x.advancableSequences,e=>(l(),a(A,{key:e.id,value:e.id,disabled:x.isCompletedStep(e),class:b({"is-current":x.isCurrent(e),"is-completed":x.isCompletedStep(e),fc_step_conditional:!!e.condition_type})},{default:c(()=>[m(h(e.title)+" ",1),x.isCurrent(e)?(l(),a(V,{key:0,size:"small",type:"info"},{default:c(()=>[m(h(_.$t("Next")),1)],void 0,!0),_:1})):v("",!0),"benchmark"===e.type?(l(),a(V,{key:1,size:"small",type:"warning"},{default:c(()=>[m(h(_.$t("Goal")),1)],void 0,!0),_:1})):v("",!0)],void 0,!0),_:2},1032,["value","disabled","class"]))),128))],void 0,!0),_:1},8,["modelValue"])])),[[E,C.loadingSequences]])],void 0),_:1},8,["modelValue","title"])}]]);export{$ as S};
