import{r as t,h as e,H as s}from"./p-cb5076d4.js";import{g as i}from"./p-d50d0ec8.js";import{I as n}from"./p-b3906d17.js";import{L as a}from"./p-5eec4552.js";import{C as r}from"./p-a90b9242.js";import{g as o}from"./p-56d4255d.js";import{g as d,a as l}from"./p-2ebea1db.js";import"./p-b3edc8b2.js";import"./p-814af281.js";import"./p-acad969c.js";const c=class{constructor(e){t(this,e),this.list=a.init(),this.actionStatus=n.init(),this.showHeader=!0,this.acceptRequest=t=>this.performAction("accept",t),this.rejectRequest=t=>this.performAction("reject",t)}fetchList(t=!1){const{list:e,table:s}=this;e.isPending||e.error&&!t||(this.list=e.beforeFetch(),this.apiAtama.getReceivedRequests(s.base,s.name).then((t=>{this.list=e.afterFetch(t,!1)}),(t=>{this.list=e.afterFetchError(t)})))}performAction(t,e){const{actionStatus:s,table:i}=this;if(s.isPending)return;this.actionStatus=s.beforeFetch();const n=t=>{this.actionStatus=s.afterFetch(t),this.onActionDone(),this.fetchList()},a=t=>{this.actionStatus=s.afterFetchError(t)};"accept"===t?this.apiAtama.acceptPairRequest(i.base,i.name,e._id).then(n,a):this.apiAtama.rejectPairRequest(i.base,i.name,e._id).then(n,a)}componentWillLoad(){this.fetchList()}render(){var t;const{i18n:n,actionStatus:a,list:c,showHeader:m}=this,h=c.isPending&&c.data;return e(s,null,(m||h)&&e("div",{class:"ml-2 mb-2 d-flex align-items-center"},m&&e("small",null,e("b",null,(null===(t=n.receivedRequests)||void 0===t?void 0:t.toLocaleUpperCase())||"RECEIVED REQUESTS")," "),h&&e("dvn-progress",{indefinite:!0,size:14,strokeWidth:2,tint:"primary"})),c.isPending&&!c.data&&e("div",{class:"d-flex justify-content-center"},e("dvn-progress",{indefinite:!0})),0===(c.data&&c.data.length)&&e("dvn-card",{elevation:0,leaned:!0,tint:"neutral"},n.noReceivedRequests||"There are no pending requests."),c.data&&c.data.map((t=>e("dvn-card",{key:t._id,elevation:0,leaned:!0,bodyLeaned:!0,style:{margin:"0 0 1rem 0"}},e("div",{class:"d-flex justify-content-between align-items-center pr-2"},e("div",{style:{cursor:"pointer"}},e("dvn-info-summary",{title:o(i(t,"sentBy")),subTitle:t.requestedAt?r.format(new Date(1e3*t.requestedAt),n.sentOnDateFormat||"DD MMM YYYY, HH:mm"):void 0,onClick:()=>this.onViewRequestSender(i(t,"sentBy"))},e("dvn-image",{slot:"media",src:i(t,"sentBy").imageUrl,shape:"circle"}))),"requested"!==t.status&&e("dvn-button",{leaned:!0,scale:"small",shape:"rounded",tagMode:!0,tint:d(t),view:"ghost"},l(n.statusLabels,t))),"requested"===t.status&&e("dvn-card-footer",{slot:"footer",alignRight:!0},e("dvn-button",{disabled:a.isPending,leaned:!0,scale:"small",tint:"secondary",onClick:()=>this.acceptRequest(t)},n.accept||"Accept"),e("dvn-button",{disabled:a.isPending,scale:"small",tint:"danger",onClick:()=>this.rejectRequest(t)},n.reject||"Reject"))))))}};export{c as atama_received_request_list}