/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import { c as l } from "../../chunks/runtime.js";
import "@arcgis/toolkit/intl";
import { isEmpty as m } from "lodash-es";
import "luxon";
import "d3-array";
import "@arcgis/toolkit/type";
import "../../chunks/series-types.js";
import "../../chunks/index.js";
import "@arcgis/core/Graphic.js";
import "@arcgis/core/renderers/support/jsonUtils.js";
import "@arcgis/core/symbols/support/symbolUtils.js";
import "@esri/arcgis-html-sanitizer";
import "@arcgis/core/intl.js";
import "@arcgis/core/layers/support/FeatureFilter.js";
import "@arcgis/core/smartMapping/statistics/histogram.js";
import "@arcgis/core/smartMapping/statistics/summaryStatistics.js";
import "simple-statistics";
import "@arcgis/core/request.js";
import "@arcgis/core/core/sql.js";
import "@arcgis/core/AttributeBinsGraphic.js";
import "@arcgis/core/geometry/support/jsonUtils.js";
import "@arcgis/core/rest/support/AttributeBinsQuery.js";
import "@arcgis/core/rest/support/StatisticDefinition.js";
import "@arcgis/core/time/TimeExtent.js";
import "@arcgis/core/core/promiseUtils.js";
import "@arcgis/toolkit/dom";
import { e as c } from "../../chunks/popover-ui-utils.js";
import { m as p, U as s } from "../../chunks/chart-ui-utils2.js";
import { u as h } from "../../chunks/useT9n.js";
import { css as d, html as u } from "lit";
import { createRef as n, ref as r } from "lit/directives/ref.js";
import { LitElement as g, createEvent as o, safeClassMap as i } from "@arcgis/lumina";
const e = {
  jsAppFlyout: "js-app-flyout",
  chartRenameComponent: "chart-rename-component",
  renameLabelContainer: "rename-label-container",
  renamePanel: "rename-panel"
}, v = d`.hide{visibility:hidden}.am5-html-container{z-index:101!important}.am5-layer-1000{z-index:1000!important}.am5-layer-30{z-index:100!important}.show{display:block}.notifyPanel{flex:0 1 auto}.disable-interactions{pointer-events:none}.dim-text{color:var(--arcgis-charts-dim-text)}.chart-rename-component{width:var(--arcgis-charts-config-panel-width-medium);height:var(--arcgis-charts-config-panel-height)}:host{overflow-y:auto;width:min-content}.rename-label-container{display:flex;padding:0 1rem;margin-top:1rem}.rename-label-container calcite-label{flex:1 1 0px;display:flex;width:0px}.rename-panel{width:calc(var(--calcite-panel-width-multiplier) * 20vw);max-width:calc(var(--calcite-panel-width-multiplier) * 420px);min-width:calc(var(--calcite-panel-width-multiplier) * 240px)}`;
class C extends g {
  constructor() {
    super(...arguments), this._messages = h(), this.characterLimitInputElement = n(), this.popoverElement = n(), this.isChartTitleInvalid = !1, this.changedName = "", this.name = "", this.arcgisChartsConfigChartRenamePopoverChange = o(), this.arcgisChartsConfigPopoverClose = o();
  }
  static {
    this.properties = { isChartTitleInvalid: 16, changedName: 16, messageOverrides: 0, name: 1, open: 5, referenceElement: 0 };
  }
  static {
    this.styles = v;
  }
  async reposition() {
    await this.popoverElement.value?.reposition();
  }
  willUpdate(t) {
    t.has("name") && (this.changedName = this.name);
  }
  updated() {
    this.popoverElement.value?.reposition(), c(this.popoverElement.value, this.open);
  }
  onNameChange(t) {
    const a = t.target.value;
    this.changedName = a, this.isChartTitleInvalid = m(a.trim()), this.characterLimitInputElement.value && p({
      inputElement: this.characterLimitInputElement.value,
      status: this.isChartTitleInvalid ? s.INVALID : s.IDLE
    });
  }
  onCancelClick() {
    this.changedName = this.name, this.arcgisChartsConfigPopoverClose.emit(), this.open = !1;
  }
  onSubmitClick() {
    this.isChartTitleInvalid || (this.name = this.changedName, this.arcgisChartsConfigChartRenamePopoverChange.emit({ name: this.changedName }), this.open = !1);
  }
  popoverClose() {
    this.changedName = this.name, this.open = !1, this.arcgisChartsConfigPopoverClose.emit();
  }
  render() {
    return u`<div class=${i({
      [e.chartRenameComponent]: !0,
      [e.jsAppFlyout]: !0
    })}><calcite-popover .referenceElement=${this.referenceElement ?? document.body} @calcitePopoverClose=${this.popoverClose} .open=${this.open} placement=bottom label auto-close ${r(this.popoverElement)}><calcite-panel class=${i(e.renamePanel)} closable .closed=${!this.open} @calcitePanelClose=${this.popoverClose} .heading=${this._messages.renameChart}><div class=${i(e.renameLabelContainer)}><calcite-label>${this._messages.chartName}<calcite-input required type=text .value=${this.changedName} @calciteInputInput=${this.onNameChange} ${r(this.characterLimitInputElement)}></calcite-input><arcgis-charts-config-invalid-input-message .invalidInputMessage=${this._messages.emptyChartTitle} .isInvalid=${this.isChartTitleInvalid}></arcgis-charts-config-invalid-input-message></calcite-label></div><calcite-button slot=footer appearance=solid scale=m width=half @click=${this.onSubmitClick}>${this._messages.submit}</calcite-button><calcite-button slot=footer appearance=outline-fill scale=m width=half @click=${this.onCancelClick}>${this._messages.cancel}</calcite-button></calcite-panel></calcite-popover></div>`;
  }
}
l("arcgis-charts-config-chart-rename-popover", C);
export {
  C as ArcgisChartsConfigChartRenamePopover
};
