/* COPYRIGHT Esri - https://js.arcgis.com/1.2/LICENSE.txt */
import { c as customElement } from "../../chunks/runtime.js";
import { css, html } from "lit";
import { d as downloadCSV, a as downloadPDF } from "../../chunks/downloadUtils.js";
import { u as useT9n } from "../../chunks/useT9n.js";
import { createRef, ref } from "lit-html/directives/ref.js";
import { LitElement } from "@arcgis/lumina";
const labelFormats = [
  {
    descriptionPDF: {
      labelWidthDisplay: "2-5/8",
      labelHeightDisplay: "1",
      labelsPerPageDisplay: "30",
      averyPartNumber: "*60"
    },
    labelSpec: {
      type: "AVERY",
      pageProperties: {
        pageType: "ANSI A",
        leftMargin: 0.1875,
        rightMargin: 0.1875,
        topMargin: 0.5,
        bottomMargin: 0.5
      },
      numLabelsAcross: 3,
      numLabelsDown: 10,
      labelWidth: 2.625,
      labelHeight: 1,
      horizGapIn: 0.125,
      vertGapIn: 0,
      labelPadding: 0.1,
      fontSizePx: 11,
      maxNumLabelLines: 4
    }
  },
  {
    descriptionPDF: {
      labelWidthDisplay: "4",
      labelHeightDisplay: "1",
      labelsPerPageDisplay: "20",
      averyPartNumber: "*61"
    },
    labelSpec: {
      type: "AVERY",
      pageProperties: {
        pageType: "ANSI A",
        leftMargin: 0.15625,
        rightMargin: 0.15625,
        topMargin: 0.47637821,
        bottomMargin: 0.5
      },
      numLabelsAcross: 2,
      numLabelsDown: 10,
      labelWidth: 4,
      labelHeight: 1.0025,
      horizGapIn: 0.1875,
      vertGapIn: 0,
      labelPadding: 0.1,
      fontSizePx: 11,
      maxNumLabelLines: 4
    }
  },
  {
    descriptionPDF: {
      labelWidthDisplay: "4",
      labelHeightDisplay: "1-1/3",
      labelsPerPageDisplay: "14",
      averyPartNumber: "*62"
    },
    labelSpec: {
      type: "AVERY",
      pageProperties: {
        pageType: "ANSI A",
        leftMargin: 0.15625,
        rightMargin: 0.15625,
        topMargin: 0.81889808,
        bottomMargin: 0.83464612
      },
      numLabelsAcross: 2,
      numLabelsDown: 7,
      labelWidth: 4,
      labelHeight: 1.3352,
      horizGapIn: 0.1875,
      vertGapIn: 0,
      labelPadding: 0.1,
      fontSizePx: 11,
      maxNumLabelLines: 6
    }
  },
  {
    descriptionPDF: {
      labelWidthDisplay: "4",
      labelHeightDisplay: "2",
      labelsPerPageDisplay: "10",
      averyPartNumber: "*63"
    },
    labelSpec: {
      type: "AVERY",
      pageProperties: {
        pageType: "ANSI A",
        leftMargin: 0.15625,
        rightMargin: 0.15625,
        topMargin: 0.5,
        bottomMargin: 0.5
      },
      numLabelsAcross: 2,
      numLabelsDown: 5,
      labelWidth: 4,
      labelHeight: 2,
      horizGapIn: 0.1875,
      vertGapIn: 0,
      labelPadding: 0.1,
      fontSizePx: 12,
      maxNumLabelLines: 10
    }
  },
  {
    descriptionPDF: {
      labelWidthDisplay: "4",
      labelHeightDisplay: "3-1/3",
      labelsPerPageDisplay: "6",
      averyPartNumber: "*64"
    },
    labelSpec: {
      type: "AVERY",
      pageProperties: {
        pageType: "ANSI A",
        leftMargin: 0.15625,
        rightMargin: 0.15625,
        topMargin: 0.4724412,
        bottomMargin: 0.50000027
      },
      numLabelsAcross: 2,
      numLabelsDown: 3,
      labelWidth: 4,
      labelHeight: 3.342,
      horizGapIn: 0.1875,
      vertGapIn: 0,
      labelPadding: 0.1,
      fontSizePx: 14,
      maxNumLabelLines: 12
    }
  },
  {
    descriptionPDF: {
      labelWidthDisplay: "1-3/4",
      labelHeightDisplay: "1/2",
      labelsPerPageDisplay: "80",
      averyPartNumber: "*67"
    },
    labelSpec: {
      type: "AVERY",
      pageProperties: {
        pageType: "ANSI A",
        leftMargin: 0.307086375,
        rightMargin: 0.307086375,
        topMargin: 0.4724412,
        bottomMargin: 0.49606326
      },
      numLabelsAcross: 4,
      numLabelsDown: 20,
      labelWidth: 1.75,
      labelHeight: 0.50155,
      horizGapIn: 0.29527575,
      vertGapIn: 0,
      labelPadding: 0.1,
      fontSizePx: 8,
      maxNumLabelLines: 3
    }
  },
  {
    descriptionPDF: {
      labelWidthDisplay: "1-3/4",
      labelHeightDisplay: "2/3",
      labelsPerPageDisplay: "60",
      averyPartNumber: "*95"
    },
    labelSpec: {
      type: "AVERY",
      pageProperties: {
        pageType: "ANSI A",
        leftMargin: 0.28936983,
        rightMargin: 0.28936983,
        topMargin: 0.53937037,
        bottomMargin: 0.5511814
      },
      numLabelsAcross: 4,
      numLabelsDown: 15,
      labelWidth: 1.75,
      labelHeight: 0.6605,
      horizGapIn: 0.30708678,
      vertGapIn: 0,
      labelPadding: 0.1,
      fontSizePx: 8,
      maxNumLabelLines: 4
    }
  }
];
const pdfLabelFormats = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  default: labelFormats
}, Symbol.toStringTag, { value: "Module" }));
const styles = css`/** @license
 * Copyright 2025 Esri
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

:host {
  display: block;
}`;
class PdfDownload extends LitElement {
  constructor() {
    super(...arguments);
    this.disabled = false;
    this._translations = useT9n({ name: "pdf-download", blocking: true });
    this._labelInfoElement = createRef();
  }
  static {
    this.properties = { defaultNumLabelsPerPage: [9, {}, { type: Number }], disabled: [5, {}, { type: Boolean }], _translations: [16, {}, { state: true }] };
  }
  static {
    this.styles = styles;
  }
  async downloadCSV(webmap, exportInfos, removeDuplicates, addColumnTitle = true) {
    return downloadCSV(
      webmap,
      exportInfos,
      true,
      // formatUsingLayerPopup
      removeDuplicates,
      addColumnTitle
    );
  }
  async downloadPDF(webmap, exportInfos, removeDuplicates = false, title = "", initialImageDataUrl = "") {
    const label = this._labelInfoElement.value ? this._labelInfoElement.value.selectedOption?.value : "";
    return downloadPDF(webmap, exportInfos, label, removeDuplicates, title, initialImageDataUrl);
  }
  render() {
    return html`<calcite-select .disabled=${this.disabled} label ${ref(this._labelInfoElement)}>${this._renderOptions()}</calcite-select>`;
  }
  _getLabelSizeText(labelInfo) {
    const lNum = labelInfo.descriptionPDF.labelsPerPageDisplay;
    const lSize = labelInfo.descriptionPDF.labelWidthDisplay + " x " + labelInfo.descriptionPDF.labelHeightDisplay;
    return this._translations.pdfLabel ? this._translations.pdfLabel.replace("{{n}}", lNum).replace("{{labelSize}}", lSize) : "";
  }
  _renderOptions() {
    const s = pdfLabelFormats;
    const sortedPdfIndo = (s.default || s).sort((a, b) => {
      const _a = Number.parseInt(a.descriptionPDF.labelsPerPageDisplay, 10);
      const _b = Number.parseInt(b.descriptionPDF.labelsPerPageDisplay, 10);
      return _a < _b ? -1 : _a > _b ? 1 : 0;
    });
    return sortedPdfIndo.map((l, i) => {
      let selected = false;
      if (this.defaultNumLabelsPerPage ? Number.parseInt(l.descriptionPDF.labelsPerPageDisplay, 10) === this.defaultNumLabelsPerPage : i === 0) {
        selected = true;
      }
      return html`<calcite-option .selected=${selected} .value=${l}>${this._getLabelSizeText(l)}</calcite-option>`;
    });
  }
}
customElement("pdf-download", PdfDownload);
export {
  PdfDownload
};
