import{N as e,L as s,$ as t,bh as i,d as n,n as d}from"./vendor-element-plus.js?ver=3.0.6";import{b1 as l,y as c,c5 as a,c6 as u,A as r,x as o,br as p,J as h,F as f,bg as b,aO as S,I as m,z as v}from"./vendor.js?ver=3.0.6";import{_}from"./fc-bits-ui.js?ver=3.0.6";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{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,x,C){const A=t,V=s,j=e,w=n,z=d,D=i;return l(),c(z,{modelValue:x.visible,"onUpdate:modelValue":$[3]||($[3]=e=>x.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:a(()=>[o("span",y,[h(w,{onClick:$[1]||($[1]=e=>_.$emit("close"))},{default:a(()=>[m(p(_.$t("Cancel")),1)],void 0,!0),_:1}),h(w,{type:"primary",loading:x.advancing,disabled:!x.selectedStepId,onClick:$[2]||($[2]=e=>C.executeAdvance())},{default:a(()=>[m(p(_.$t("Advance")),1)],void 0,!0),_:1},8,["loading","disabled"])])]),default:a(()=>[u((l(),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:x.selectedStepId,"onUpdate:modelValue":$[0]||($[0]=e=>x.selectedStepId=e),class:"fluentcrm_line_items"},{default:a(()=>[(l(!0),r(f,null,b(C.advancableSequences,e=>(l(),c(V,{key:e.id,value:e.id,disabled:C.isCompletedStep(e),class:S({"is-current":C.isCurrent(e),"is-completed":C.isCompletedStep(e),fc_step_conditional:!!e.condition_type})},{default:a(()=>[m(p(e.title)+" ",1),C.isCurrent(e)?(l(),c(A,{key:0,size:"small",type:"info"},{default:a(()=>[m(p(_.$t("Next")),1)],void 0,!0),_:1})):v("",!0),"benchmark"===e.type?(l(),c(A,{key:1,size:"small",type:"warning"},{default:a(()=>[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,x.loadingSequences]])],void 0),_:1},8,["modelValue","title"])}]]);export{$ as S};