/* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
import { c as s } from "../../chunks/runtime.js";
import { css as i, html as a } from "lit";
import { LitElement as l } from "@arcgis/lumina";
import { i as o } from "../../chunks/utils3.js";
import { u as c } from "../../chunks/useHandles.js";
import { watch as d } from "@arcgis/core/core/reactiveUtils.js";
const n = i`:host{display:flex;flex-direction:column;flex-grow:1}calcite-tabs{flex-grow:1}calcite-tab{--calcite-tab-content-block-padding: 0}calcite-loader{margin-right:var(--calcite-spacing-xxs)}`;
class r extends l {
  constructor() {
    super(...arguments), this._prevLayoutTemplateId = null, this._handles = c("disconnect"), this._selectedTab = "layout", this._hasPendingExport = !1, this.hideAdvancedOptions = !1, this.autoPopulateAuthor = !1, this.hideFeatureAttributes = !1, this.hideIncludeTables = !1;
  }
  static {
    this.properties = { _selectedTab: 16, _hasPendingExport: 16, hideAdvancedOptions: 5, autoPopulateAuthor: 5, showSaveAs: 5, arcgisSaveAs: 0, viewModel: 0, messages: 0, showTemplateSelector: 0, allowedFormatsForSaving: 1, hideFeatureAttributes: 5, hideIncludeTables: 5 };
  }
  static {
    this.styles = n;
  }
  loaded() {
    this.manager.onLifecycle(() => [
      this.viewModel.exportedLinks.on("change", () => {
        this._handles.removeHandles("pending-exports"), this._handles.addHandles(this.viewModel.exportedLinks.toArray().map((e) => d(() => 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() {
    !o(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`<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} .hideAdvancedOptions=${this.hideAdvancedOptions} .autoPopulateAuthor=${this.autoPopulateAuthor} .hideFeatureAttributes=${this.hideFeatureAttributes} .hideIncludeTables=${this.hideIncludeTables} .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} .hideAdvancedOptions=${this.hideAdvancedOptions} .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} .showSaveAs=${this.showSaveAs} .arcgisSaveAs=${this.arcgisSaveAs}></arcgis-print-exports-panel></calcite-tab></calcite-tabs>`;
  }
}
s("arcgis-print-main-panel", r);
export {
  r as PrintMainPanel
};
