import { c as s } from "../../chunks/runtime.js";
import { html as a } from "lit-html";
import { LitElement as i } from "@arcgis/lumina";
import { i as l } from "../../chunks/utils.js";
import { css as o } from "@lit/reactive-element/css-tag.js";
import { u as c } from "../../chunks/useHandles.js";
import { watch as n } from "@arcgis/core/core/reactiveUtils.js";
/*! All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
v4.33.16 */
const p = o`calcite-tab{--calcite-tab-content-block-padding: 0}calcite-loader{margin-right:var(--calcite-spacing-xxs)}`;
class r extends i {
  constructor() {
    super(...arguments), this._prevLayoutTemplateId = null, this._handles = c("disconnect"), this._selectedTab = "layout", this._hasPendingExport = !1;
  }
  static {
    this.properties = { _selectedTab: 16, _hasPendingExport: 16, saveAsButtonCallback: 0, viewModel: 0, messages: 0, showTemplateSelector: 0, allowedFormatsForSaving: 1 };
  }
  static {
    this.styles = p;
  }
  loaded() {
    this.manager.onLifecycle(() => [
      this.viewModel.exportedLinks.on("change", () => {
        this._handles.removeHandles("pending-exports"), this._handles.addHandles(this.viewModel.exportedLinks.toArray().map((e) => n(() => e.state, () => this.requestUpdate(), { initial: !0 })), "pending-exports");
      })
    ]);
  }
  async _layoutTabChangeHandler() {
    const t = (this._prevLayoutTemplateId ? this.viewModel.getLayoutTemplateById(this._prevLayoutTemplateId) : null) ?? this.viewModel.defaultTemplate;
    await this.viewModel.applyTemplate(t), this._prevLayoutTemplateId = t?.id, this._selectedTab = "layout";
  }
  async _mapOnlyTabChangeHandler() {
    this._updatePrevLayoutTemplateId(), await this.viewModel.applyTemplate("map-only"), this._selectedTab = "map-only";
  }
  async _exportsTabChangeHandler() {
    this._updatePrevLayoutTemplateId(), this._selectedTab = "exports";
  }
  _selectExportsTab() {
    this._updatePrevLayoutTemplateId(), this._selectedTab = "exports";
  }
  _updatePrevLayoutTemplateId() {
    !l(this.viewModel.templateOptions.layout) && this.viewModel.templateOptions.id && (this._prevLayoutTemplateId = this.viewModel.templateOptions.id);
  }
  render() {
    const e = this.viewModel.exportedLinks.some(({ state: t }) => t === "pending");
    return a`<div><calcite-tabs layout=center bordered><calcite-tab-nav slot=title-group><calcite-tab-title @calciteTabsActivate=${this._layoutTabChangeHandler} .selected=${this._selectedTab === "layout"}>${this.messages.layoutTab}</calcite-tab-title><calcite-tab-title @calciteTabsActivate=${this._mapOnlyTabChangeHandler} .selected=${this._selectedTab === "map-only"}>${this.messages.mapOnlyTab}</calcite-tab-title><calcite-tab-title @calciteTabsActivate=${this._exportsTabChangeHandler} .selected=${this._selectedTab === "exports"}>${e ? a`<calcite-loader inline label=loading scale=s></calcite-loader>` : null}${this.messages.exportsTab}</calcite-tab-title></calcite-tab-nav><calcite-tab selected><arcgis-print-layout-panel .messages=${this.messages} .viewModel=${this.viewModel} .showTemplateSelector=${this.showTemplateSelector} .selectExportsTab=${this._selectExportsTab.bind(this)}></arcgis-print-layout-panel></calcite-tab><calcite-tab><arcgis-print-map-only-panel .messages=${this.messages} .viewModel=${this.viewModel} .selectExportsTab=${this._selectExportsTab.bind(this)}></arcgis-print-map-only-panel></calcite-tab><calcite-tab><arcgis-print-exports-panel .messages=${this.messages} .viewModel=${this.viewModel} .allowedFormatsForSaving=${this.allowedFormatsForSaving} .saveAsButtonCallback=${this.saveAsButtonCallback}></arcgis-print-exports-panel></calcite-tab></calcite-tabs></div>`;
  }
}
s("arcgis-print-main-panel", r);
export {
  r as PrintMainPanel
};
