/* COPYRIGHT Esri - https://js.arcgis.com/1.2/LICENSE.txt */
import b from"./N6IQW2WT.js";import a from"./C2LXNVZ5.js";import{b as f}from"./ABSRNM72.js";import{F as c,G as p,H as g,h as m,i as o,r as h,u as _}from"./5CQPQ7AE.js";import"./3QPJ2JCA.js";export default $arcgis.t(([C,F,,{f:b}])=>{var I=m`@layer{
/**
 * @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.
 */

:host {
  display: block;
}

.buttons-container {
  align-items: center;
  display: flex;
  padding: 4px;
  color: var(--calcite-color-text-1) !important;
  background-color: var(--calcite-color-foreground-1) !important;
  border-block-start: 1px solid var(--calcite-color-border-3);
  border-block-end: 1px solid var(--calcite-color-border-3);
}
}`,u=class extends g{constructor(){super(...arguments),this.enableSnapping=!1,this.graphics=[],this.showUserImageInCommentsList=!1,this.showFullCommentTitle=!0,this._likeFieldAvailable=!1,this._likeCount=0,this._disLikeCount=0,this._dislikeFieldAvailable=!1,this._commentsAvailable=!1,this._isLikeBtnClicked=!1,this._isDislikeBtnClicked=!1,this._relatedFeaturesOIDs=[],this._updating=!1,this._infoCard=c(),this._commentsList=c(),this._likeField="",this._dislikeField="",this._validFieldTypes=["small-integer","integer","big-integer","single","long"],this.relatedTableId="",this.loadingStatus=h(),this.commentClick=h(),this.commentSelect=h(),this.addComment=h(),this.likeOrDislikeClicked=h(),this.featureSelectionChange=h()}static{this.properties={enableSnapping:[5,{},{type:Boolean}],mapView:[0,{},{attribute:!1}],graphics:[0,{},{attribute:!1}],reportingOptions:[0,{},{attribute:!1}],layerItemsHash:[0,{},{attribute:!1}],showUserImageInCommentsList:[5,{},{type:Boolean}],showFullCommentTitle:[5,{},{type:Boolean}],_likeFieldAvailable:[16,{},{state:!0}],_likeCount:[16,{},{state:!0}],_disLikeCount:[16,{},{state:!0}],_dislikeFieldAvailable:[16,{},{state:!0}],_commentsAvailable:[16,{},{state:!0}],_isLikeBtnClicked:[16,{},{state:!0}],_isDislikeBtnClicked:[16,{},{state:!0}],_relatedFeaturesOIDs:[16,{},{state:!0}],_updating:[16,{},{state:!0}]}}static{this.styles=I}static{this.shadowRootOptions=_}willUpdate(e){e.has("graphics")&&this.graphicsWatchHandler()}async graphicsWatchHandler(){await this.getCompleteGraphic(this.graphics[0]),this.checkLikeDislikeFields(),await this.processComments()}async refresh(e){e&&await this.getCompleteGraphic(e),await this.processComments(),e&&this.isLikeDislikeConfigured(e.layer)?this.graphics.length>1&&this.checkLikeDislikeFields():(this._likeFieldAvailable=!1,this._dislikeFieldAvailable=!1)}async back(){this._infoCard.value&&this._infoCard.value.back()}async next(){this._infoCard.value&&this._infoCard.value.next()}async toggleListView(){this._infoCard.value&&this._infoCard.value.toggleListView()}async load(){await this.getCompleteGraphic(this.graphics[0]),this.checkLikeDislikeFields(),await this.processComments()}render(){let e=this._relatedFeaturesOIDs?.length>0?`objectId in(${this._relatedFeaturesOIDs})`:"1=0";return o`<calcite-panel><info-card .enableSnapping=${this.enableSnapping} .graphics=${this.graphics} .mapView=${this.mapView} @selectionChanged=${i=>{this.featureSelectionChange.emit(i.detail)}} position=relative ${p(this._infoCard)}></info-card>${(this._likeFieldAvailable||this._dislikeFieldAvailable||this._commentsAvailable)&&o`<div class="buttons-container">${this._commentsAvailable&&o`<calcite-button appearance=transparent icon-end=speech-bubble kind=neutral @click=${()=>{this.addComment.emit()}} scale=m>${this._relatedFeaturesOIDs.length}</calcite-button>`||""}${this._likeFieldAvailable&&o`<calcite-button appearance=transparent icon-end=thumbs-up .kind=${this._isLikeBtnClicked?"brand":"neutral"} .loading=${this._updating} @click=${this.onLikeButtonClick} scale=m>${this._likeCount??this._selectedGraphic?.attributes[this._likeField]??0}</calcite-button>`||""}${this._dislikeFieldAvailable&&o`<calcite-button appearance=transparent icon-end=thumbs-down .kind=${this._isDislikeBtnClicked?"brand":"neutral"} .loading=${this._updating} @click=${this.onDislikeButtonClick} scale=m>${this._disLikeCount??this._selectedGraphic?.attributes[this._dislikeField]??0}</calcite-button>`||""}</div>`||""}${this.relatedTableId&&this._commentsAvailable&&o`<feature-list class="height-full" .mapView=${this.mapView} @featureClick=${()=>{this.commentClick.emit()}} @featureSelect=${i=>{this.commentSelect.emit(i.detail)}} page-size=5 .selectedLayerId=${this.relatedTableId} .showFullTitle=${this.showFullCommentTitle} .showUserImageInList=${this.showUserImageInCommentsList} text-size=small .whereClause=${e} ${p(this._commentsList)}></feature-list>`||""}</calcite-panel>`}async getCompleteGraphic(e){if(e){let i=e.layer,s=i.createQuery(),t=Number(e.getObjectId());if(!Number.isNaN(t)){s.objectIds=[t];let l=await i.queryFeatures(s);this._selectedGraphic=l.features[0]}}}async processComments(){let e=this._selectedGraphic?.layer;if(this.reportingOptions&&this.reportingOptions[e.id]&&this.reportingOptions[e.id].comment&&e?.relationships&&e.relationships?.length>0){let s=this.mapView&&await b(this.mapView),t=null,l=null;if(e?.relationships?.some(a=>{let r=s?.filter(n=>e.url===n.url&&n.layerId===a.relatedTableId);return r&&r.length>0?(t=r[0],l=a.id,!0):!1}),this.relatedTableId=t?.id??"",this.relatedTableId){let a=this._selectedGraphic?.attributes[e?.objectIdField],r=new F({objectIds:[a],outFields:["*"],relationshipId:l}),n=r&&await e.queryRelatedFeatures(r).catch(d=>{console.error(d)}),k=[];n&&n[a]&&n[a].features.forEach(d=>{k.push(d.attributes[t.objectIdField])}),this._relatedFeaturesOIDs=k,this._commentsAvailable=!0}else this._relatedFeaturesOIDs=[],this._commentsAvailable=!1}else this._relatedFeaturesOIDs=[],this._commentsAvailable=!1,this.relatedTableId=""}isLikeDislikeConfigured(e){let i=!1,s=!1;if(this.reportingOptions&&e&&this.reportingOptions[e.id]){if(!this.reportingOptions[e.id].like&&!this.reportingOptions[e.id].dislike)return!1;let t=this.reportingOptions[e.id].likeField,l=this.reportingOptions[e.id].dislikeField;if(!t&&!l)return!1;e.fields.forEach(a=>{this._validFieldTypes.indexOf(a.type)>-1&&this.layerItemsHash&&this.reportingOptions&&this.layerItemsHash[e.id].supportsUpdate&&(a.name===t&&this.reportingOptions[e.id].like?i=!0:a.name===l&&this.reportingOptions[e.id].dislike&&(s=!0))})}return i||s}checkLikeDislikeFields(){this._likeFieldAvailable=!1,this._dislikeFieldAvailable=!1,this._isLikeBtnClicked=!1,this._isDislikeBtnClicked=!1,this._likeCount=0,this._disLikeCount=0;let e=this._selectedGraphic?.layer;if(this.reportingOptions&&e&&this.reportingOptions[e?.id]){if(this._likeField=this.reportingOptions[e.id].likeField||"",this._dislikeField=this.reportingOptions[e.id].dislikeField||"",!this._likeField&&!this._dislikeField)return;e.fields.forEach(i=>{this._validFieldTypes.indexOf(i.type)>-1&&this.layerItemsHash&&this.reportingOptions&&this.layerItemsHash[e.id].supportsUpdate&&(i.name===this._likeField&&this.reportingOptions[e.id].like?(this._likeFieldAvailable=!0,this._likeCount=this._selectedGraphic?.attributes[i.name]||0):i.name===this._dislikeField&&this.reportingOptions[e.id].dislike&&(this._dislikeFieldAvailable=!0,this._disLikeCount=this._selectedGraphic?.attributes[i.name]||0))}),this.getFromLocalStorage()}}onLikeButtonClick(){this._isDislikeBtnClicked&&this._selectedGraphic?.layer&&this.reportingOptions&&this.reportingOptions[this._selectedGraphic.layer.id].dislike&&this.onDislikeButtonClick(),this._isLikeBtnClicked=!this._isLikeBtnClicked,this._isLikeBtnClicked?this._likeCount++:this._likeCount--,this.updateFeaturesLikeDislikeField(this._likeField,this._isLikeBtnClicked)}onDislikeButtonClick(){this._isLikeBtnClicked&&this._selectedGraphic?.layer&&this.reportingOptions&&this.reportingOptions[this._selectedGraphic.layer.id].like&&this.onLikeButtonClick(),this._isDislikeBtnClicked=!this._isDislikeBtnClicked,this._isDislikeBtnClicked?this._disLikeCount++:this._disLikeCount--,this.updateFeaturesLikeDislikeField(this._dislikeField,this._isDislikeBtnClicked)}async updateFeaturesLikeDislikeField(e,i){let s={},t=this._selectedGraphic?.layer;this._updating=!0;let l=this._selectedGraphic;if(l){l.attributes[e]=Number(l.attributes[e])+(i?1:-1),s[t.objectIdField]=l.attributes[t.objectIdField],s[e]=l.attributes[e];let a=new C;if(a){a.attributes=s;let r={updateFeatures:[a]};await t.applyEdits(r).then(()=>{this._selectedGraphic=l,this.setInLocalStorage(),this._updating=!1,this.likeOrDislikeClicked.emit()},n=>{this._updating=!1,console.log(n)})}}}getFromLocalStorage(){let e=this._selectedGraphic?.layer&&this._selectedGraphic.layer.id,i=e?.toString()&&localStorage[e];if(i){let t=JSON.parse(i).filter(l=>l.id===this._selectedGraphic?.getObjectId());t.length>0&&(this._isLikeBtnClicked=t[0].like,this._isDislikeBtnClicked=t[0].dislike)}}setInLocalStorage(){let e=this._selectedGraphic?.layer&&this._selectedGraphic.layer.id,i=e?.toString()&&localStorage[e],s=[];if(i){s=JSON.parse(i);let t=s.findIndex(l=>l.id===this._selectedGraphic?.getObjectId());t>=0&&s.splice(t,1)}s.push({id:this._selectedGraphic?.getObjectId(),like:this._isLikeBtnClicked&&this._likeCount!==0,dislike:this._isDislikeBtnClicked&&this._disLikeCount!==0}),e?.toString()&&localStorage.setItem(e.toString(),JSON.stringify(s))}};f("feature-details",u);return u},"Graphic","rest/support/RelationshipQuery",a,b)