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