import { c as o } from "../../chunks/runtime.js";
import { css as n, html as l } from "lit";
import { keyed as a } from "lit/directives/keyed.js";
import { watch as r } from "@arcgis/core/core/reactiveUtils.js";
import { LitElement as m, safeClassMap as s } from "@arcgis/lumina";
import { u as p } from "../../chunks/useHandles.js";
import { a as d, g as h, b as _ } from "../../chunks/utils.js";
import { useDirection as g } from "@arcgis/lumina/controllers";
/*! 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 u = n`.arcgis-print__template-select-container{border:1px solid var(--calcite-color-border-1);cursor:pointer}.arcgis-print__template-select-container .arcgis-print__template-select-error,.arcgis-print__template-select-container .arcgis-print__template-select-arrow{display:flex;align-self:center;margin-right:var(--calcite-spacing-md)}`, i = "arcgis-print", c = {
  templateSelectContainer: `${i}__template-select-container`,
  templateSelectError: `${i}__template-select-error`,
  templateSelectArrow: `${i}__template-select-arrow`
};
class $ extends m {
  constructor() {
    super(...arguments), this._handles = p("disconnect"), this._direction = g(), this._templateState = "not-loaded";
  }
  static {
    this.properties = { _selectedTemplate: 16, _templateState: 16, viewModel: 0, messages: 0, showTemplateSelector: 0 };
  }
  static {
    this.styles = u;
  }
  loaded() {
    this.manager.onLifecycle(() => [
      r(() => this.viewModel.templateOptions.id, (e) => {
        this._handles.removeHandles("template-handle"), this._selectedTemplate = e ? this.viewModel.getLayoutTemplateById(e) ?? void 0 : void 0, this._handles.addHandles(r(() => this._selectedTemplate?.state, (t) => this._templateState = t ?? "not-loaded", { initial: !0 }), "template-handle");
      }, { initial: !0 })
    ]);
  }
  render() {
    const e = this._selectedTemplate ? d(this._selectedTemplate, this.messages) : this.messages.selectTemplate;
    return l`<calcite-block class=${s(c.templateSelectContainer)} .description=${h(this._selectedTemplate)} .heading=${e} .label=${e} .loading=${this._templateState === "loading"} @click=${this.showTemplateSelector} @keydown=${(t) => {
      (t.key === "Enter" || t.key === " ") && this.showTemplateSelector();
    }} tabindex=0>${a("template-select-icon", l`<calcite-icon .icon=${(this._selectedTemplate?.layout ? _(this._selectedTemplate.layout) : null) || "custom-print"} scale=l slot=content-start></calcite-icon>`)}${this._templateState === "error" ? a("template-select-error", l`<calcite-icon class=${s(c.templateSelectError)} icon=exclamation-mark-circle scale=s slot=actions-end></calcite-icon>`) : null}${a("template-select-arrow", l`<calcite-icon class=${s(c.templateSelectArrow)} .icon=${this._direction === "rtl" ? "chevron-left" : "chevron-right"} scale=s slot=actions-end></calcite-icon>`)}</calcite-block>`;
  }
}
o("arcgis-print-template-select", $);
export {
  $ as PrintTemplateSelect
};
