import{r as t,B as a,h as e,f as s}from"./p-a89095f5.js";const r=class{constructor(a){t(this,a),this.users=[],this.graphTitle=void 0,this.datasets=[],this.labels=[],this.currentUsers=[]}async setUsers(t){try{this.currentUsers="string"==typeof t?JSON.parse(t):t.length>0?t:this.graphPaySplitsEl.getAttribute("users")?JSON.parse(this.graphPaySplitsEl.getAttribute("users")):[];const a=["#3e95cd","#8e5ea2","#3cba9f","#e8c3b9","#c45850"],e=[];return this.users.map((t=>{this.labels.push(t.user.user_name),e.push(t.amount)})),this.datasets=[{backgroundColor:a,data:e}],this.currentUsers}catch(t){return console.log(t),[]}}onUsersUpdate(){this.setUsers(this.users)}formatUSD(t){return new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}).format(t)}getPaymentText(t){let a="";return"manual"===t.type?a=`${this.formatUSD(t.amount)} paid manually`:"charge"===t.type?a=`${this.formatUSD(t.amount)} paid on ${t.brand} card ending in ${t.ending_in}`:"check"===t.type&&(a=`${this.formatUSD(t.amount)} paid by check ${t.check_number}`),a}componentDidLoad(){(null==a?void 0:a.isBrowser)&&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:(null===(a=null==t?void 0:t.user)||void 0===a?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,"percent"===a.type?100*a.percent+"%":"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="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}";export{r as fireenjin_graph_pay_splits}