import{r as registerInstance,h,H as Host}from"./index-102043e0.js";import{g as getDataModelField}from"./data-model-f5160369.js";import{I as ItemFetchState}from"./item-fetch-state-7bde809d.js";import{L as ListFetchState}from"./list-fetch-state-623a5ba4.js";import{C as CalendarUtils}from"./calendar-622f8c95.js";import{g as getUserFullName}from"./User-d2ee8b71.js";import{g as getTintForStatus,a as getLabelForStatus}from"./pair-request-ee2b9bbc.js";import"./index-3958847a.js";import"./_commonjsHelpers-27f122dd.js";import"./moment-6f6ab70c.js";var AtamaReceivedRequestList=function(){function e(e){var t=this;registerInstance(this,e);this.list=ListFetchState.init();this.actionStatus=ItemFetchState.init();this.showHeader=true;this.acceptRequest=function(e){return t.performAction("accept",e)};this.rejectRequest=function(e){return t.performAction("reject",e)}}e.prototype.fetchList=function(e){var t=this;if(e===void 0){e=false}var a=this,i=a.list,s=a.table;if(i.isPending||i.error&&!e){return}this.list=i.beforeFetch();this.apiAtama.getReceivedRequests(s.base,s.name).then((function(e){t.list=i.afterFetch(e,false)}),(function(e){t.list=i.afterFetchError(e)}))};e.prototype.performAction=function(e,t){var a=this;var i=this,s=i.actionStatus,n=i.table;if(s.isPending){return}this.actionStatus=s.beforeFetch();var r=function(e){a.actionStatus=s.afterFetch(e);a.onActionDone();a.fetchList()};var o=function(e){a.actionStatus=s.afterFetchError(e)};if(e==="accept"){this.apiAtama.acceptPairRequest(n.base,n.name,t._id).then(r,o)}else{this.apiAtama.rejectPairRequest(n.base,n.name,t._id).then(r,o)}};e.prototype.componentWillLoad=function(){this.fetchList()};e.prototype.render=function(){var e=this;var t;var a=this,i=a.i18n,s=a.actionStatus,n=a.list,r=a.showHeader;var o=n.isPending&&n.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,((t=i.receivedRequests)===null||t===void 0?void 0:t.toLocaleUpperCase())||"RECEIVED REQUESTS")," "),o&&h("dvn-progress",{indefinite:true,size:14,strokeWidth:2,tint:"primary"})),n.isPending&&!n.data&&h("div",{class:"d-flex justify-content-center"},h("dvn-progress",{indefinite:true})),(n.data&&n.data.length)===0&&h("dvn-card",{elevation:0,leaned:true,tint:"neutral"},i.noReceivedRequests||"There are no pending requests."),n.data&&n.data.map((function(t){return h("dvn-card",{key:t._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:getUserFullName(getDataModelField(t,"sentBy")),subTitle:t.requestedAt?CalendarUtils.format(new Date(t.requestedAt*1e3),i.sentOnDateFormat||"DD MMM YYYY, HH:mm"):undefined,onClick:function(){return e.onViewRequestSender(getDataModelField(t,"sentBy"))}},h("dvn-image",{slot:"media",src:getDataModelField(t,"sentBy").imageUrl,shape:"circle"}))),t.status!=="requested"&&h("dvn-button",{leaned:true,scale:"small",shape:"rounded",tagMode:true,tint:getTintForStatus(t),view:"ghost"},getLabelForStatus(i.statusLabels,t))),t.status==="requested"&&h("dvn-card-footer",{slot:"footer",alignRight:true},h("dvn-button",{disabled:s.isPending,leaned:true,scale:"small",tint:"secondary",onClick:function(){return e.acceptRequest(t)}},i.accept||"Accept"),h("dvn-button",{disabled:s.isPending,scale:"small",tint:"danger",onClick:function(){return e.rejectRequest(t)}},i.reject||"Reject")))})))};return e}();export{AtamaReceivedRequestList as atama_received_request_list};