import{c as e,n as t,E as a,k as l,ay as i,o as s,a6 as o,a2 as n,ac as r,j as c,h as p,i as m,aB as d,aH as h,aI as _,e as u,aR as g,aS as f,g as v}from"../../../../vendor-element-plus.js?ver=3.1.8";import{aQ as w,W as y,X as T,Z as b,ab as $,a5 as k,J as S,a9 as C,aa as D,a8 as P,Y as I,a6 as A,ac as B,ay as E,b2 as j}from"../../../../vendor.js?ver=3.1.8";import{C as x}from"../../../../Confirm.js?ver=3.1.8";import{P as V}from"../../../../PaginationBar.js?ver=3.1.8";import{_ as O,I as N,a as F,T as L}from"../../../../fc-bits-ui.js?ver=3.1.8";import{I as U}from"../../../../InlineDoc.js?ver=3.1.8";import{E as H}from"../../../../EmailPreview.js?ver=3.1.8";import{B as M}from"../../../../BuiltinTemplateDrawer.js?ver=3.1.8";import{F as q}from"../../../../FloatingBulkActionShell.js?ver=3.1.8";import{T as G}from"../../../../TopNav.js?ver=3.1.8";import{P as R}from"../../../../PageHeader.js?ver=3.1.8";import{D as J}from"../../../../DataTable.js?ver=3.1.8";import{G as Q}from"../../../../GenericPromo.js?ver=3.1.8";import"../../../../PreviewIframeBuilder.js?ver=3.1.8";import"../../../../TestEmail.js?ver=3.1.8";import"../../../../CampaignSubjectLines.js?ver=3.1.8";import"../../../../PromoCard.js?ver=3.1.8";const Y={name:"BulkTemplateAction",components:{Icons:N,Close:e},emits:["deselect-all","refetch","select-all","select-only-this-page"],props:{selectedTemplates:{type:Array,default:()=>[]},totalCount:{type:Number,default:0},currentPageCount:{type:Number,default:0},perPage:{type:Number,default:10},allSelected:{type:Boolean,default:!1},search:{type:String,default:""}},computed:{allSelectedOnPage(){const e=this.selectedTemplates.length,t=this.currentPageCount;return t>0&&e===t&&e===this.perPage}},data:()=>({doing_action:!1}),methods:{confirmAndDeleteTemplates(){t.confirm(this.$t("Are you sure to delete?")+" "+this.$t("delete_all_templates_notice"),this.$t("Delete Templates"),{confirmButtonText:this.$t("Delete"),cancelButtonText:this.$t("Cancel"),type:"warning"}).then(()=>{this.doBulkAction()}).catch(()=>{})},doBulkAction(){let e={action_name:"delete_templates"};this.allSelected?(e.select_all=!0,e.search=this.search||""):e.template_ids=this.selectedTemplates.map(e=>e.ID),this.doing_action=!0,this.$post("templates/do-bulk-action",e).then(e=>{this.$notify.success(e.message),this.$emit("refetch")}).catch(e=>{this.handleError(e)}).finally(()=>{this.doing_action=!1})}}},K={class:"fcrm_bulk_action_bar"},W={class:"fcrm_bulk_action_left"},z={class:"fc_bulk_selection_count"},X={key:0,class:"fc_bulk_divider","aria-hidden":"true"},Z={key:2,class:"fc_bulk_divider","aria-hidden":"true"},ee={class:"icon"};const te={class:"fcrm_email_templates_page"},ae={class:"fcrm_page_header_top_nav_wrapper"},le={class:"fcrm_page_header_top_nav"},ie={class:"fcrm-layout-width"},se={class:"icon"},oe={class:"el-popover__reference"},ne={class:"icon"},re={class:"icon"},ce={class:"icon"},pe={class:"fcrm_empty_state"},me={class:"fcrm_empty_state_text"},de={class:"fcrm_template_type_icon"},he=["title"],_e=["onClick"],ue={class:"fcrm_template_preview_pill_btn"},ge={class:"el-dropdown-link"},fe={class:"el-popover__reference"},ve={class:"icon"},we={class:"el-popover__reference"},ye={class:"icon"},Te={class:"el-popover__reference"},be={class:"icon"},$e={class:"el-popover__reference"},ke={class:"icon"},Se={key:2},Ce={key:0,class:"fcrm_import_content"},De={class:"upload-icon"},Pe={class:"el-upload__text"};const Ie=O({name:"Templates",components:{CopyDocument:r,GenericPromo:Q,Icons:N,PageHeader:R,FloatingBulkActionShell:q,DataTable:J,TopNav:G,EmailPreview:H,Confirm:x,PaginationBar:V,BulkTemplateAction:O(Y,[["render",function(e,t,s,o,n,r){const c=w("Close"),p=a,m=l,d=w("Icons"),h=i;return y(),T("div",K,[b("div",W,[$(m,{link:"","aria-label":e.$t("Deselect"),onClick:t[0]||(t[0]=t=>e.$emit("deselect-all"))},{default:k(()=>[$(p,null,{default:k(()=>[$(c)],void 0,!0),_:1})],void 0),_:1},8,["aria-label"]),b("span",z,[s.allSelected?(y(),T(S,{key:0},[C(D(e.$t("All"))+" ",1),b("strong",null,D(s.totalCount),1),C(" "+D(e.$t("selected")),1)],64)):(y(),T(S,{key:1},[b("strong",null,D(s.selectedTemplates.length),1),C(" "+D(e.$t("selected")),1)],64))]),r.allSelectedOnPage&&!s.allSelected?(y(),T("span",X)):P("",!0),r.allSelectedOnPage&&!s.allSelected?(y(),I(m,{key:1,link:"",onClick:t[1]||(t[1]=t=>e.$emit("select-all"))},{default:k(()=>[C(D(e.$t("Select All"))+" "+D(s.totalCount),1)],void 0),_:1})):P("",!0),s.allSelected?(y(),T("span",Z)):P("",!0),s.allSelected?(y(),I(m,{key:3,link:"",onClick:t[2]||(t[2]=t=>e.$emit("select-only-this-page"))},{default:k(()=>[C(D(e.$t("Select only this page")),1)],void 0),_:1})):P("",!0),t[3]||(t[3]=b("span",{class:"fc_bulk_divider","aria-hidden":"true"},null,-1)),e.hasPermission("fcrm_manage_email_delete")?A((y(),I(m,{key:4,disabled:n.doing_action,type:"danger",size:"small",plain:"",onClick:r.confirmAndDeleteTemplates},{default:k(()=>[b("span",ee,[$(d,{"icon-name":"delete"})]),C(" "+D(e.$t("Delete")),1)],void 0),_:1},8,["disabled","onClick"])),[[h,n.doing_action]]):P("",!0)])])}]]),InlineDoc:U,BuiltinTemplateDrawer:M,EditPen:n,Delete:o,View:s},data:()=>({loading:!1,templates:[],pagination:{current_page:1,per_page:20,total:0},url:"",title:"",dialogVisible:!1,order:"descending",orderBy:"ID",search:"",selection:!1,selectedTemplates:[],open_drawer:!1,show_drawer:!1,builtInTemplates:[],isLoadingTemplates:!1,importing:!1,oneTimeFetch:!0,showTemplatePreview:!1,previewTemplateId:"",email_template:{post_title:"",post_content:"",post_excerpt:"",email_subject:"",edit_type:"html",design_template:"simple",settings:{template_config:{}}},importDialogVisible:!1,inline_errors:null,allSelected:!1,current_mode:"system"===L.getCurrentTheme()?L.getSystemTheme():L.getCurrentTheme()}),computed:{importUrl(){let e=window.ajaxurl;return e+=(e.match(/\?/)?"&":"?")+jQuery.param({action:"fluentcrm_import_template"}),e},canSelectAll(){if(!this.pagination||!this.pagination.per_page||!this.pagination.total)return!1;const e=this.selectedTemplates.length===this.pagination.per_page,t=this.selectedTemplates.length({fontWeight:500,color:"publish"===e?"green":"gray"}),setup(){let e=this.$route.query;if(window.fcrm_template_sub_params&&(e=window.fcrm_template_sub_params),this.search=e.search||"",this.order="ascending"===e.order?"ASC":"DESC",this.orderBy=e.orderBy,e.page&&(this.pagination.current_page=parseInt(e.page)),e.per_page)this.pagination.per_page=parseInt(e.per_page);else{const e=parseInt(this.storage.get("template_perpage",20))||20;this.pagination.per_page=e}return!1},fetch(){this.loading=!0,this.selection=!1,this.storage.set("template_perpage",this.pagination.per_page);const e={order:"ascending"==this.order?"ASC":"DESC",orderBy:this.orderBy,per_page:this.pagination.per_page,page:this.pagination.current_page,search:this.search},t={};Object.keys(e).forEach(a=>{void 0!==e[a]&&(t[a]=e[a])}),window.fcrm_template_sub_params=t,t.t=Date.now(),this.$router.replace({name:"templates",query:t}),e.types=["publish","draft"],this.$get("templates",e).then(e=>{this.templates=e.templates.data,this.pagination.total=e.templates.total}).catch(e=>{this.handleError(e)}).finally(()=>{this.loading=!1})},onSelection(e){this.selection=!!e.length,this.selectedTemplates=e,e.length>0&&e.length!==this.pagination.per_page&&(this.allSelected=!1),e.length||(this.allSelected=!1)},clearTemplateSelection(){this.$refs.templateTable&&this.$refs.templateTable.clearSelection(),this.selectedTemplates=[],this.allSelected=!1,this.selection=!1},selectAllTemplates(){this.canSelectAll&&(this.$refs.templateTable&&this.templates&&this.templates.length>0&&this.templates.forEach(e=>{this.$refs.templateTable.toggleRowSelection(e,!0)}),this.allSelected=!0)},selectOnlyThisPage(){this.allSelected=!1;const e=this.templates.map(e=>e.ID);this.selectedTemplates=this.selectedTemplates.filter(t=>e.includes(t.ID))},duplicate(e){this.duplicating=!0,this.$post(`templates/duplicate/${e.ID}`).then(e=>{this.$notify.success(e.message),this.fetch(),this.$router.push({name:"edit_template",params:{template_id:e.template_id},query:{is_new:"yes"}})}).catch(e=>{this.handleError(e)}).finally(()=>{this.duplicating=!1})},edit(e){this.$router.push({name:"edit_template",params:{template_id:e.ID}})},remove(e){this.$del(`templates/${e.ID}`).then(e=>{this.fetch(),this.$notify.success({title:this.$t("Great!"),message:e.message,offset:19})})},syncVisibility(){this.dialogVisible=!1},onDialogClose(){this.fetch(),this.url=""},sortTemplates(e){this.orderBy=e.prop,this.order=e.order,this.fetch()},exportTemplate(e){this.has_campaign_pro?location.href=window.ajaxurl+"?"+jQuery.param({action:"fluentcrm_export_template",template_id:e.ID,_nonce:window.fcAdmin.nonce}):this.$notify.error(this.$t("Template_Export_Alert"))},showPreview(e){this.previewTemplateId=e.ID,this.fetchTemplate()},openBuiltinTemplateDrawer(){this.open_drawer=!0},fetchTemplate(){this.$get(`templates/${this.previewTemplateId}`).then(e=>{this.email_template=e.template,this.showTemplatePreview=!0}).catch(e=>{this.handleError(e)})},success(e){this.$notify.success(e.message),this.$router.push({name:"edit_template",params:{template_id:e.template_id}})},error(e){try{const t=JSON.parse(e.message);this.$notify.error(t.message),t.requires&&(this.inline_errors=t.requires)}catch(t){this.$notify.error(e.message||this.$t("An error occurred"))}},onThemeChanged(e){var t;this.current_mode=(null==(t=e.detail)?void 0:t.effective)||("system"===L.getCurrentTheme()?L.getSystemTheme():L.getCurrentTheme())}},mounted(){window.addEventListener(F,this.onThemeChanged),this.setup(),this.fetch(),this.changeTitle(this.$t("Email Templates"))},beforeUnmount(){window.removeEventListener(F,this.onThemeChanged)}},[["render",function(e,t,s,o,n,r){const S=w("TopNav"),x=w("Icons"),V=l,O=m,N=p,F=c,L=w("inline-doc"),U=w("page-header"),H=u,M=d,q=w("icons"),G=_,R=w("router-link"),J=w("View"),Q=a,Y=w("confirm"),K=h,W=w("email-preview"),z=w("pagination-bar"),X=w("data-table"),Z=w("bulk-template-action"),ee=w("floating-bulk-action-shell"),Ie=g,Ae=f,Be=w("generic-promo"),Ee=v,je=w("builtin-template-drawer"),xe=i;return y(),T("div",te,[b("div",ae,[b("div",le,[$(S)]),t[6]||(t[6]=b("div",{class:"fcrm_page_header_top_actions"},null,-1))]),b("div",ie,[$(U,null,{title:k(()=>[C(D(e.$t("Email Templates"))+" ",1),A(b("small",null,"("+D(e.formatMoney(n.pagination.total))+")",513),[[B,n.pagination.total]])]),actions:k(()=>[e.hasPermission("fcrm_manage_email_templates")?(y(),I(F,{key:0,trigger:"click"},{dropdown:k(()=>[$(N,null,{default:k(()=>[$(O,{class:"fc_dropdown_action",onClick:t[0]||(t[0]=e=>n.importDialogVisible=!0)},{default:k(()=>[b("span",oe,[b("span",ne,[$(x,{"icon-name":"import"})]),C(" "+D(e.$t("Import")),1)])],void 0,!0),_:1})],void 0,!0),_:1})]),default:k(()=>[$(V,{class:"el-dropdown-link"},{default:k(()=>[C(D(e.$t("More Actions"))+" ",1),b("span",se,[$(x,{"icon-name":"downIcon"})])],void 0,!0),_:1})],void 0,!0),_:1})):P("",!0),$(L,{doc_id:1729}),e.hasPermission("fcrm_manage_email_templates")?(y(),I(V,{key:1,type:"primary",onClick:t[1]||(t[1]=e=>r.openBuiltinTemplateDrawer())},{default:k(()=>[b("span",re,[$(x,{"icon-name":"plus"})]),C(" "+D(e.$t("Add Template")),1)],void 0,!0),_:1})):P("",!0)]),_:1}),$(X,{"has-selection":!1},E({"header-left":k(()=>[$(H,{clearable:"",modelValue:n.search,"onUpdate:modelValue":t[2]||(t[2]=e=>n.search=e),onClear:r.fetch,onKeyup:j(r.fetch,["enter"]),placeholder:e.$t("Type and Enter...")},{prefix:k(()=>[b("span",ce,[$(x,{"icon-name":"search"})])]),_:1},8,["modelValue","onClear","onKeyup","placeholder"])]),table:k(()=>[n.loading&&!n.templates.length?(y(),I(M,{key:0,style:{padding:"20px"},rows:7})):A((y(),I(K,{key:1,ref:"templateTable",border:"",data:n.templates,style:{width:"100%"},stripe:"","default-sort":{prop:n.orderBy,order:n.order},onSortChange:r.sortTemplates,onSelectionChange:r.onSelection},{empty:k(()=>[b("div",pe,[$(q,{"icon-name":"common-empty-state"}),b("div",me,[b("span",null,D(e.$t("Create your first email template to save time on future emails.")),1)])])]),default:k(()=>[$(G,{type:"selection",width:45}),$(G,{label:e.$t("ID"),width:"100",prop:"ID",sortable:"custom"},null,8,["label"]),$(G,{prop:"post_title","min-width":"450",label:e.$t("Title"),sortable:"custom"},{default:k(e=>[$(R,{class:"template-title",to:{name:"edit_template",params:{template_id:e.row.ID}}},{default:k(()=>[b("span",de,["visual_builder"==e.row.design_template?(y(),I(x,{key:0,"icon-name":"visualBuilder"})):"raw_classic"==e.row.design_template?(y(),I(x,{key:1,"icon-name":"classicEditor"})):"raw_html"==e.row.design_template?(y(),I(x,{key:2,"icon-name":"rawHTML"})):(y(),I(x,{key:3,"icon-name":"gutenberg"}))]),C(" "+D(e.row.post_title),1)],void 0,!0),_:2},1032,["to"])]),_:1},8,["label"]),$(G,{width:"190",label:e.$t("Last Modified"),prop:"post_modified",sortable:"custom"},{default:k(t=>[b("span",{title:t.row.post_modified},D(e.nsHumanDiffTime(t.row.post_modified)),9,he)]),_:1},8,["label"]),$(G,{width:"160",label:e.$t("Preview")},{default:k(t=>[b("div",{class:"fcrm_preview_text_with_icon_btn",onClick:e=>r.showPreview(t.row)},[b("span",ue,[$(Q,null,{default:k(()=>[$(J)],void 0,!0),_:1}),b("span",null,D(e.$t("Show Preview")),1)])],8,_e)]),_:1},8,["label"]),$(G,{fixed:"right",align:"center",width:"60","class-name":"fcrm_table_actions_cell"},{default:k(t=>[$(F,{trigger:"click",placement:"bottom-end"},{dropdown:k(()=>[$(N,null,{default:k(()=>[e.hasPermission("fcrm_manage_email_templates")?(y(),I(O,{key:0,onClick:e=>r.edit(t.row)},{default:k(()=>[b("span",fe,[b("span",ve,[$(x,{"icon-name":"EditPen"})]),C(" "+D(e.$t("Edit")),1)])],void 0,!0),_:1},8,["onClick"])):P("",!0),e.hasPermission("fcrm_manage_email_templates")?(y(),I(O,{key:1,onClick:e=>r.duplicate(t.row)},{default:k(()=>[b("span",we,[b("span",ye,[$(x,{"icon-name":"duplicate"})]),C(" "+D(e.$t("Duplicate")),1)])],void 0,!0),_:1},8,["onClick"])):P("",!0),e.hasPermission("fcrm_manage_email_templates")?(y(),I(O,{key:2,onClick:e=>r.exportTemplate(t.row)},{default:k(()=>[b("span",Te,[b("span",be,[$(x,{"icon-name":"export"})]),C(" "+D(e.$t("Export")),1)])],void 0,!0),_:1},8,["onClick"])):P("",!0),e.hasPermission("fcrm_manage_email_templates")?(y(),I(O,{key:3,class:"fcrm_danger_action"},{default:k(()=>[$(Y,{placement:"top-start",message:e.$t("Delete_Template_Alert"),onYes:e=>r.remove(t.row)},{reference:k(()=>[b("span",$e,[b("span",ke,[$(x,{"icon-name":"delete"})]),C(" "+D(e.$t("Delete")),1)])]),_:1},8,["message","onYes"])],void 0,!0),_:2},1024)):P("",!0)],void 0,!0),_:2},1024)]),default:k(()=>[b("span",ge,[$(x,{"icon-name":"more_actions"})])],void 0,!0),_:2},1024)]),_:1})],void 0,!0),_:1},8,["data","default-sort","onSortChange","onSelectionChange"])),[[xe,n.loading]]),n.showTemplatePreview?(y(),T("div",Se,[$(W,{onModalClosed:t[3]||(t[3]=()=>{n.showTemplatePreview=!1}),auto_load:!0,show_audit:!0,campaign:n.email_template},null,8,["campaign"])])):P("",!0)]),_:2},[n.loading?void 0:{name:"pagination",fn:k(()=>[$(z,{pagination:n.pagination,onFetch:r.fetch},null,8,["pagination","onFetch"])]),key:"0"}]),1024),$(ee,{visible:n.selection,"theme-mode":n.current_mode,"custom-layout":!0},{default:k(()=>[$(Z,{selectedTemplates:n.selectedTemplates,"total-count":n.pagination.total,"per-page":n.pagination.per_page,"current-page-count":n.templates.length,"all-selected":n.allSelected,search:n.search,onRefetch:r.fetch,onDeselectAll:r.clearTemplateSelection,onSelectAll:r.selectAllTemplates,onSelectOnlyThisPage:r.selectOnlyThisPage},null,8,["selectedTemplates","total-count","per-page","current-page-count","all-selected","search","onRefetch","onDeselectAll","onSelectAll","onSelectOnlyThisPage"])],void 0),_:1},8,["visible","theme-mode"])]),$(Ee,{title:e.$t("Import Template"),modelValue:n.importDialogVisible,"onUpdate:modelValue":t[4]||(t[4]=e=>n.importDialogVisible=e),"append-to-body":!0,"close-on-click-modal":!1,width:"640px","modal-class":"fcrm_import_dialog"},{default:k(()=>[e.has_campaign_pro?(y(),T("div",Ce,[b("h3",null,D(e.$t("Upload JSON File")),1),$(Ie,{drag:"",limit:1,action:r.importUrl,ref:"uploader",multiple:!1,"on-error":r.error,"on-success":r.success},{default:k(()=>[b("span",De,[$(x,{"icon-name":"upload"})]),b("div",Pe,D(e.$t("Choose a file or drag & drop it here.")),1),$(V,null,{default:k(()=>[C(D(e.$t("Browse File")),1)],void 0,!0),_:1})],void 0,!0),_:1},8,["action","on-error","on-success"]),$(Ae,{title:e.$t("Not_Import_Templates_Alert"),type:"info","show-icon":"",closable:!1},null,8,["title"]),n.inline_errors?(y(),I(Ae,{key:0,title:n.inline_errors,type:"error","show-icon":"",closable:!1},null,8,["title"])):P("",!0)])):(y(),I(Be,{key:1}))],void 0),_:1},8,["title","modelValue"]),$(je,{create_mode:!0,open_drawer:n.open_drawer,"onUpdate:open_drawer":t[5]||(t[5]=e=>n.open_drawer=e)},null,8,["open_drawer"])])}]]);export{Ie as default};