import{r as e,c as i,h as t,H as s,g as n}from"./p-ec7718e6.js";import"./p-2d511d0e.js";import{D as r}from"./p-3c3b4f3f.js";import"./p-d66fb38c.js";import"./p-e249790d.js";import"./p-552063c3.js";import"./p-9c626387.js";import"./p-ae623d5d.js";import{L as o}from"./p-6f02ee7c.js";import{P as a,c as d,b as l}from"./p-f650e043.js";import{R as c,a as p}from"./p-a48e8a8e.js";const h=class{constructor(t){e(this,t),this.action=i(this,"action",7),this.list=o.init(),this.shownTab="pairs",this.onSizeChange=e=>{this.size=e}}componentWillLoad(){this.fetchMembershipConfigOfMemberToShow()}componentDidLoad(){this.uiHelper=new c(this.el,this.onSizeChange)}fetchMembershipConfigOfMemberToShow(){var e;const{notifier:i,view:{table:t,ui:{i18n:s}}}=this,{memberToViewRefFieldId:n}=this.params,r=null===(e=t.fields.find((e=>"reference"===e.type&&e.id===n)))||void 0===e?void 0:e.otherCollection;this.apiUye.getMembershipConfigWithName(r).then((e=>{this.membershipConfigToShow=e,this.fetchList()}),(e=>i.alert(s.fetchConfigurationError||"Getting configuration failed.",e.status)))}fetchList(){const{list:e}=this;if(e.isPending)return;const{membership:i,notifier:t,view:{table:s,ui:{i18n:n}}}=this,{userRefFieldId:r}=this.params;this.list=e.beforeFetch(),this.apiAtama.getPairsOfUser(s.base,s.name,r,i._id).then((i=>this.list=e.afterFetch(i,!1)),(i=>{this.list=e.afterFetchError(i),t.alert(n.fetchListError||"Fetching list failed.",i.status)}))}onRequestAcceptOrReject(){this.fetchList()}onClickReceivedRequestUser(e){this.action.emit({type:"navigation",direction:"forward",resetHistory:!0,viewId:this.params.viewIdToViewRequestSender,params:{item:e}})}render(){var e;const{list:i,membershipConfigToShow:n,shownTab:o,size:c,view:h}=this,{ui:{i18n:v}}=h,m=c<p.Medium;if(!n)return t("div",{class:"d-flex justify-content-center pt-3"},t("dvn-progress",{indefinite:!0}));const{memberToViewRefFieldId:f,userRefFieldId:u}=this.params,w=(i.data||[]).map((e=>{const i=r.decode(e[f][0]);return i.pairId=e._id,i})),b=!!i.data,g=a.decode(h.table),j=l(g,u),R=d(g,u),y=b&&(null==j?void 0:j.isActive())&&(0===j.pairLimit||j.pairLimit>w.length),q="pairs"===o||!m,I=!!R,_=!(!I||"pair-requests"!==o&&m),x=!m;return t(s,{class:"d-block"},m&&I&&t("div",{class:"d-flex justify-content-center pt-3"},t("dvn-content-switcher",{options:[{label:v.pairs||"Pairs",value:"pairs"},{label:v.receivedRequests||"Received Requests",value:"pair-requests"}],onChange:e=>this.shownTab=e.detail,value:this.shownTab})),y&&t("div",{class:"pt-3"},t("dvn-card",{elevation:0,leaned:!0,tint:v.selectionCardTint||"primary"},t("dvn-card-header",{slot:"header",tint:v.selectionCardTint||"primary",title:v.selectionCardTitle||"Selection is on!"}),v.selectionCardMessage||"You can view all available users and send them requests.",t("dvn-card-footer",{slot:"footer",alignRight:!0},t("dvn-button",{tint:v.selectionCardActionTint||"secondary",onClick:()=>this.action.emit({type:"navigation",direction:"forward",resetHistory:!0,viewId:this.params.viewIdToNavigateToSelectPair})},v.selectionCardActionLabel||"Go to selection page")))),t("div",{class:"row"},q&&t("div",{class:{"col-md-12 pt-3":!0,"col-lg-8":_}},_&&t("div",{class:"ml-2 mb-2 d-flex align-items-center"},x&&t("small",null,t("b",null,(null===(e=v.pairs)||void 0===e?void 0:e.toLocaleUpperCase())||"PAIRS")," "),i.isPending&&i.data&&t("dvn-progress",{indefinite:!0,size:14,strokeWidth:2,tint:"primary"})),i.isPending&&!i.data&&t("div",{class:"d-flex justify-content-center"},t("dvn-progress",{indefinite:!0})),i.data&&t("div",null,w.length>0?t("dvn-card-list-view",{config:h.ui,fields:n.fields,items:w}):t("dvn-card",{elevation:0,leaned:!0,tint:"warning"},v.noPairsMessage||"You don't have any pairs."))),_&&t("div",{class:{"col-sm-12 col-md-4 pt-3":!m,"col-sm-12 col-md-12 pt-3":m}},t("atama-received-request-list",{i18n:v,apiAtama:this.apiAtama,onActionDone:()=>this.onRequestAcceptOrReject(),onViewRequestSender:e=>this.onClickReceivedRequestUser(e),showHeader:x,table:this.view.table}))))}get el(){return n(this)}};export{h as dvn_app_view_atama_member_pairs_overview_view}