import{ax as e,aw as t,e as a,k as s,ay as i,g as l,c as n,R as o,as as r,a6 as c,ac as d,a2 as u,j as p,h as m,i as h,aB as g,aH as _,aI as f,E as y,aR as q,aS as v,n as b}from"../../../../vendor-element-plus.js?ver=3.1.8";import{W as S,Y as $,a5 as w,Z as k,ab as C,ax as T,b2 as V,aa as D,a6 as x,a9 as E,aQ as A,X as P,a8 as j,J as B}from"../../../../vendor.js?ver=3.1.8";import{_ as I,I as F,a as N,T as U}from"../../../../fc-bits-ui.js?ver=3.1.8";import{C as O}from"../../../../Confirm.js?ver=3.1.8";import{P as M}from"../../../../PaginationBar.js?ver=3.1.8";import{I as H}from"../../../../InlineDoc.js?ver=3.1.8";import{T as J}from"../../../../TopNav.js?ver=3.1.8";import{P as K}from"../../../../PageHeader.js?ver=3.1.8";import{D as R}from"../../../../DataTable.js?ver=3.1.8";import{F as Q}from"../../../../FloatingBulkActionShell.js?ver=3.1.8";const Y={name:"CreateSequence",props:{modelValue:{type:Boolean,default:!1}},emits:["update:modelValue","toggleDialog"],data:()=>({sequence:{title:""},errors:{title:""},saving:!1}),computed:{isVisible:{get(){return this.modelValue},set(e){this.$emit("update:modelValue",e),this.$emit("toggleDialog",e)}}},methods:{save(){this.sequence.title?(this.errors={title:""},this.saving=!0,this.$post("sequences",this.sequence).then(e=>{this.$notify.success(e.message),this.$router.push({name:"edit-sequence",params:{id:e.sequence.id}})}).catch(e=>{const t=e.data?e.data:e;if(t.status&&403===t.status)this.notify.error(t.message);else if(t.title){const e=Object.keys(t.title);this.errors.title=t.title[e[0]]}}).finally(e=>{this.saving=!1})):this.errors.title=this.$t("Title field is required")}}},z={class:"error"},L={class:"dialog-footer"};const G={class:"fcrm_email_sequences_page"},W={class:"fcrm_page_header_top_nav_wrapper"},X={class:"fcrm_page_header_top_nav"},Z={class:"fcrm-layout-width"},ee={key:0},te={class:"icon"},ae={class:"el-popover__reference"},se={class:"icon"},ie={class:"icon"},le={class:"icon"},ne={class:"fcrm_empty_state"},oe={class:"fcrm_empty_state_text"},re={key:0},ce=["title"],de={style:{"vertical-align":"middle"}},ue={key:1},pe=["aria-label"],me={class:"el-popover__reference"},he={class:"icon"},ge={class:"el-popover__reference"},_e={class:"icon"},fe={class:"el-popover__reference"},ye={class:"icon"},qe={class:"el-popover__reference"},ve={class:"icon"},be={class:"fcrm_bulk_action_bar"},Se={class:"fcrm_bulk_action_left"},$e={class:"fc_bulk_selection_count"},we={key:0,class:"fc_bulk_divider","aria-hidden":"true"},ke={key:2,class:"fc_bulk_divider","aria-hidden":"true"},Ce={class:"icon"},Te={class:"fcrm_import_content"},Ve={class:"upload-icon"},De={class:"el-upload__text"};const xe=I({name:"all-sequences",components:{Icons:F,PageHeader:K,TopNav:J,DataTable:R,FloatingBulkActionShell:Q,CreateSequence:I(Y,[["render",function(n,o,r,c,d,u){const p=a,m=t,h=e,g=s,_=l,f=i;return S(),$(_,{title:n.$t("Create new email sequence"),modelValue:u.isVisible,"onUpdate:modelValue":o[2]||(o[2]=e=>u.isVisible=e),"append-to-body":!0,"close-on-click-modal":!1,width:"640px",class:"fc-create-email-sequence"},{footer:w(()=>[k("span",L,[x((S(),$(g,{disabled:d.saving,type:"primary",onClick:o[1]||(o[1]=e=>u.save())},{default:w(()=>[E(D(n.$t("Next")),1)],void 0,!0),_:1},8,["disabled"])),[[f,d.saving]])])]),default:w(()=>[k("div",null,[C(h,{onSubmit:T(u.save,["prevent"]),model:d.sequence,"label-position":"top"},{default:w(()=>[C(m,{label:n.$t("Sequence Title")},{default:w(()=>[C(p,{ref:"title",placeholder:n.$t("Sequence Title"),modelValue:d.sequence.title,"onUpdate:modelValue":o[0]||(o[0]=e=>d.sequence.title=e),onKeyup:V(u.save,["enter"])},null,8,["placeholder","modelValue","onKeyup"]),k("span",z,D(d.errors.title),1)],void 0,!0),_:1},8,["label"])],void 0,!0),_:1},8,["onSubmit","model"])])],void 0),_:1},8,["title","modelValue"])}]]),Confirm:O,PaginationBar:M,InlineDoc:H,EditPen:u,CopyDocument:d,Delete:c,ArrowDownBold:r,Money:o,Close:n},data:()=>({sequences:[],pagination:{total:0,per_page:10,current_page:1},loading:!0,dialogVisible:!1,duplicating:!1,search:"",options:{sampleCsv:null,delimiter:"comma"},order:"desc",orderBy:"id",selection:!1,selectedSequences:[],deleting:!1,importDialogVisible:!1,inline_errors:null,allSelected:!1,current_mode:"system"===U.getCurrentTheme()?U.getSystemTheme():U.getCurrentTheme()}),computed:{url(){let e=window.ajaxurl;return e+=(e.match(/\?/)?"&":"?")+jQuery.param({action:"fluentcrm_import_sequence",_nonce:window.fcAdmin.rest.nonce}),e},canSelectAll(){if(!this.pagination||!this.pagination.per_page||!this.pagination.total)return!1;const e=this.selectedSequences.length===this.pagination.per_page,t=this.selectedSequences.length{void 0!==e[a]&&(t[a]=e[a])}),window.fcrm_seq_sub_params=t,t.t=Date.now(),this.$router.replace({name:"email-sequences",query:t}),delete e.t,this.$get("sequences",e).then(e=>{this.sequences=e.sequences.data,this.pagination.total=e.sequences.total}).catch(e=>{this.handleError(e)}).finally(()=>{this.loading=!1})},remove(e){this.$del(`sequences/${e.id}`).then(e=>{this.fetch(),this.$notify.success({title:this.$t("Great!"),message:e.message,offset:19})}).catch(e=>{this.handleError(e)})},duplicateSequence(e){this.duplicating=!0,this.$post(`sequences/${e.id}/duplicate`).then(e=>{this.$notify.success(e.message),this.$router.push({name:"edit-sequence",params:{id:e.sequence.id}})}).catch(e=>{this.handleError(e)}).finally(()=>{this.duplicating=!1})},exportSequence(e){location.href=window.ajaxurl+"?"+jQuery.param({action:"fluentcrm_export_sequence",sequence_id:e.id,_nonce:window.fcAdmin.rest.nonce})},handleSortable(e){"descending"===e.order?(this.orderBy=e.prop,this.order="desc"):(this.orderBy=e.prop,this.order="asc"),this.fetch()},onSelection(e){this.selection=!!e.length,this.selectedSequences=e,e.length>0&&e.length!==this.pagination.per_page&&(this.allSelected=!1),e.length||(this.allSelected=!1)},confirmAndDeleteSelected(){b.confirm(this.$t("Are you sure you want to delete the selected sequences?"),this.$t("Delete Sequences"),{confirmButtonText:this.$t("Delete"),cancelButtonText:this.$t("Cancel"),type:"warning"}).then(()=>{this.deleteSelected()}).catch(()=>{})},selectAllSequences(){this.canSelectAll&&(this.$refs.sequencesTable&&this.sequences&&this.sequences.length>0&&this.sequences.forEach(e=>{this.$refs.sequencesTable.toggleRowSelection(e,!0)}),this.allSelected=!0)},selectOnlyThisPage(){this.allSelected=!1;const e=this.sequences.map(e=>e.id);this.selectedSequences=this.selectedSequences.filter(t=>e.includes(t.id))},clearSequenceSelection(){this.$refs.sequencesTable&&this.$refs.sequencesTable.clearSelection(),this.selectedSequences=[],this.allSelected=!1,this.selection=!1},deleteSelected(){let e={sequence_ids:[]};this.allSelected?(e.select_all=!0,e.search=this.search||""):e.sequence_ids=this.selectedSequences.map(e=>e.id),this.deleting=!0,this.$post("sequences/do-bulk-action",e).then(e=>{this.$notify.success(e.message),this.fetch(),this.clearSequenceSelection()}).catch(e=>{this.handleError(e)}).finally(()=>{this.deleting=!1})},success(e){this.$notify.success(e.message),this.$router.push({name:"edit-sequence",params:{id:e.sequence.id}})},error(e){try{const t=JSON.parse(e.message);this.$notify.error(t.message),t.requires&&"string"==typeof t.requires&&(this.inline_errors=t.requires)}catch(t){this.$notify.error(t.message||this.$t("An error occurred. Please try again."))}},onThemeChanged(e){var t;this.current_mode=(null==(t=e.detail)?void 0:t.effective)||("system"===U.getCurrentTheme()?U.getSystemTheme():U.getCurrentTheme())}},mounted(){window.addEventListener(N,this.onThemeChanged),this.setup(),this.fetch(),this.changeTitle(this.$t("Email Sequences"))},beforeUnmount(){window.removeEventListener(N,this.onThemeChanged)}},[["render",function(e,t,n,o,r,c){const d=A("TopNav"),u=A("Icons"),b=s,T=h,I=m,F=p,N=A("inline-doc"),U=A("page-header"),O=a,M=g,H=A("icons"),J=f,K=A("router-link"),R=A("Money"),Q=y,Y=A("confirm"),z=_,L=A("pagination-bar"),xe=A("data-table"),Ee=A("Close"),Ae=A("floating-bulk-action-shell"),Pe=A("create-sequence"),je=q,Be=v,Ie=l,Fe=i;return S(),P("div",G,[k("div",W,[k("div",X,[C(d)])]),k("div",Z,[C(U,null,{title:w(()=>[E(D(e.$t("Email Sequences"))+" ",1),r.pagination.total?(S(),P("small",ee,"("+D(e.formatMoney(r.pagination.total))+")",1)):j("",!0)]),actions:w(()=>[e.hasPermission("fcrm_manage_emails")?(S(),$(F,{key:0,trigger:"click"},{dropdown:w(()=>[C(I,null,{default:w(()=>[C(T,{class:"fc_dropdown_action",onClick:t[0]||(t[0]=e=>r.importDialogVisible=!0)},{default:w(()=>[k("span",ae,[k("span",se,[C(u,{"icon-name":"import"})]),E(" "+D(e.$t("Import")),1)])],void 0,!0),_:1})],void 0,!0),_:1})]),default:w(()=>[C(b,{class:"el-dropdown-link"},{default:w(()=>[E(D(e.$t("More Actions"))+" ",1),k("span",te,[C(u,{"icon-name":"downIcon"})])],void 0,!0),_:1})],void 0,!0),_:1})):j("",!0),C(N,{doc_id:1601}),e.hasPermission("fcrm_manage_emails")?(S(),$(b,{key:1,type:"primary",onClick:t[1]||(t[1]=e=>r.dialogVisible=!0)},{default:w(()=>[k("span",ie,[C(u,{"icon-name":"plus"})]),E(" "+D(e.$t("Add Sequence")),1)],void 0,!0),_:1})):j("",!0)]),_:1}),C(xe,{"has-selection":!1},{"header-left":w(()=>[C(O,{clearable:"",size:"small",modelValue:r.search,"onUpdate:modelValue":t[2]||(t[2]=e=>r.search=e),onClear:c.fetch,onKeyup:V(c.fetch,["enter"]),placeholder:e.$t("Type and Enter...")},{prefix:w(()=>[k("span",le,[C(u,{"icon-name":"search"})])]),_:1},8,["modelValue","onClear","onKeyup","placeholder"])]),table:w(()=>[!r.loading&&!r.duplicating||r.sequences.length?x((S(),$(z,{key:1,stripe:"",border:"",ref:"sequencesTable",data:r.sequences,onSortChange:c.handleSortable,onSelectionChange:c.onSelection},{empty:w(()=>[k("div",ne,[C(H,{"icon-name":"common-empty-state"}),k("div",oe,[k("span",null,D(e.$t("Create your first email sequence to automate your email campaigns.")),1)])])]),default:w(()=>[C(J,{type:"selection",width:45}),C(J,{sortable:"custom","min-width":250,label:e.$t("Title"),prop:"title"},{default:w(e=>[C(K,{to:{name:"edit-sequence",params:{id:e.row.id},query:{t:(new Date).getTime()}}},{default:w(()=>[E(D(e.row.title),1)],void 0,!0),_:2},1032,["to"])]),_:1},8,["label"]),C(J,{width:190,label:e.$t("Emails")},{default:w(t=>[t.row.stats?(S(),P("span",re,[C(K,{to:{name:"edit-sequence",params:{id:t.row.id},query:{t:(new Date).getTime()}}},{default:w(()=>[E(D(e.$_n("%d Email","%d Emails",t.row.stats.emails)),1)],void 0,!0),_:2},1032,["to"]),t.row.stats.revenue&&t.row.stats.revenue.currency?(S(),P("span",{key:0,title:e.$t("Revenue From Sequence Emails")},[k("span",de,[C(Q,null,{default:w(()=>[C(R)],void 0,!0),_:1})]),E(" "+D(t.row.stats.revenue.currency)+" "+D(t.row.stats.revenue.amount),1)],8,ce)):j("",!0)])):(S(),P("span",ue,"--"))]),_:1},8,["label"]),C(J,{width:170,sortable:"custom",label:e.$t("Subscribers"),prop:"recipients_count"},{default:w(t=>[C(K,{to:{name:"sequence-subscribers",params:{id:t.row.id},query:{t:(new Date).getTime()}}},{default:w(()=>[k("span",null,D(e.$_n("%d subscriber","%d subscribers",t.row.stats.subscribers)),1)],void 0,!0),_:2},1032,["to"])]),_:1},8,["label"]),C(J,{width:180,sortable:"custom",label:e.$t("Created at"),prop:"created_at"},{default:w(t=>[k("span",null,D(e.nsHumanDiffTime(t.row.created_at)),1)]),_:1},8,["label"]),C(J,{fixed:"right",width:"60","class-name":"fcrm_table_actions_cell"},{default:w(t=>[C(F,{trigger:"click",placement:"bottom-end"},{dropdown:w(()=>[C(I,null,{default:w(()=>[e.hasPermission("fcrm_manage_emails")?(S(),$(T,{key:0,onClick:a=>e.$router.push({name:"edit-sequence",params:{id:t.row.id},query:{t:(new Date).getTime()}})},{default:w(()=>[k("span",me,[k("span",he,[C(u,{"icon-name":"EditPen"})]),E(" "+D(e.$t("Edit")),1)])],void 0,!0),_:1},8,["onClick"])):j("",!0),e.hasPermission("fcrm_manage_emails")?(S(),$(T,{key:1,onClick:e=>c.duplicateSequence(t.row)},{default:w(()=>[k("span",ge,[k("span",_e,[C(u,{"icon-name":"duplicate"})]),E(" "+D(e.$t("Duplicate")),1)])],void 0,!0),_:1},8,["onClick"])):j("",!0),e.hasPermission("fcrm_read_emails")?(S(),$(T,{key:2,onClick:e=>c.exportSequence(t.row)},{default:w(()=>[k("span",fe,[k("span",ye,[C(u,{"icon-name":"export"})]),E(" "+D(e.$t("Export")),1)])],void 0,!0),_:1},8,["onClick"])):j("",!0),e.hasPermission("fcrm_manage_email_delete")?(S(),$(T,{key:3,class:"fcrm_danger_action"},{default:w(()=>[C(Y,{placement:"top-start",message:e.$t("Are you sure you want to delete this Sequence?"),onYes:e=>c.remove(t.row)},{reference:w(()=>[k("span",qe,[k("span",ve,[C(u,{"icon-name":"delete"})]),E(" "+D(e.$t("Delete")),1)])]),_:1},8,["message","onYes"])],void 0,!0),_:2},1024)):j("",!0)],void 0,!0),_:2},1024)]),default:w(()=>[k("span",{class:"el-dropdown-link",role:"button",tabindex:"0","aria-label":e.$t("More actions")},[C(u,{"icon-name":"more_actions"})],8,pe)],void 0,!0),_:2},1024)]),_:1})],void 0,!0),_:1},8,["data","onSortChange","onSelectionChange"])),[[Fe,r.loading||r.duplicating]]):(S(),$(M,{key:0,style:{padding:"20px"},rows:7}))]),pagination:w(()=>[C(L,{pagination:r.pagination,onFetch:c.fetch},null,8,["pagination","onFetch"])]),_:1}),C(Ae,{visible:r.selection&&!r.loading&&!r.duplicating&&r.pagination.total,"theme-mode":r.current_mode,"custom-layout":!0},{default:w(()=>[k("div",be,[k("div",Se,[C(b,{link:"","aria-label":e.$t("Deselect"),onClick:c.clearSequenceSelection},{default:w(()=>[C(Q,null,{default:w(()=>[C(Ee)],void 0,!0),_:1})],void 0,!0),_:1},8,["aria-label","onClick"]),k("span",$e,[r.allSelected?(S(),P(B,{key:0},[E(D(e.$t("All"))+" ",1),k("strong",null,D(r.pagination.total),1),E(" "+D(e.$t("selected")),1)],64)):(S(),P(B,{key:1},[k("strong",null,D(r.selectedSequences.length),1),E(" "+D(e.$t("selected")),1)],64))]),c.canSelectAll&&!r.allSelected?(S(),P("span",we)):j("",!0),c.canSelectAll&&!r.allSelected?(S(),$(b,{key:1,link:"",onClick:c.selectAllSequences},{default:w(()=>[E(D(e.$t("Select All"))+" "+D(r.pagination.total),1)],void 0,!0),_:1},8,["onClick"])):j("",!0),r.allSelected?(S(),P("span",ke)):j("",!0),r.allSelected?(S(),$(b,{key:3,link:"",onClick:c.selectOnlyThisPage},{default:w(()=>[E(D(e.$t("Select only this page")),1)],void 0,!0),_:1},8,["onClick"])):j("",!0),t[5]||(t[5]=k("span",{class:"fc_bulk_divider","aria-hidden":"true"},null,-1)),e.hasPermission("fcrm_manage_email_delete")?x((S(),$(b,{key:4,disabled:r.deleting,type:"danger",size:"small",plain:"",onClick:c.confirmAndDeleteSelected},{default:w(()=>[k("span",Ce,[C(u,{"icon-name":"delete"})]),E(" "+D(e.$t("Delete")),1)],void 0,!0),_:1},8,["disabled","onClick"])),[[Fe,r.deleting]]):j("",!0)])])],void 0),_:1},8,["visible","theme-mode"]),C(Pe,{modelValue:r.dialogVisible,"onUpdate:modelValue":t[3]||(t[3]=e=>r.dialogVisible=e)},null,8,["modelValue"]),C(Ie,{title:e.$t("Import Sequence"),modelValue:r.importDialogVisible,"onUpdate:modelValue":t[4]||(t[4]=e=>r.importDialogVisible=e),"append-to-body":!0,"close-on-click-modal":!1,width:"640px","modal-class":"fcrm_import_dialog"},{default:w(()=>[k("div",Te,[k("h3",null,D(e.$t("Upload JSON File")),1),C(je,{drag:"",limit:1,action:c.url,ref:"uploader",multiple:!1,"on-error":c.error,"on-success":c.success,"aria-label":e.$t("Upload JSON file by dragging or clicking")},{default:w(()=>[k("span",Ve,[C(u,{"icon-name":"upload"})]),k("div",De,D(e.$t("Choose a file or drag & drop it here.")),1),C(b,null,{default:w(()=>[E(D(e.$t("Browse File")),1)],void 0,!0),_:1})],void 0,!0),_:1},8,["action","on-error","on-success","aria-label"]),C(Be,{title:e.$t("Email_Sequence_Import_Note"),type:"info","show-icon":"",closable:!1},null,8,["title"]),r.inline_errors?(S(),$(Be,{key:0,title:r.inline_errors,type:"error","show-icon":"",closable:!1},null,8,["title"])):j("",!0)])],void 0),_:1},8,["title","modelValue"])])])}]]);export{xe as default};