import { reactive as T, computed as N, toRefs as j, defineComponent as A, resolveComponent as f, openBlock as x, createElementBlock as B, normalizeClass as E, unref as l, createVNode as m, withCtx as y, isRef as k, createBlock as H, createCommentVNode as L } from "vue";
import { u as M, b as V } from "./layer-select-Ba4IEiWY.js";
import { i as W, _ as J } from "./utils-B4smQbM-.js";
import "./vendor-D4icwOYu.js";
import "ant-design-vue";
import "@mapgis/webclient-common";
import { E as G } from "./jspdf-DZ_enIpE.js";
var s = /* @__PURE__ */ ((t) => (t.TIFF = "tiff", t.PNG = "png", t.BMP = "bmp", t.GIF = "gif", t.JPG = "jpg", t.ICO = "ico", t.PDF = "pdf", t))(s || {});
const $ = {
  /**
   * @description 图片格式，支持tiff、bmp、png、gif、jpg、ico、pdf格式
   */
  format: {
    type: String,
    default: "png",
    validator(t) {
      return Object.keys(s).map((h) => s[h]).includes(t);
    }
  },
  /**
   * @description 图片文件名
   */
  filename: {
    type: String,
    default: "screenshotFile"
  },
  /**
   * @description pdf中图片宽度
   */
  width: {
    type: Number,
    default: 1920
  },
  /**
   * @description pdf中图片高度
   */
  height: {
    type: Number,
    default: 1080
  }
}, q = {
  screenshot: (t) => W(t)
}, K = (t, h) => {
  const { zondy: C, viewState: P } = M(), r = T({
    // 图片格式
    format: t.format,
    // 下载文件名
    filename: t.filename,
    // 下载pdf的宽度
    width: t.width,
    // 下载pdf的高度
    height: t.height
  }), _ = Object.keys(s).map((n) => ({
    value: s[n],
    label: s[n]
  })), g = N(() => r.filename), w = N(() => r.format === s.PDF);
  async function b() {
    if (!g.value)
      return;
    const { PictureFormat: n } = C.enum, e = {
      // 默认png格式的图片
      format: n.png,
      // 由于只支持支持png，jpeg格式，默认不下载图片
      isDownload: !1
    }, i = (await P.view.takeScreenshot(e)).dataUrl;
    h("screenshot", i);
    const o = D();
    if (o.includes("image/")) {
      const a = I(i, o), p = URL.createObjectURL(a);
      S(p), URL.revokeObjectURL(p);
    } else o.includes("pdf") && U(i);
  }
  function D() {
    const { format: n } = r;
    let e;
    switch (n) {
      case s.PDF:
        e = "application/pdf";
        break;
      case s.TIFF:
      case s.BMP:
      case s.PNG:
      case s.GIF:
        e = `image/${n}`;
        break;
      case s.JPG:
        e = "image/jpeg";
        break;
      case s.ICO:
        e = "image/x-icon";
        break;
    }
    return e;
  }
  function I(n, e) {
    const c = n.split(","), i = atob(c[1]);
    let o = i.length;
    const a = new Uint8Array(o);
    for (; o--; )
      a[o] = i.charCodeAt(o);
    return new Blob([a], { type: e });
  }
  function S(n) {
    const { filename: e } = r, c = document.createElement("a");
    c.setAttribute("href", n), c.setAttribute("download", e), c.setAttribute("target", "_blank");
    const i = document.createEvent("MouseEvents");
    i.initEvent("click", !0, !0), c.dispatchEvent(i);
  }
  function U(n) {
    const { filename: e, width: c, height: i } = r, o = i / c;
    let a = new G("p", "pt", "a4"), p = a.internal.pageSize.height, d = a.internal.pageSize.width;
    const z = (p - 20) / (d - 20);
    o <= z && (a = new G("l", "pt", "a4"), p = a.internal.pageSize.height, d = a.internal.pageSize.width);
    const u = p - 2 * 10, F = d - 2 * 10, O = u / o;
    if (O < F) {
      const v = (d - O) / 2;
      a.addImage(n, "PNG", v, 10, O, u);
    } else {
      const v = F * o, R = (p - v) / 2;
      a.addImage(n, "PNG", 10, R, F, v);
    }
    a.save(e);
  }
  return { ...j(r), pictureTypeOptions: _, isAllowDownload: g, showPDFConfig: w, handlePictureDownload: b };
}, Q = /* @__PURE__ */ A({
  name: "MapgisScreenshot",
  __name: "screenshot",
  props: $,
  emits: q,
  setup(t, { emit: h }) {
    const C = t, P = h, r = V("screenshot"), { format: _, filename: g, width: w, height: b, pictureTypeOptions: D, isAllowDownload: I, showPDFConfig: S, handlePictureDownload: U } = K(C, P);
    return (n, e) => {
      const c = f("a-input"), i = f("a-select"), o = f("mapgis-ui-icon-identity"), a = f("a-flex"), p = f("mapgis-ui-input-number-panel"), d = f("a-form-item"), z = f("mapgis-ui-setting-form");
      return x(), B("div", {
        class: E([l(r).b()])
      }, [
        m(a, {
          gap: "small",
          align: "center"
        }, {
          default: y(() => [
            m(c, {
              value: l(g),
              "onUpdate:value": e[0] || (e[0] = (u) => k(g) ? g.value = u : null),
              placeholder: "请输入图片名称",
              "allow-clear": ""
            }, null, 8, ["value"]),
            m(i, {
              value: l(_),
              "onUpdate:value": e[1] || (e[1] = (u) => k(_) ? _.value = u : null),
              options: l(D)
            }, null, 8, ["value", "options"]),
            m(o, {
              title: "下载",
              class: E([l(r).e("download"), !l(I) && l(r).em("download", "disabled")]),
              icon: "mapgis-download",
              width: 18,
              height: 18,
              onClick: l(U)
            }, null, 8, ["class", "onClick"])
          ]),
          _: 1
        }),
        l(S) ? (x(), H(z, {
          key: 0,
          layout: "horizontal",
          itemLayout: "grid",
          size: "default",
          class: E(l(r).e("form"))
        }, {
          default: y(() => [
            m(d, { label: "PDF宽度" }, {
              default: y(() => [
                m(p, {
                  value: l(w),
                  "onUpdate:value": e[2] || (e[2] = (u) => k(w) ? w.value = u : null),
                  size: "medium",
                  range: [1, 5e3],
                  rangeShow: !1,
                  step: 1,
                  slider: !0,
                  labelCol: { span: 0 },
                  wrapperCol: { span: 24 }
                }, null, 8, ["value"])
              ]),
              _: 1
            }),
            m(d, { label: "PDF高度" }, {
              default: y(() => [
                m(p, {
                  value: l(b),
                  "onUpdate:value": e[3] || (e[3] = (u) => k(b) ? b.value = u : null),
                  size: "medium",
                  range: [1, 5e3],
                  rangeShow: !1,
                  step: 1,
                  slider: !0,
                  labelCol: { span: 0 },
                  wrapperCol: { span: 24 }
                }, null, 8, ["value"])
              ]),
              _: 1
            })
          ]),
          _: 1
        }, 8, ["class"])) : L("", !0)
      ], 2);
    };
  }
}), oe = /* @__PURE__ */ J(Q, [["__scopeId", "data-v-b5b4d87b"]]);
export {
  oe as S,
  s as a,
  $ as b,
  q as s,
  K as u
};
