import{aA as t,aB as r,aH as e,aI as s,ay as a,k as o,aD as i}from"../../../../vendor-element-plus.js?ver=3.1.0";import{P as n}from"../../../../PaginationBar.js?ver=3.1.0";import{D as l}from"../../../../DataTable.js?ver=3.1.0";import{r as d,c,o as h,d as _,w as p,a as u,L as m,b as y,K as b,Q as f,as as g,O as v,P as k}from"../../../../vendor.js?ver=3.1.0";import{_ as S}from"../../../../fc-bits-ui.js?ver=3.1.0";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 L={key:0,class:"fluentcrm_purchase_history_wrapper"},$={key:1},B={class:"text-align-center"};const M=S({name:"ProfilePurchaseHistory",props:["subscriber_id"],components:{PurchaseHistoryBlock:S({name:"PurchaseHistoryBlock",props:["provider","subscriber_id"],components:{PaginationBar:n,DataTable:l},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(n,l,S,L,$,B){const M=o,j=r,A=s,x=e,E=d("pagination-bar"),F=d("data-table"),I=t,z=i,K=a;return h(),c("div",C,[_(z,{gutter:24},{default:p(()=>[_(I,{md:$.sidebar_html?16:24,sm:24},{default:p(()=>[_(F,{class:"fcrm_purchase_history_table_wrapper",wrapper_border:!0,"has-selection":!1},{"header-left":p(()=>[y("h3",P,k(S.provider.title),1)]),"header-actions":p(()=>[y("div",w,[$.has_recount?(h(),u(M,{key:0,class:"fcrm_purchase_history_resync_btn",onClick:l[0]||(l[0]=t=>B.fetch("yes")),type:"default",size:"small"},{default:p(()=>[v(k(n.$t("Re-Sync")),1)],void 0,!0),_:1})):m("",!0)])]),table:p(()=>[y("div",H,[$.loading?(h(),u(j,{key:0,animated:"",rows:10})):b((h(),u(x,{key:1,"empty-text":n.$t("No Data Found"),border:"",stripe:"",data:$.orders,onSortChange:B.handleSortable},{empty:p(()=>[y("p",null,[v(k(n.$t("Purchase History from"))+" ",1),y("b",null,k(S.provider.name),1),v(" "+k(n.$t("PurchaseHistoryBlock.empty_desc")),1)])]),default:p(()=>[(h(!0),c(f,null,g(B.table_columns,(t,r)=>{var e,s;return h(),u(A,{key:r,width:$.columnsConfig[r]?$.columnsConfig[r].width:"",label:$.columnsConfig[r]&&$.columnsConfig[r].label?$.columnsConfig[r].label:"",prop:(null==(e=$.columnsConfig[r])?void 0:e.sortable)?$.columnsConfig[r].key:"",sortable:!!(null==(s=$.columnsConfig[r])?void 0:s.sortable)},{default:p(t=>[y("div",{innerHTML:t.row[r]},null,8,D)]),_:2},1032,["width","label","prop","sortable"])}),128))],void 0,!0),_:1},8,["empty-text","data","onSortChange"])),[[K,$.loading]]),$.after_html?(h(),c("div",{key:2,class:"fc_history_before",innerHTML:$.after_html},null,8,T)):m("",!0)])]),pagination:p(()=>[_(E,{pagination:$.pagination,onFetch:B.fetch},null,8,["pagination","onFetch"])]),_:1})],void 0,!0),_:1},8,["md"]),$.sidebar_html?(h(),u(I,{key:0,md:8,sm:24},{default:p(()=>[y("div",{class:"fc_history_sidebar",innerHTML:$.sidebar_html},null,8,q)],void 0,!0),_:1})):m("",!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,s,a,o){const i=d("purchase-history-block");return a.app_ready?(h(),c("div",L,[o.is_empty_item?(h(),c("div",$,[y("h3",B,k(t.$t("Pro_Purchase_hfEwbsh")),1)])):(h(!0),c(f,{key:0},g(a.providersData,(t,r)=>(h(),u(i,{key:r,provider:t,subscriber_id:e.subscriber_id},null,8,["provider","subscriber_id"]))),128))])):m("",!0)}]]);export{M as default};
