import{r as e,c as i,h as t,H as s,g as r}from"./p-1ea36ff3.js";import{R as n,a as o}from"./p-b2c002e9.js";import{D as a}from"./p-d50d0ec8.js";import{L as d}from"./p-5eec4552.js";import{P as l,c,b as p}from"./p-bc737eae.js";import"./p-48f43f2a.js";import"./p-28c66a78.js";import"./p-6eb29778.js";import"./p-eebad85b.js";import"./p-681f800a.js";import"./p-3b35e507.js";import"./p-240d1ae7.js";import"./p-35267d98.js";let h=class{constructor(t){e(this,t),this.action=i(this,"action",7),this.list=d.init(),this.shownTab="pairs",this.onSizeChange=e=>{this.size=e}}componentWillLoad(){this.fetchMembershipConfigOfMemberToShow()}componentDidLoad(){this.uiHelper=new n(this.el,this.onSizeChange)}fetchMembershipConfigOfMemberToShow(){var e;const{notifier:i,view:{table:t,ui:{i18n:s}}}=this,{memberToViewRefFieldId:r}=this.params,n=null===(e=t.fields.find((e=>"reference"===e.type&&e.id===r)))||void 0===e?void 0:e.otherCollection;this.apiUye.getMembershipConfigWithName(n).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:r}}}=this,{userRefFieldId:n}=this.params;this.list=e.beforeFetch(),this.apiAtama.getPairsOfUser(s.base,s.name,n,i._id).then((i=>this.list=e.afterFetch(i,!1)),(i=>{this.list=e.afterFetchError(i),t.alert(r.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:r,shownTab:n,size:d,view:h}=this,{ui:{i18n:m}}=h,v=d<o.Medium;if(!r)return t("div",{class:"d-flex justify-content-center pt-3"},t("dvn-progress",{indefinite:!0}));const{memberToViewRefFieldId:f,userRefFieldId:u}=this.params,b=(i.data||[]).map((e=>{const i=a.decode(e[f][0]);return i.pairId=e._id,i})),w=!!i.data,g=l.decode(h.table),j=p(g,u),R=c(g,u),y=w&&(null==j?void 0:j.isActive())&&(0===j.pairLimit||j.pairLimit>b.length),q="pairs"===n||!v,I=!!R,_=!(!I||"pair-requests"!==n&&v),x=!v;return t(s,{class:"d-block"},v&&I&&t("div",{class:"d-flex justify-content-center pt-3"},t("dvn-content-switcher",{options:[{label:m.pairs||"Pairs",value:"pairs"},{label:m.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:m.selectionCardTint||"primary"},t("dvn-card-header",{slot:"header",tint:m.selectionCardTint||"primary",title:m.selectionCardTitle||"Selection is on!"}),m.selectionCardMessage||"You can view all available users and send them requests.",t("dvn-card-footer",{slot:"footer",alignRight:!0},t("dvn-button",{tint:m.selectionCardActionTint||"secondary",onClick:()=>this.action.emit({type:"navigation",direction:"forward",resetHistory:!0,viewId:this.params.viewIdToNavigateToSelectPair})},m.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=m.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,b.length>0?t("dvn-card-list-view",{config:h.ui,fields:r.fields,items:b}):t("dvn-card",{elevation:0,leaned:!0,tint:"warning"},m.noPairsMessage||"You don't have any pairs."))),_&&t("div",{class:{"col-sm-12 col-md-4 pt-3":!v,"col-sm-12 col-md-12 pt-3":v}},t("atama-received-request-list",{i18n:m,apiAtama:this.apiAtama,onActionDone:()=>this.onRequestAcceptOrReject(),onViewRequestSender:e=>this.onClickReceivedRequestUser(e),showHeader:x,table:this.view.table}))))}get el(){return r(this)}};export{h as dvn_app_view_atama_member_pairs_overview_view}