/* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
import { c } from "../../chunks/runtime.js";
import { css as h, html as r } from "lit";
import { classes as g } from "@arcgis/toolkit/dom";
import p from "@arcgis/core/widgets/Print/PrintViewModel.js";
import { LitElement as m, createEvent as a, safeClassMap as w } from "@arcgis/lumina";
import { usePropertyChange as u } from "@arcgis/lumina/controllers";
import { reEmitEvent as l } from "@arcgis/lumina/controllers/accessor";
import { u as f } from "../../chunks/useT9n.js";
import { m as v } from "../../chunks/useViewModel.js";
import { g as n } from "../../chunks/globalCss.js";
import { watch as s } from "@arcgis/core/core/reactiveUtils.js";
const _ = h`.esri-widget__heading{color:var(--calcite-color-text-2);margin:0 0 .5rem;font-weight:var(--calcite-font-weight-semibold)}h1.esri-widget__heading{font-size:var(--calcite-font-size-xl)}h2.esri-widget__heading{font-size:var(--calcite-font-size-md)}h3.esri-widget__heading,h4.esri-widget__heading,h5.esri-widget__heading,h6.esri-widget__heading{font-size:var(--calcite-font-size)}.esri-widget{box-sizing:border-box;color:var(--calcite-color-text-2);background-color:var(--calcite-color-foreground-1);font-size:var(--calcite-font-size);line-height:var(--calcite-font-line-height-relative-tight)}.esri-widget *,.esri-widget :before,.esri-widget :after{box-sizing:inherit}.esri-widget.esri-widget--disabled>*{opacity:.4;pointer-events:none}.esri-widget.esri-widget--compact{--esri-widget-padding-y: 0;--esri-widget-padding-x: 0}.esri-widget__anchor{color:var(--calcite-color-text-2)}.esri-widget__anchor:hover{color:var(--calcite-color-text-3)}.esri-widget__anchor:hover,.esri-widget__anchor:focus{text-decoration:underline}.esri-widget__anchor--disabled{opacity:.4;pointer-events:none}.esri-widget__header{background-color:var(--calcite-color-foreground-1);flex:1 0 100%;justify-content:space-between;align-items:center;width:100%;min-height:48px;padding:12px 0 12px 15px;display:flex}.esri-widget__heading{word-break:break-word}.esri-widget__header .esri-widget__heading{width:calc(100% - 48px);text-align:initial;color:var(--calcite-color-text-1);align-items:center;margin:0;padding:0;display:flex}.esri-widget__header-button{appearance:none;cursor:pointer;color:var(--calcite-color-text-2);background-color:var(--calcite-color-foreground-1);border:none;flex:0 0 48px;justify-content:center;align-self:stretch;align-items:center;width:48px;padding:0;display:flex}.esri-widget__footer{background-color:var(--calcite-color-foreground-1);justify-content:center;align-items:center;width:100%;min-height:48px;display:flex}.esri-widget__footer-pagination{color:var(--calcite-color-text-2);justify-content:space-between;align-items:center;display:flex}.esri-widget__footer-pagination-previous-button,.esri-widget__footer-pagination-next-button{cursor:pointer;background-color:var(--calcite-color-foreground-1);border:0;margin:0 7px;padding:12px 15px;transition:background-color .125s ease-in-out}.esri-widget__footer-pagination-previous-button:hover,.esri-widget__footer-pagination-previous-button:focus,.esri-widget__footer-pagination-next-button:hover,.esri-widget__footer-pagination-next-button:focus{color:var(--calcite-color-text-1);background-color:var(--calcite-color-foreground-1)}.esri-menu{visibility:hidden;z-index:1;background-clip:padding;background-color:var(--calcite-color-foreground-1);background-clip:padding-box;width:100%;max-height:0;margin:2px 0 0;padding:0;font-size:var(--calcite-font-size);line-height:var(--calcite-spacing-xl);position:absolute;top:100%;left:0;overflow:hidden;box-shadow:0 1px 2px #0000004d}.esri-menu .esri-menu__header{color:var(--calcite-color-text-inverse);background-color:var(--calcite-color-inverse);padding:6px 12px}.esri-menu__list{margin:0;padding:0;list-style:none}.esri-menu__list-item{cursor:pointer;border-top:1px solid #adadad4d;border-left:3px solid #0000;padding:.8em 1em}.esri-menu__list-item [class^=esri-icon-],.esri-menu__list-item [class*=" esri-icon-"]{padding-right:2.8px}.esri-menu__list-item:first-child{border-top:none}.esri-menu__list-item--focus,.esri-menu__list-item:hover,.esri-menu__list-item:focus{background-color:var(--calcite-color-foreground-1)}.esri-menu__list-item:active{background-color:var(--calcite-color-foreground-current)}.esri-menu__list-item--active,.esri-menu__list-item--active:hover,.esri-menu__list-item--active:focus{background-color:var(--calcite-color-foreground-1);border-left-color:var(--calcite-color-brand)}.esri-widget__table{border-collapse:collapse;color:var(--calcite-color-text-1);border:none;width:100%;line-height:var(--calcite-font-line-height-relative-tight)}.esri-widget__table tr:nth-child(odd){background-color:var(--calcite-color-transparent)}.esri-widget__table tr:nth-child(2n){background-color:var(--calcite-color-transparent-press)}.esri-widget__table tr a{color:var(--calcite-color-text-2)}.esri-widget__table tr a:hover,.esri-widget__table tr a:focus{color:var(--calcite-color-text-1)}.esri-widget__table tr td,.esri-widget__table tr th{vertical-align:top;word-break:break-word;padding:.5em .7em;font-size:var(--calcite-font-size-sm);font-weight:var(--calcite-font-weight-regular)}.esri-widget__table tr th{text-align:left;border-right:3px solid #0000000d;width:50%}.esri-widget__table tr td{width:50%}.esri-input{color:var(--calcite-color-text-1);background-color:var(--calcite-color-foreground-1);border:1px solid #959595;font-size:var(--calcite-font-size)}.esri-input::-ms-clear{display:none}.esri-input::placeholder{opacity:1;color:var(--calcite-color-text-2)}.esri-input:placeholder-shown{text-overflow:ellipsis}.esri-input[type=text],.esri-input[type=password],.esri-input[type=number]{height:32px;padding:0 .5em}calcite-combobox.esri-input{border:none}.esri-widget__content--empty{text-align:center;color:var(--calcite-color-border-input);flex-flow:column wrap;align-items:center;padding:18px 22px;display:flex}.esri-widget__content--empty h1.esri-widget__heading,.esri-widget__content--empty h2.esri-widget__heading,.esri-widget__content--empty h3.esri-widget__heading,.esri-widget__content--empty h4.esri-widget__heading,.esri-widget__content--empty h5.esri-widget__heading{font-weight:var(--calcite-font-weight-regular)}.esri-widget__content-illustration--empty{width:128px;padding:1rem 0}.esri-widget__content-icon--empty{width:32px;padding:.5rem 0}.esri-select{appearance:none;cursor:pointer;color:var(--calcite-color-text-2);background:var(--calcite-color-foreground-1) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='-8 -8 32 32' width='32' height='32'%3E%3Cpath d='M8 11.207l-4-4V5.793l4 4 4-4v1.414z' fill='%23adadad' fillrule='nonzero'/%3E%3C/svg%3E") 100% no-repeat;border:1px solid #959595;border-radius:0;width:100%;height:32px;margin:0;padding:0 .5em;font-family:inherit;font-size:.85em;display:block}.esri-select[disabled]{cursor:auto}.esri-select::-ms-expand{display:none}.esri-disabled a,.esri-disabled [role=menu],.esri-disabled [role=checkbox],.esri-disabled [class^=esri-icon-],.esri-disabled [class*=" esri-icon-"]{color:var(--calcite-color-text-3)}.keynav-mode .esri-widget:focus,.keynav-mode .esri-widget :focus{z-index:1;outline-offset:2px;outline:2px solid #adadad}.esri-widget__loader-animation{border:.15em solid #adadad4d;border-top-color:var(--calcite-color-border-input);border-radius:100%;width:1em;height:1em;font-size:var(--calcite-font-size-md);animation:1.25s linear infinite esri-rotate;display:block;transform:translateZ(0)}:dir(rtl) .esri-widget__table th{text-align:right;border-left:3px solid #0000000d;border-right:none}:dir(rtl) .esri-select{background-position:0}:dir(rtl) .esri-menu__list-item{border-left:none;border-right:3px solid #0000}:dir(rtl) .esri-menu__list-item [class^=esri-icon-],:dir(rtl) .esri-menu__list-item [class*=" esri-icon-"]{padding-left:2px;padding-right:0}:dir(rtl) .esri-menu__list-item--active{border-right-color:var(--calcite-color-brand)}.esri-icon-font-fallback-text{clip:rect(0 0 0 0);width:1px;height:1px;position:absolute;overflow:hidden}.esri-rotating{animation:1.25s linear infinite esri-rotate;transform:translateZ(0)}.esri-clearfix:before,.esri-clearfix:after{content:" ";display:table}.esri-clearfix:after{clear:both}.esri-interactive{cursor:pointer}.esri-hidden{display:none!important}.esri-invisible{visibility:hidden!important}.esri-offscreen{position:absolute;top:-999em;left:-999em}.esri-match-height{flex-direction:column;flex:auto;display:flex;overflow:hidden}:host{--panel-min-height--large: 240px;display:flex;flex-direction:column;flex-grow:1}.root{display:flex;position:relative;flex-grow:1;min-height:var(--panel-min-height--large)}.root section[aria-hidden=true]{display:none}.panel-items-centered{display:flex;align-items:center}.container{display:flex;flex-direction:column;flex-grow:1}.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)}.panel-error{color:var(--calcite-color-status-danger)}`, b = v(p), d = (o) => {
  if (!o)
    return "all";
  const e = typeof o == "string" ? o.split(",").map((t) => t.trim()).filter((t) => t) : [o];
  return !e.length || e.includes("all") ? "all" : e;
};
class x extends m {
  constructor() {
    super(...arguments), this.messages = f({ blocking: !0 }), this.viewModel = b(this), this.error = null, this._showTemplates = !1, this.view = this.viewModel.view, this.hideHeader = !1, this.icon = "print", this.hideAdvancedOptions = !1, this.allowedFormats = this.viewModel.allowedFormats, this.allowedLayouts = this.viewModel.allowedLayouts, this.autoPopulateAuthor = !1, this.exportedLinks = this.viewModel.exportedLinks, this.extraParameters = this.viewModel.extraParameters, this.headingLevel = 3, this.hideFeatureAttributes = !1, this.hideIncludeTables = !1, 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.arcgisComplete = l(() => this.viewModel, "complete"), this.arcgisPropertyChange = u()("state"), this.arcgisReady = a(), this.arcgisSubmit = l(() => this.viewModel, "submit"), this.arcgisBrowseTemplatesChange = a(), this.arcgisSaveAs = a();
  }
  static {
    this.properties = { error: 16, _showTemplates: 16, view: 0, hideHeader: 5, referenceElement: 1, icon: 1, hideAdvancedOptions: 5, allowedFormats: [1, { type: String, converter: d }], allowedLayouts: [1, { type: String, converter: d }], autoPopulateAuthor: 5, allowedFormatsForSaving: 1, exportedLinks: 0, extraParameters: 0, headingLevel: 9, hideFeatureAttributes: 5, hideIncludeTables: 5, excludeDefaultTemplates: 5, excludeOrganizationTemplates: 5, outSpatialReference: 0, portal: 0, showPrintAreaEnabled: 5, printServiceUrl: 1, showSaveAs: 5, templateCustomTextElements: 0, templateOptions: 0, autoDestroyDisabled: 5, messageOverrides: 0, label: 1, state: 32 };
  }
  static {
    this.styles = _;
  }
  get excludeDefaultTemplates() {
    return !this.viewModel.includeDefaultTemplates;
  }
  set excludeDefaultTemplates(e) {
    this.viewModel.includeDefaultTemplates = !e;
  }
  addPortalTemplate(e) {
    return this.viewModel.addPortalTemplate(e);
  }
  async destroy() {
    await this.manager.destroy(), this.viewModel.destroy();
  }
  loaded() {
    this.manager.onLifecycle(() => [
      s(() => this.viewModel.error, (i) => this.error = i),
      s(() => this.viewModel.state, (i) => {
        i === "ready" && this.arcgisReady.emit();
      }),
      this.viewModel.browseTemplates.on("change", (i) => {
        this.arcgisBrowseTemplatesChange.emit(i);
      }),
      s(() => [this.printServiceUrl, this.portal], () => {
        this.viewModel.load();
      }, { initial: !0 })
    ]);
    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 = {
      "panel-items-centered": this.viewModel.state === "initializing"
    };
    return r`<div class=${w(g("root", n.widget, n.panel, e))}>${this._renderPanel()}</div>`;
  }
  _renderPanel() {
    return this.viewModel.state === "disabled" || this.viewModel.state === "initializing" ? r`<calcite-loader .label=${this.messages.loading} scale=m></calcite-loader>` : r`<calcite-flow><calcite-flow-item .selected=${!this._showTemplates}><div class="container">${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;
    }}><arcgis-print-template-selector .messages=${this.messages} .viewModel=${this.viewModel} .hideTemplateSelector=${this._hideTemplateSelector.bind(this)} .excludeOrganizationTemplates=${this.excludeOrganizationTemplates}><slot name=browse-template-button></slot></arcgis-print-template-selector></calcite-flow-item></calcite-flow>`;
  }
  _renderPanelHeader() {
    return this.hideHeader ? null : r`<header class="header-title">${this.messages.export}</header>`;
  }
  _renderPanelContent() {
    const e = this.viewModel.view, t = e?.type !== "2d";
    return !!this.error || t ? r`<div class="panel-error">${e ? t ? this.messages.sceneViewError : this.messages.serviceError : this.messages.noViewError}</div>` : r`<arcgis-print-main-panel .messages=${this.messages} .viewModel=${this.viewModel} .showTemplateSelector=${this._showTemplateSelector.bind(this)} .hideAdvancedOptions=${this.hideAdvancedOptions} .hideFeatureAttributes=${this.hideFeatureAttributes} .hideIncludeTables=${this.hideIncludeTables} .allowedFormatsForSaving=${this.allowedFormatsForSaving} .autoPopulateAuthor=${this.autoPopulateAuthor} .showSaveAs=${this.showSaveAs} .arcgisSaveAs=${this.arcgisSaveAs}></arcgis-print-main-panel>`;
  }
}
c("arcgis-print", x);
export {
  x as ArcgisPrint
};
