import { c as m } from "../../chunks/runtime.js";
import { css as x, html as s } from "lit";
import { watch as _ } from "@arcgis/core/core/reactiveUtils.js";
import { g as l } from "../../chunks/globalCss.js";
import { u as f } from "../../chunks/useT9n.js";
import { createRef as d, ref as p } from "lit/directives/ref.js";
import v from "@arcgis/core/widgets/Expand/ExpandViewModel.js";
import { usePropertyChange as b } from "@arcgis/lumina/controllers";
import { m as w } from "../../chunks/useViewModel.js";
import { LitElement as $, createEvent as y, safeClassMap as i, nothing as C } from "@arcgis/lumina";
/*! All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.34/esri/copyright.txt for details.
v4.34.7 */
const E = x`:host{display:flex;pointer-events:auto;--arcgis-expand-icon-number-left: none;--arcgis-expand-icon-number-right: none}arcgis-expand>.arcgis-expand__content--expanded{background-color:var(--calcite-color-background)}.arcgis-expand{--esri-widget-panel-max-height: 95svh;--calcite-sheet-max-height: var(--esri-widget-panel-max-height);--calcite-sheet-height: auto;min-width:32px;min-height:32px}.arcgis-expand__toggle{position:relative}.arcgis-expand__popover-content{flex-direction:column;display:flex;max-height:var(--arcgis-expand-max-height, 95svh);::slotted(*){max-height:var(--arcgis-expand-max-height, 95svh);overflow-y:auto}::slotted(arcgis-sketch){--arcgis-internal-sketch-gap: var(--calcite-spacing-none)}::slotted(:is(arcgis-area-measurement-2d,arcgis-area-measurement-3d,arcgis-basemap-gallery,arcgis-basemap-layer-list,arcgis-bookmarks,arcgis-building-explorer,arcgis-catalog-layer-list,arcgis-directions,arcgis-direct-line-measurement-3d,arcgis-distance-measurement-2d,arcgis-editor,arcgis-feature-form,arcgis-features,arcgis-layer-list,arcgis-legend,arcgis-line-of-sight,arcgis-print,arcgis-shadow-cast,arcgis-slice,arcgis-table-list,arcgis-utility-network-trace,arcgis-grid-controls)){width:var(--arcgis-internal-panel-width);min-width:var(--calcite-spacing-xxxl);min-height:var(--calcite-spacing-xxxl);transition:max-height .25s ease-in-out}}.arcgis-expand__popover-content .esri-widget--panel{width:300px}.arcgis-expand__panel{max-height:var(--esri-widget-panel-max-height)}.arcgis-expand__panel-content{::slotted(*){width:100%}::slotted(:is(arcgis-area-measurement-2d,arcgis-area-measurement-3d,arcgis-basemap-gallery,arcgis-basemap-layer-list,arcgis-bookmarks,arcgis-building-explorer,arcgis-catalog-layer-list,arcgis-directions,arcgis-direct-line-measurement-3d,arcgis-distance-measurement-2d,arcgis-editor,arcgis-feature-form,arcgis-features,arcgis-layer-list,arcgis-legend,arcgis-line-of-sight,arcgis-print,arcgis-shadow-cast,arcgis-slice,arcgis-table-list,arcgis-utility-network-trace,arcgis-grid-controls)){overflow-y:auto}}.arcgis-expand__panel-content .esri-widget{width:auto}.arcgis-expand__panel-content .esri-widget--panel{flex:auto}.arcgis-map-container-ui__element .arcgis-expand__popover-content .esri-widget,.arcgis-map-container-ui__element .arcgis-expand__popover-content .esri-widget.esri-component,.arcgis-map-container-ui__element .arcgis-expand__panel-content .esri-widget,.arcgis-map-container-ui__element .arcgis-expand__panel-content .esri-widget.esri-component,.arcgis-expand__popover-content .esri-widget,.arcgis-expand__popover-content .esri-widget.esri-component,.arcgis-expand__panel-content .esri-widget,.arcgis-expand__panel-content .esri-widget.esri-component{box-sizing:border-box;box-shadow:none;margin-bottom:0}.arcgis-expand__panel-content,.arcgis-expand__content-container{background-color:var(--calcite-color-foreground-1);flex-direction:column;flex:auto;justify-content:stretch;display:flex}.arcgis-expand__sheet .arcgis-expand__panel-content,.arcgis-expand__sheet .arcgis-expand__content-container{overflow:hidden}.arcgis-expand__panel-icon-number{align-self:center}.arcgis-expand__icon{display:flex}calcite-button:not(:hover) .arcgis-expand__icon:not(calcite-icon){color:var(--calcite-color-text-3)}.arcgis-expand__icon-flip{transform:var(--arcgis-collapse-icon-flip)}.arcgis-expand__icon-number{transform-origin:50%;color:var(--calcite-color-text-inverse);pointer-events:none;background-color:var(--calcite-color-text-3);border-radius:var(--calcite-spacing-xl);justify-content:center;align-items:center;height:var(--calcite-spacing-lg);padding:.125em .333em;font-size:var(--calcite-font-size-sm);line-height:1em;display:flex;position:absolute;top:-6px;left:var(--arcgis-expand-icon-number-left);right:var(--arcgis-expand-icon-number-right)}`, a = "arcgis-expand", n = {
  base: a,
  toggle: `${a}__toggle`,
  popoverContent: `${a}__popover-content`,
  panel: `${a}__panel`,
  panelContent: `${a}__panel-content`,
  sheet: `${a}__sheet`,
  contentContainer: `${a}__content-container`,
  icon: `${a}__icon`,
  iconFlip: `${a}__icon-flip`,
  iconNumber: `${a}__icon-number`
}, g = "chevrons-left", h = "chevrons-right", T = w(v);
class k extends $ {
  constructor() {
    super(...arguments), this.popoverEl = d(), this.messages = f({}), this.viewModel = T(this), this.toggleActionEl = d(), this.view = this.viewModel.view, this.state = this.viewModel.state, this.autoDestroyDisabled = !1, this.autoCollapse = this.viewModel.autoCollapse, this.closeOnEscDisabled = !1, this.content = "", this.expandTooltip = "", this.collapseTooltip = "", this.focusTrapDisabled = !1, this.focusTrapEnabled = this.focusTrapDisabled, this.group = this.viewModel.group, this.iconNumber = 0, this.mode = "auto", this.arcgisPropertyChange = b()("expanded"), this.arcgisReady = y();
  }
  static {
    this.properties = { expandTitle: 16, _displaySheet: 16, view: 0, state: 3, icon: 1, label: 1, autoDestroyDisabled: 5, position: 1, referenceElement: 1, autoCollapse: 5, closeOnEscDisabled: 5, content: 1, expanded: 7, expandIcon: 3, expandTooltip: 1, collapseIcon: 3, collapseTooltip: 1, focusTrapDisabled: 5, focusTrapEnabled: 5, group: 1, iconNumber: 9, mode: 1, placement: 1, messageOverrides: 0 };
  }
  static {
    this.styles = E;
  }
  get expandTitle() {
    const { expanded: e, messages: t, collapseTooltip: r, expandTooltip: o } = this;
    return (e ? r || t.collapse : o || t.expand) ?? "";
  }
  get _displaySheet() {
    switch (this.mode) {
      case "drawer":
        return !0;
      case "auto":
        return this.viewModel.view?.widthBreakpoint === "xsmall";
      default:
        return !1;
    }
  }
  get expanded() {
    return this.viewModel.expanded;
  }
  set expanded(e) {
    this.viewModel.expanded = e;
  }
  get expandIcon() {
    if (this._expandIcon)
      return this._expandIcon;
    let e = null;
    return this.content instanceof HTMLElement && ("widget" in this.content && this.content.widget?.icon ? e = this.content.widget.icon : "icon" in this.content ? e = this.content.icon : e = this.content.getAttribute("icon")), e ?? g;
  }
  set expandIcon(e) {
    this._expandIcon = e;
  }
  get collapseIcon() {
    return this._collapseIcon ?? h;
  }
  set collapseIcon(e) {
    this._collapseIcon = e;
  }
  async collapse() {
    this.expanded = !1;
  }
  async destroy() {
    await this.manager.destroy();
  }
  async expand() {
    this.expanded = !0;
  }
  loaded() {
    this.manager.onLifecycle(() => [
      _(() => this.viewModel?.view?.size, () => this.popoverEl?.value?.reposition(), { initial: !0 })
    ]);
  }
  toggle() {
    this.expanded = !this.expanded;
  }
  getPopoverPlacement() {
    if (this.placement)
      return this.placement;
    switch (this.el.slot) {
      case "bottom-start":
      case "bottom-left":
        return "right-end";
      case "bottom-right":
      case "bottom-end":
        return "left-end";
      case "top-start":
      case "top-left":
        return "right-start";
      case "top-right":
      case "top-end":
        return "left-start";
      case "manual":
      default:
        return "auto";
    }
  }
  _isCloseOnEscapeDisabled(e) {
    const { closeOnEscDisabled: t } = this;
    return typeof t == "function" ? t(e) : t;
  }
  _handlePopoverClose(e) {
    e.target === this.popoverEl.value && this.collapse();
  }
  _handleKeyDown(e) {
    this.expanded && e.key === "Escape" && this._isCloseOnEscapeDisabled(e) && e.preventDefault();
  }
  render() {
    const { _displaySheet: e, toggleActionEl: t, viewModel: { expanded: r }, label: o } = this;
    return s`<div class=${i({ [n.base]: !0, [l.widget]: !0 })}>${this._renderToggle()}${e ? s`<calcite-sheet class=${i(n.sheet)} height=l .label=${o ?? ""} @keydown=${this._handleKeyDown} .open=${r} position=block-end @calciteSheetClose=${this.collapse}><calcite-panel class=${i(n.panel)} closable .closed=${!r} .heading=${o} @keydown=${this._handleKeyDown} @calcitePanelClose=${this.collapse}><div class=${i(n.panelContent)}>${this._renderContent()}</div></calcite-panel></calcite-sheet>` : t.value ? s`<calcite-popover .focusTrapDisabled=${this.focusTrapDisabled} .label=${o ?? ""} @keydown=${this._handleKeyDown} trigger-disabled .open=${this.expanded} overlay-positioning=fixed .placement=${this.getPopoverPlacement()} .referenceElement=${t.value} @calcitePopoverClose=${this._handlePopoverClose} ${p(this.popoverEl)}><div class=${i(n.popoverContent)}>${this._renderContent()}</div></calcite-popover>` : null}</div>`;
  }
  _renderBadgeNumber() {
    const { expanded: e, iconNumber: t } = this;
    return t && !e ? s`<span class=${i(n.iconNumber)}>${t}</span>` : null;
  }
  _renderToggleButton() {
    const { expanded: e, expandTitle: t, expandIcon: r, collapseIcon: o } = this, c = e ? o : r, u = c === g || c === h;
    return s`<calcite-action class=${i(l.widgetButton)} @click=${this.toggle} scale=s .text=${t} title=${t ?? C} ${p(this.toggleActionEl)}>${c ? s`<calcite-icon class=${i({ [n.icon]: !0, [n.iconFlip]: u })} .icon=${c} scale=s></calcite-icon>` : null}</calcite-action>`;
  }
  _renderToggle() {
    return s`<div class=${i(n.toggle)}>${this._renderToggleButton()}${this._renderBadgeNumber()}</div>`;
  }
  _renderContent() {
    return s`<div class=${i(n.contentContainer)}><slot></slot></div>`;
  }
}
m("arcgis-expand", k);
export {
  k as ArcgisExpand
};
