import{aE as e,aF as s,aQ as t,ay as i,k as n,g as a}from"./vendor-element-plus.js?ver=3.1.10";import{W as d,Y as l,a5 as c,a6 as u,X as r,Z as o,aa as p,ab as h,J as f,az as S,a0 as b,a9 as m,a8 as v}from"./vendor.js?ver=3.1.10";import{_}from"./fc-bits-ui.js?ver=3.1.10";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,z=a,D=i;return d(),l(z,{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,[h(w,{onClick:$[1]||($[1]=e=>_.$emit("close"))},{default:c(()=>[m(p(_.$t("Cancel")),1)],void 0,!0),_:1}),h(w,{type:"primary",loading:C.advancing,disabled:!C.selectedStepId,onClick:$[2]||($[2]=e=>x.executeAdvance())},{default:c(()=>[m(p(_.$t("Advance")),1)],void 0,!0),_:1},8,["loading","disabled"])])]),default:c(()=>[u((d(),r("div",q,[o("p",g,p(_.$t("Select the step to advance this subscriber to. The selected step will be executed immediately.")),1),h(j,{modelValue:C.selectedStepId,"onUpdate:modelValue":$[0]||($[0]=e=>C.selectedStepId=e),class:"fluentcrm_line_items"},{default:c(()=>[(d(!0),r(f,null,S(x.advancableSequences,e=>(d(),l(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(p(e.title)+" ",1),x.isCurrent(e)?(d(),l(V,{key:0,size:"small",type:"info"},{default:c(()=>[m(p(_.$t("Next")),1)],void 0,!0),_:1})):v("",!0),"benchmark"===e.type?(d(),l(V,{key:1,size:"small",type:"warning"},{default:c(()=>[m(p(_.$t("Goal")),1)],void 0,!0),_:1})):v("",!0)],void 0,!0),_:2},1032,["value","disabled","class"]))),128))],void 0,!0),_:1},8,["modelValue"])])),[[D,C.loadingSequences]])],void 0),_:1},8,["modelValue","title"])}]]);export{$ as S};
