/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{__decorate as t}from"tslib";import{property as e,subclass as o}from"../../core/accessorSupport/decorators.js";import{substitute as i}from"../../intl/substitute.js";import l from"./Grid/Column.js";import{css as r}from"./Grid/ColumnCSS.js";import{isIFeatureTableSupportedLayerWithRelationships as s,findRelationship as n}from"./support/tableUtils.js";const a={showRecordsButton:"esri-column__show-related-records-button"};let p=class extends l{constructor(t){super(t),this.flexGrow=1,this.icon="relationship-class",this.layer=null,this.relatedLayer=null,this.relationshipId=null,this.renderFunction=({root:t,rowData:e})=>{if(!e)return;const o=e.item,{layer:l,relatedLayer:n}=this;if(!o?.feature||!s(l)||!s(n))return;const{messages:p}=this,{index:d}=e,{feature:h,objectId:c}=o,{collapsed:u,showRelatedTableCallback:b,relationshipId:y}=this,f=o.relatedRecords,m=f?.find(t=>t.relationshipId===y)?.count??0,C=!u&&b&&p?.recordsCount?i(p.recordsCount,{count:m}):`${m}`,v=t=>{t.preventDefault(),u||this.showRelatedTableCallback?.({feature:h,index:d,layer:l,objectId:c,relatedLayer:n,relationshipId:y})},w=u?void 0:"chevron-right";if(t.firstChild){const e=t.firstChild;return e.textContent=C,e.onclick=v,void(w&&(e.iconEnd=w))}const x=this.createCalciteButton({className:`${a.showRecordsButton} ${r.contentFull}`,iconEnd:w,iconFlipRtl:"both",scale:"m",textContent:C,title:C,onclick:v});this.removeCellContent(t),t.appendChild(x)},this.resizable=!0,this.showRelatedTableCallback=null,this.textAlign="center",this.width="200px"}get _relationshipLabel(){return this.label||this.originRelationship?.name||this.layer.title||""}get collapsed(){return this._get("collapsed")||!1}set collapsed(t){t?this.set({flexGrow:0,resizable:!1,width:"80px"}):this.set({flexGrow:1,resizable:!0,width:"200px"}),this._set("collapsed",t)}get effectiveLabel(){return this.collapsed?"":this._relationshipLabel}get iconNode(){const{icon:t}=this;return t?this.createCalciteIcon({icon:t,textLabel:this._relationshipLabel}):null}get originRelationship(){const t=this.relationshipId;return this.relatedLayer.relationships?.find(({id:e})=>e===t)}get relationship(){return n(this.layer,this.relationshipId)}};t([e()],p.prototype,"_relationshipLabel",null),t([e()],p.prototype,"collapsed",null),t([e()],p.prototype,"effectiveLabel",null),t([e()],p.prototype,"flexGrow",void 0),t([e()],p.prototype,"icon",void 0),t([e()],p.prototype,"iconNode",null),t([e()],p.prototype,"layer",void 0),t([e()],p.prototype,"originRelationship",null),t([e()],p.prototype,"relatedLayer",void 0),t([e()],p.prototype,"relationship",null),t([e()],p.prototype,"relationshipId",void 0),t([e()],p.prototype,"renderFunction",void 0),t([e()],p.prototype,"resizable",void 0),t([e()],p.prototype,"showRelatedTableCallback",void 0),t([e()],p.prototype,"textAlign",void 0),t([e()],p.prototype,"width",void 0),p=t([o("esri.widgets.FeatureTable.RelationshipColumn")],p);const d=p;export{d as default};
