import{r as t,B as a,h as e,e as s}from"./p-03169580.js";const o="floodteam-graph-pay-splits floodteam-error .floodteam-error-wrapper{padding:0 !important}floodteam-graph-pay-splits .graph-pay-splits-wrapper{display:block;max-width:400px;width:90%;margin:0 auto}floodteam-graph-pay-splits h1{text-align:center;color:var(--ion-color-success) !important;font-size:2em;font-weight:bold}floodteam-graph-pay-splits floodteam-graph{display:block;max-width:400px;margin:0 auto}floodteam-graph-pay-splits floodteam-item h4{color:var(--ion-color-medium-shade) !important}floodteam-graph-pay-splits floodteam-item floodteam-badge{--floodteam-badge-padding:0 10px;--floodteam-badge-background:var(--ion-color-success);--floodteam-badge-color:#ffffff}";let r=class{constructor(a){t(this,a);this.users=[];this.datasets=[];this.labels=[];this.currentUsers=[]}async setUsers(t){try{this.currentUsers=typeof t==="string"?JSON.parse(t):t.length>0?t:this.graphPaySplitsEl.getAttribute("users")?JSON.parse(this.graphPaySplitsEl.getAttribute("users")):[];const a=["#3e95cd","#8e5ea2","#3cba9f","#e8c3b9","#c45850"];const e=[];this.users.map((t=>{this.labels.push(t.user.user_name);e.push(t.amount)}));this.datasets=[{backgroundColor:a,data:e}];return this.currentUsers}catch(t){console.log(t);return[]}}onUsersUpdate(){this.setUsers(this.users)}formatUSD(t){const a=new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"});return a.format(t)}getPaymentText(t){let a="";if(t.type==="manual"){a=`${this.formatUSD(t.amount)} paid manually`}else if(t.type==="charge"){a=`${this.formatUSD(t.amount)} paid on ${t.brand} card ending in ${t.ending_in}`}else if(t.type==="check"){a=`${this.formatUSD(t.amount)} paid by check ${t.check_number}`}return a}componentDidLoad(){if(!(a===null||a===void 0?void 0:a.isBrowser))return;this.setUsers(this.users)}render(){return e("div",{class:"graph-pay-splits-wrapper"},this.graphTitle?e("h1",null,this.graphTitle):null,e("fireenjin-graph",{type:"doughnut",datasets:this.datasets,labels:this.labels}),this.users.map((t=>{var a;return e("ion-item",null,e("fireenjin-avatar",{src:((a=t===null||t===void 0?void 0:t.user)===null||a===void 0?void 0:a.user_avatar)?t.user.user_avatar:"./img/avatar.png",slot:"start"}),e("h4",null,t.user.user_name),t.payables&&t.payables.length>0?t.payables.map((a=>[e("p",null,a.type==="percent"?a.percent*100+"%":"Flat"," ","- ",t.user.group.group_name),a.payment?e("p",null,this.getPaymentText(a.payment)):null])):e("floodteam-error",{message:"No payment is tied to this payable!"}),e("ion-badge",{slot:"end"},this.formatUSD(t.amount)))})))}get graphPaySplitsEl(){return s(this)}static get watchers(){return{users:["onUsersUpdate"]}}};r.style=o;export{r as fireenjin_graph_pay_splits};
//# sourceMappingURL=p-523bcf9e.entry.js.map