/* COPYRIGHT Esri - https://js.arcgis.com/1.2/LICENSE.txt */
import g from"./OKOYUP5P.js";import f from"./7BOA27L2.js";import"./5XHAT3I6.js";import"./GUMFHB46.js";import"./DC5KIXAN.js";import"./GPOPJGGG.js";import e from"./EZAL5KYF.js";import d from"./HBC3TKGZ.js";import"./W4YXXJAS.js";import"./S7VQX4XX.js";import"./4Q4PZB7R.js";import c from"./T2ZUVHM7.js";import a from"./HUJP6DFF.js";import{a as v}from"./XN2LWKJE.js";import"./4BPRM7CL.js";import"./NIL6NWG5.js";import"./ED6SUP22.js";import"./E6P6PYNW.js";import"./IKKBLHLZ.js";import"./CUA2IUXX.js";import"./4UZDZNJD.js";import"./KOTG6W5Z.js";import"./6SC7YR5Y.js";import"./Z6NOHRUL.js";import"./GVM4XYEI.js";import"./NGDVSE4Z.js";import"./BTNJZZQQ.js";import"./ZYQ4P2ON.js";import"./5MKH4QDV.js";import"./3GWWHA4S.js";import"./3YYHZQJB.js";import"./JEJ23R3P.js";import"./TONS7KZJ.js";import"./Q62UEPOL.js";import"./44A5XEM4.js";import{b as T}from"./ODCCVHGI.js";import{G as y,H as _,h as u,i as b}from"./42WFQ3AX.js";import"./3QPJ2JCA.js";export default $arcgis.t(([])=>{var C=u`/** @license
 * Copyright 2025 Esri
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

.height-51 {
  height: 51px;
}

.width-51 {
  width: 51px;
}`,f=class extends _{constructor(){super(),this._translations=v({name:"field-selection",blocking:!0}),this._fieldSortOrder="default",this._selectedFields=[],this._fieldVisibilityPopoverClickHandler=e=>{this._fieldVisibilityPopoverNode?this._isInNode(e.target,"arcgis-field-pick-list")||(document.body.removeChild(this._fieldVisibilityPopoverNode),this._fieldVisibilityPopoverNode=void 0,document.removeEventListener("click",this._fieldVisibilityPopoverClickHandler)):document.removeEventListener("click",this._fieldVisibilityPopoverClickHandler)},this.listenOn(window,"columnReorder",this.handleColumnReorder,{capture:!0})}static{this.properties={configExtraFields:1,layer:[0,{},{attribute:!1}],mapView:[0,{},{attribute:!1}],table:[0,{},{attribute:!1}],tableRef:[0,{},{attribute:!1}],_translations:[16,{},{state:!0}]}}static{this.styles=C}render(){return b`<calcite-action alignment=center appearance=solid class="height-51 width-51" id=solutions-field-selection .text=${this._translations.fieldVisibility} scale=m @click=${()=>this._handleFieldVisibilityClick()} @mouseover=${()=>this._addTableTooltip(this._fieldVisibilityActionNode,this._translations.fieldVisibility)} @mouseout=${()=>this._removeTableTooltip()} @focus=${()=>this._addTableTooltip(this._fieldVisibilityActionNode,this._translations.fieldVisibility)} ${y(e=>this._fieldVisibilityActionNode=e)}><calcite-icon scale=s icon=gear></calcite-icon></calcite-action>`}handleColumnReorder(){this._fieldSortOrder="default",this._fieldVisibilityPopoverNode&&(this.removeFieldsPickList(),this._handleFieldVisibilityClick())}_handleFieldVisibilityClick(){if(this._fieldVisibilityPopoverNode)return;let e=this.table?.tableTemplate?.columnTemplates;if(this.layer&&this.mapView&&e&&this._fieldVisibilityActionNode){document.removeEventListener("click",this._fieldVisibilityPopoverClickHandler);let t=this.table.fieldColumns.map(l=>({alias:l.field.alias,description:l.field.description,name:l.field.name,type:l.field.type}));if(this._hasAttachmentsEnabled(this.layer)){let l="Attachments";if(this._shouldShowField(l.toUpperCase(),!1)){if(!e.some(a=>a.fieldName.toUpperCase()===l.toUpperCase())){let a={fieldName:l,type:"attachment",visible:!0};e.push(a)}t.push({name:l,alias:"Photos and files",type:"none",description:l})}}if(this.table.relatedRecordsEnabled&&this.layer.relationships&&this.layer.relationships.length>0){let l=this.layer.parent;this.layer.relationships.forEach(a=>{let o,r=this._shouldShowField(a.name||"",!0);if(!e.some(n=>n.fieldName.toLowerCase()===a.name?.toLowerCase()?(o=a.name,!0):!1))if(a.name){o=a.name;let n={fieldName:o,type:"relationship",visible:!0};r=this._shouldShowField(o,!0),e.push(n)}else{let n=[...l?.layers||[],...l?.tables],d;if(n.some(c=>c.layerId===a.relatedTableId?(d=c,!0):!1),d){o=d.title,a.name=o;let c={fieldName:o,type:"relationship",visible:!0};r=this._shouldShowField(o,!0),e.push(c)}}o&&r&&t.push({name:o,alias:`Related ${o}`,type:"none",description:`related:${o}`})})}let i=this._fieldVisibilityPopoverNode?this._fieldVisibilityPopoverNode:document.createElement("arcgis-field-pick-list");i.layer=this.layer,i.fields=t,i.showFieldInfo=!0,i.showFieldName=!0,i.showDescription=!1,i.showSelectionAll=!0,i.hideCancel=!0,i.hideSort=!1,i.showFilterLength=5,i.multiple=!0,i.heading=this._translations.fieldVisibility,i.okBtnText=this._translations.doneWithFieldChanges,i.filterPlaceholderText=this._translations.filterFields,i.sortBy=this._fieldSortOrder??"default";let p=this.table?.visibleColumns.map(l=>l.fieldName.startsWith("EsriFeatureTableRelationshipColumn")||l.fieldName.startsWith("EsriFeatureTableAttachmentsColumn")?l.effectiveLabel:l.fieldName);i.selectedFields=e.reduce((l,a)=>((p?p.indexOf(a.fieldName)>-1:a.visible)&&l.push(a.fieldName),l),[]),this._selectedFields=i.selectedFields,i.style.minHeight="340px",i.popoverProps={refElement:this._fieldVisibilityActionNode,popoverWidth:300,placement:"bottom-end",offsetDistance:-20,triggerDisabled:!1,autoClose:!1},i.addEventListener("arcgisChange",l=>{l.stopPropagation();let a=l.detail.selectedFields,o=this._getDifference(a,this._selectedFields),r=this._getDifference(this._selectedFields,a);o.concat(r).forEach(d=>{let c=this.layer?.relationships?.map(m=>m.name)||[];if(d==="Attachments"){let m=this.table.columns.find(h=>"onShowAttachments"in h);m.hidden=r.indexOf(d)>-1}else c.indexOf(d)>-1?this.table.columns.filter(h=>"relationshipId"in h).forEach(h=>{r.indexOf(d)>-1,d==h.effectiveLabel&&(h.hidden=r.indexOf(d)>-1)}):this.table.toggleColumnVisibility(d)}),this._selectedFields=a,this._updateTable(this.table.tableTemplate)}),i.addEventListener("arcgisSortByChange",l=>{l.stopPropagation(),this._fieldSortOrder=l.detail,this._sortFields(l.detail)}),i.addEventListener("arcgisClose",()=>{this._closePopovers(),setTimeout(()=>this._fieldVisibilityActionNode.setFocus(),200)}),document.body.appendChild(i),this._fieldVisibilityPopoverNode=i,setTimeout(()=>document.addEventListener("click",this._fieldVisibilityPopoverClickHandler),200)}}_shouldShowField(e,t){return(this.configExtraFields||[]).some(s=>t?s.replace("related:","").toUpperCase()===e.toUpperCase():s.toUpperCase()===e.toUpperCase())}removeFieldsPickList(){this._fieldVisibilityPopoverNode&&(document.body.removeChild(this._fieldVisibilityPopoverNode),this._fieldVisibilityPopoverNode=void 0)}_sortFields(e){let t=this.table.tableTemplate.columnTemplates,s=this._getSortOrder(e),p=t.filter(a=>a.type!=="attachment"&&a.type!=="relationship").sort((a,o)=>{let r=s.indexOf(a.fieldName),n=s.indexOf(o.fieldName);return r===-1&&n!==-1?1:r!==-1&&n===-1?-1:r===-1&&n===-1?0:r-n}),l=t.filter(a=>a.type==="attachment"||a.type==="relationship");this.tableRef.setColumnOrder([...p,...l]),this._updateTable(this.table.tableTemplate)}_getSortOrder(e){let t=[...this.layer.fields];return e==="display"?t.sort((s,i)=>s.alias.localeCompare(i.alias)):e==="field"?t.sort((s,i)=>s.name.localeCompare(i.name)):e==="type"&&t.sort((s,i)=>s.type.localeCompare(i.type)),t.map(s=>s.name)}_getDifference(e,t){return e.filter(s=>!t.includes(s))}_updateTable(e){this.table.tableTemplate=e,this._isStandardView()&&this._syncAttributeTableTemplate()}async _syncAttributeTableTemplate(){let e=this.table.layer;if(e.attributeTableTemplate){let{_modules:t}=this,s=e.attributeTableTemplate.clone();t?.attributeTableTemplateUtils.syncAttributeTableTemplate(this.table,s),JSON.stringify(s)!==JSON.stringify(e.attributeTableTemplate)&&(e.attributeTableTemplate=s)}if(e.attributeTableTemplate?.orderByFields?.length>1){let t=e.attributeTableTemplate.clone(),s=this.table.activeSortOrders[0];t.orderByFields=[{field:s.fieldName,order:s.direction}],e.attributeTableTemplate=t,this._syncColumnDirectionsWithOrderByFields()}}_syncColumnDirectionsWithOrderByFields(){let e=this.table.activeSortOrders[0]?.fieldName;this.table.columns.forEach(t=>{"fieldName"in t&&t.fieldName!==e&&(t.direction=void 0)}),this.table.tableTemplate?.columnTemplates.forEach(t=>{"fieldName"in t&&t.fieldName!==e&&(t.direction=void 0)})}_isStandardView(){return!this.table.relatedTable&&!this.table.attachmentsViewOptions.objectId}_closePopovers(){document.removeEventListener("click",this._fieldVisibilityPopoverClickHandler),this._fieldVisibilityPopoverNode&&(document.body.removeChild(this._fieldVisibilityPopoverNode),this._fieldVisibilityPopoverNode=void 0)}_addTableTooltip(e,t){let s=document.createElement("calcite-tooltip");s.className="table-tooltip",s.referenceElement=e,s.placement="trailing-start",s.open=!0;let i=document.createElement("div");i.className="tooltip",i.innerHTML=t,s.append(i),document.body.append(s)}_removeTableTooltip(){document.querySelectorAll(".table-tooltip").forEach(e=>e.parentNode?.removeChild(e))}_isInNode(e,t){for(;e;){if(e.nodeName===t.toUpperCase())return!0;e=e.parentElement}return!1}_hasAttachmentsEnabled(e){if(!e?.capabilities)return!1;let{capabilities:{data:{supportsAttachment:t},operations:{supportsQueryAttachments:s}}}=e;return t&&s}};T("field-selection",f);return f},a,c,d,e,f,g)