import{aA as t,aB as r,aH as e,aI as a,ay as s,k as o,aD as i}from"../../../../vendor-element-plus.js?ver=3.1.8";import{aQ as n,W as l,X as d,ab as c,a5 as h,Z as _,Y as p,a6 as u,J as m,az as y,a9 as b,aa as f,a8 as g}from"../../../../vendor.js?ver=3.1.8";import{P as v}from"../../../../PaginationBar.js?ver=3.1.8";import{D as k}from"../../../../DataTable.js?ver=3.1.8";import{_ as S}from"../../../../fc-bits-ui.js?ver=3.1.8";const C={class:"purchase_history_block fcrm_mb_24"},P={class:"fcrm_table_header_inner_left_title"},w={class:"fcrm_purchase_history_table_header_actions"},H={class:"fcrm_purchase_history_table_body"},D=["innerHTML"],T=["innerHTML"],q=["innerHTML"];const $={key:0,class:"fluentcrm_purchase_history_wrapper"},B={key:1},L={class:"text-align-center"};const M=S({name:"ProfilePurchaseHistory",props:["subscriber_id"],components:{PurchaseHistoryBlock:S({name:"PurchaseHistoryBlock",props:["provider","subscriber_id"],components:{PaginationBar:v,DataTable:k},data:()=>({loading:!1,orders:[],pagination:{per_page:10,current_page:1,total:0},sidebar_html:"",after_html:"",has_recount:!1,columnsConfig:{},query_data:{sort_by:"",sort_type:""},sortState:{currentProp:"",direction:""}}),computed:{table_columns(){let t=[];return this.orders&&this.orders.length&&(t=this.orders[0]),t}},methods:{handleSortable(t){t.prop?(this.query_data.sort_by=t.prop,this.sortState.currentProp!==t.prop?(this.sortState.currentProp=t.prop,this.sortState.direction="ASC"):this.sortState.direction="ASC"===this.sortState.direction?"DESC":"ASC",this.query_data.sort_type=this.sortState.direction,this.fetch()):(this.query_data.sort_by="",this.query_data.sort_type="",this.sortState.currentProp="",this.sortState.direction="")},fetch(t=!1){this.loading=!0,this.$get(`subscribers/${this.subscriber_id}/purchase-history`,{provider:this.provider.provider_key,page:this.pagination.current_page,per_page:this.pagination.per_page,sort_by:this.query_data.sort_by,sort_type:this.query_data.sort_type,will_recount:t}).then(t=>{this.orders=t.orders.data,this.pagination.total=parseInt(t.orders.total),t.orders.sidebar_html&&(this.sidebar_html=t.orders.sidebar_html),t.orders.after_html&&(this.after_html=t.orders.after_html),this.has_recount=t.orders.has_recount,t.orders.columns_config&&(this.columnsConfig=t.orders.columns_config)}).catch(t=>{this.handleError(t)}).finally(()=>{this.loading=!1})}},mounted(){this.fetch()}},[["render",function(v,k,S,$,B,L){const M=o,j=r,A=a,x=e,E=n("pagination-bar"),F=n("data-table"),z=t,I=i,J=s;return l(),d("div",C,[c(I,{gutter:24},{default:h(()=>[c(z,{md:B.sidebar_html?16:24,sm:24},{default:h(()=>[c(F,{class:"fcrm_purchase_history_table_wrapper",wrapper_border:!0,"has-selection":!1},{"header-left":h(()=>[_("h3",P,f(S.provider.title),1)]),"header-actions":h(()=>[_("div",w,[B.has_recount?(l(),p(M,{key:0,class:"fcrm_purchase_history_resync_btn",onClick:k[0]||(k[0]=t=>L.fetch("yes")),type:"default",size:"small"},{default:h(()=>[b(f(v.$t("Re-Sync")),1)],void 0,!0),_:1})):g("",!0)])]),table:h(()=>[_("div",H,[B.loading?(l(),p(j,{key:0,animated:"",rows:10})):u((l(),p(x,{key:1,"empty-text":v.$t("No Data Found"),border:"",stripe:"",data:B.orders,onSortChange:L.handleSortable},{empty:h(()=>[_("p",null,[b(f(v.$t("Purchase History from"))+" ",1),_("b",null,f(S.provider.name),1),b(" "+f(v.$t("PurchaseHistoryBlock.empty_desc")),1)])]),default:h(()=>[(l(!0),d(m,null,y(L.table_columns,(t,r)=>{var e,a;return l(),p(A,{key:r,width:B.columnsConfig[r]?B.columnsConfig[r].width:"",label:B.columnsConfig[r]&&B.columnsConfig[r].label?B.columnsConfig[r].label:"",prop:(null==(e=B.columnsConfig[r])?void 0:e.sortable)?B.columnsConfig[r].key:"",sortable:!!(null==(a=B.columnsConfig[r])?void 0:a.sortable)},{default:h(t=>[_("div",{innerHTML:t.row[r]},null,8,D)]),_:2},1032,["width","label","prop","sortable"])}),128))],void 0,!0),_:1},8,["empty-text","data","onSortChange"])),[[J,B.loading]]),B.after_html?(l(),d("div",{key:2,class:"fc_history_before",innerHTML:B.after_html},null,8,T)):g("",!0)])]),pagination:h(()=>[c(E,{pagination:B.pagination,onFetch:L.fetch},null,8,["pagination","onFetch"])]),_:1})],void 0,!0),_:1},8,["md"]),B.sidebar_html?(l(),p(z,{key:0,md:8,sm:24},{default:h(()=>[_("div",{class:"fc_history_sidebar",innerHTML:B.sidebar_html},null,8,q)],void 0,!0),_:1})):g("",!0)],void 0),_:1})])}]])},data:()=>({providersData:{},app_ready:!1}),computed:{is_empty_item(){return this.isEmptyValue(this.providersData)}},mounted(){this.each(window.fcAdmin.purchase_providers,(t,r)=>{const e={title:t.title,name:t.name,provider_key:r};this.providersData[r]=e}),this.app_ready=!0}},[["render",function(t,r,e,a,s,o){const i=n("purchase-history-block");return s.app_ready?(l(),d("div",$,[o.is_empty_item?(l(),d("div",B,[_("h3",L,f(t.$t("Pro_Purchase_hfEwbsh")),1)])):(l(!0),d(m,{key:0},y(s.providersData,(t,r)=>(l(),p(i,{key:r,provider:t,subscriber_id:e.subscriber_id},null,8,["provider","subscriber_id"]))),128))])):g("",!0)}]]);export{M as default};
