import{r as registerInstance,h,H as Host}from"./index-ecdfb761.js";import{g as getDataModelField}from"./data-model-88af49fc.js";import{I as ItemFetchState}from"./item-fetch-state-a8a04fb7.js";import{L as ListFetchState}from"./list-fetch-state-e772aa74.js";import{C as CalendarUtils}from"./calendar-470c802a.js";import{g as getTintForStatus,a as getLabelForStatus}from"./pair-request-ee2b9bbc.js";import"./index-a3ca021c.js";import"./_commonjsHelpers-27f122dd.js";import"./moment-65eca6b3.js";var AtamaReceivedRequestList=function(){function t(t){var e=this;registerInstance(this,t);this.list=ListFetchState.init();this.actionStatus=ItemFetchState.init();this.showHeader=true;this.acceptRequest=function(t){return e.performAction("accept",t)};this.rejectRequest=function(t){return e.performAction("reject",t)}}t.prototype.fetchList=function(t){var e=this;if(t===void 0){t=false}var a=this,i=a.list,n=a.table;if(i.isPending||i.error&&!t){return}this.list=i.beforeFetch();this.apiAtama.getReceivedRequests(n.base,n.name).then((function(t){e.list=i.afterFetch(t,false)}),(function(t){e.list=i.afterFetchError(t)}))};t.prototype.performAction=function(t,e){var a=this;var i=this,n=i.actionStatus,s=i.table;if(n.isPending){return}this.actionStatus=n.beforeFetch();var r=function(t){a.actionStatus=n.afterFetch(t);a.onActionDone();a.fetchList()};var o=function(t){a.actionStatus=n.afterFetchError(t)};if(t==="accept"){this.apiAtama.acceptPairRequest(s.base,s.name,e._id).then(r,o)}else{this.apiAtama.rejectPairRequest(s.base,s.name,e._id).then(r,o)}};t.prototype.componentWillLoad=function(){this.fetchList()};t.prototype.render=function(){var t=this;var e;var a=this,i=a.i18n,n=a.actionStatus,s=a.list,r=a.showHeader;var o=s.isPending&&s.data;return h(Host,null,(r||o)&&h("div",{class:"ml-2 mb-2 d-flex align-items-center"},r&&h("small",null,h("b",null,((e=i.receivedRequests)===null||e===void 0?void 0:e.toLocaleUpperCase())||"RECEIVED REQUESTS")," "),o&&h("dvn-progress",{indefinite:true,size:14,strokeWidth:2,tint:"primary"})),s.isPending&&!s.data&&h("div",{class:"d-flex justify-content-center"},h("dvn-progress",{indefinite:true})),(s.data&&s.data.length)===0&&h("dvn-card",{elevation:0,leaned:true,tint:"neutral"},i.noReceivedRequests||"There are no pending requests."),s.data&&s.data.map((function(e){return h("dvn-card",{key:e._id,elevation:0,leaned:true,bodyLeaned:true,style:{margin:"0 0 1rem 0"}},h("div",{class:"d-flex justify-content-between align-items-center pr-2"},h("div",{style:{cursor:"pointer"}},h("dvn-info-summary",{title:getDataModelField(e,"sentBy").name,subTitle:e.requestedAt?CalendarUtils.format(new Date(e.requestedAt*1e3),i.sentOnDateFormat||"DD MMM YYYY, HH:mm"):undefined,onClick:function(){return t.onViewRequestSender(getDataModelField(e,"sentBy"))}},h("dvn-image",{slot:"media",shape:"circle",src:getDataModelField(e,"sentBy").imageUrl,text:getDataModelField(e,"sentBy").initials}))),e.status!=="requested"&&h("dvn-button",{leaned:true,scale:"small",shape:"rounded",tagMode:true,tint:getTintForStatus(e),view:"ghost"},getLabelForStatus(i.statusLabels,e))),e.status==="requested"&&h("dvn-card-footer",{slot:"footer",alignRight:true},h("dvn-button",{disabled:n.isPending,leaned:true,scale:"small",tint:"secondary",onClick:function(){return t.acceptRequest(e)}},i.accept||"Accept"),h("dvn-button",{disabled:n.isPending,scale:"small",tint:"danger",onClick:function(){return t.rejectRequest(e)}},i.reject||"Reject")))})))};return t}();export{AtamaReceivedRequestList as atama_received_request_list};