import { c as d } from "../../chunks/runtime.js";
import { html as i } from "lit-html";
import { classes as h } from "@arcgis/components-utils";
import p from "@geoscene/core/widgets/Print/PrintViewModel.js";
import { LitElement as m, createEvent as g, noShadowRoot as w, safeClassMap as l } from "@arcgis/lumina";
import { usePropertyChange as v } from "@arcgis/lumina/controllers";
import { reEmitEvent as o } from "@arcgis/lumina/controllers/accessor";
import { u } from "../../chunks/useT9n.js";
import { m as f } from "../../chunks/useViewModel.js";
import { g as n } from "../../chunks/globalCss.js";
import { css as _ } from "@lit/reactive-element/css-tag.js";
/*! All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
See https://js.geoscene.cn/4.33/geoscene/copyright.txt for details.
v4.33.18 */
const M = _`@layer{:root{--panel-min-height--large: 240px;--side-spacing: var(--calcite-spacing-lg);--cap-spacing: var(--calcite-spacing-md)}.geoscene-print{display:flex;position:relative;flex-grow:1;padding:0;min-height:var(--panel-min-height--large)!important;overflow-y:auto}.geoscene-print section[aria-hidden=true]{display:none}.geoscene-print__panel-items--centered{display:flex;align-items:center}.geoscene-print__container{display:flex;flex-direction:column;flex-grow:1}.geoscene-print__header-title{margin:0 auto 0 0;padding:var(--calcite-spacing-md) var(--calcite-spacing-lg);font-size:var(--calcite-font-size-0);font-weight:var(--calcite-font-weight-bold)}.geoscene-print__panel--error{color:var(--calcite-color-status-danger)}geoscene-print-template-selector{overflow-y:hidden;display:flex}}`, a = "geoscene-print", r = {
  base: a,
  headerTitle: `${a}__header-title`,
  panelItemsCentered: `${a}__panel-items--centered`,
  printWidgetContainer: `${a}__container`,
  panelError: `${a}__panel--error`
}, T = f(p), c = (s) => {
  if (!s)
    return "all";
  const e = typeof s == "string" ? s.split(",").map((t) => t.trim()).filter((t) => t) : [s];
  return !e.length || e.includes("all") ? "all" : e;
};
class $ extends m {
  constructor() {
    super(...arguments), this.messages = u({ blocking: !0 }), this.viewModel = T(this), this._showTemplates = !1, this.error = this.viewModel.error, this.hideHeader = !1, this.position = "top-left", this.icon = "print", this.allowedFormats = this.viewModel.allowedFormats, this.allowedLayouts = this.viewModel.allowedLayouts, this.exportedLinks = this.viewModel.exportedLinks, this.extraParameters = this.viewModel.extraParameters, this.headingLevel = 3, this.excludeDefaultTemplates = !this.viewModel.includeDefaultTemplates, this.excludeOrganizationTemplates = !1, this.outSpatialReference = this.viewModel.outSpatialReference, this.portal = this.viewModel.portal, this.showPrintAreaEnabled = this.viewModel.showPrintAreaEnabled, this.printServiceUrl = this.viewModel.printServiceUrl, this.templateCustomTextElements = this.viewModel.templateCustomTextElements, this.templateOptions = this.viewModel.templateOptions, this.autoDestroyDisabled = !1, this.state = this.viewModel.state, this.geoscenePropertyChange = v()("state"), this.geosceneReady = g(), this.geosceneComplete = o(() => this.viewModel, "complete"), this.geosceneSubmit = o(() => this.viewModel, "submit");
  }
  static {
    this.properties = { _showTemplates: 16, error: 16, hideHeader: 5, referenceElement: 1, position: 3, icon: 1, allowedFormats: [1, { type: String, converter: c }], allowedLayouts: [1, { type: String, converter: c }], browseTemplateButtonOnClick: 0, allowedFormatsForSaving: 1, exportedLinks: 0, extraParameters: 1, headingLevel: 9, excludeDefaultTemplates: 5, excludeOrganizationTemplates: 5, outSpatialReference: 0, portal: 0, showPrintAreaEnabled: 5, printServiceUrl: 1, saveAsButtonCallback: 0, templateCustomTextElements: 0, templateOptions: 0, autoDestroyDisabled: 5, messageOverrides: 0, label: 1, state: 3 };
  }
  static {
    this.styles = M;
  }
  static {
    this.shadowRootOptions = w;
  }
  async destroy() {
    await this.manager.destroy(), this.viewModel.destroy();
  }
  loaded() {
    this.manager.onLifecycle(() => []), this.viewModel.load();
    const { height: e, width: t } = this.viewModel.templateOptions;
    this.viewModel.templateOptions.width = t || 800, this.viewModel.templateOptions.height = e || 1100;
  }
  _showTemplateSelector() {
    this._showTemplates = !0;
  }
  _hideTemplateSelector() {
    this._showTemplates = !1;
  }
  render() {
    const e = {
      [r.panelItemsCentered]: this.viewModel.state === "initializing"
    };
    return i`<div class=${l(h(r.base, n.widget, n.panel, e))}>${this._renderPanel()}</div>`;
  }
  _renderPanel() {
    return this.viewModel.state === "initializing" ? i`<calcite-loader label=loading scale=m></calcite-loader>` : i`<calcite-flow><calcite-flow-item .selected=${!this._showTemplates}><div class=${l(r.printWidgetContainer)}>${this._renderPanelHeader()}${this._renderPanelContent()}</div></calcite-flow-item><calcite-flow-item .heading=${this.messages.chooseTemplate} .selected=${this._showTemplates} @calciteFlowItemBack=${(e) => {
      e.preventDefault(), this._showTemplates = !1;
    }}><geoscene-print-template-selector .messages=${this.messages} .viewModel=${this.viewModel} .browseTemplateButtonOnClick=${this.browseTemplateButtonOnClick} .hideTemplateSelector=${this._hideTemplateSelector.bind(this)} .excludeOrganizationTemplates=${this.excludeOrganizationTemplates}></geoscene-print-template-selector></calcite-flow-item></calcite-flow>`;
  }
  _renderPanelHeader() {
    return this.hideHeader ? null : i`<header class=${l(r.headerTitle)}>${this.messages.export}</header>`;
  }
  _renderPanelContent() {
    const e = this.viewModel.view, t = e?.type !== "2d";
    return !!this.error || t ? i`<div class=${l(r.panelError)}>${e ? t ? this.messages.sceneViewError : this.messages.serviceError : this.messages.noViewError}</div>` : i`<geoscene-print-main-panel .messages=${this.messages} .viewModel=${this.viewModel} .showTemplateSelector=${this._showTemplateSelector.bind(this)} .allowedFormatsForSaving=${this.allowedFormatsForSaving} .saveAsButtonCallback=${this.saveAsButtonCallback}></geoscene-print-main-panel>`;
  }
}
d("geoscene-print", $);
export {
  $ as GeoscenePrint
};