import { defineComponent as Q, ref as C, unref as L, openBlock as W, createElementBlock as ee, withDirectives as te, createElementVNode as R, vShow as ne, renderSlot as re } from "vue";
import * as T from "xlsx";
import "lodash-es";
import oe from "dayjs";
import "ant-design-vue";
const ie = "G", se = oe;
for (let e = 0; e <= 15; e++)
  e.toString(16);
/*!
 * is-plain-object <https://github.com/jonschlinkert/is-plain-object>
 *
 * Copyright (c) 2014-2017, Jon Schlinkert.
 * Released under the MIT License.
 */
function V(e) {
  return Object.prototype.toString.call(e) === "[object Object]";
}
function ae(e) {
  var n, t;
  return V(e) === !1 ? !1 : (n = e.constructor, n === void 0 ? !0 : (t = n.prototype, !(V(t) === !1 || t.hasOwnProperty("isPrototypeOf") === !1)));
}
function N() {
  return N = Object.assign ? Object.assign.bind() : function(e) {
    for (var n = 1; n < arguments.length; n++) {
      var t = arguments[n];
      for (var r in t)
        Object.prototype.hasOwnProperty.call(t, r) && (e[r] = t[r]);
    }
    return e;
  }, N.apply(this, arguments);
}
function U(e, n) {
  if (e == null)
    return {};
  var t, r, o = {}, i = Object.keys(e);
  for (r = 0; r < i.length; r++)
    n.indexOf(t = i[r]) >= 0 || (o[t] = e[t]);
  return o;
}
const F = { silent: !1, logLevel: "warn" }, ue = ["validator"], M = Object.prototype, X = M.toString, le = M.hasOwnProperty, Y = /^\s*function (\w+)/;
function q(e) {
  var n;
  const t = (n = e == null ? void 0 : e.type) !== null && n !== void 0 ? n : e;
  if (t) {
    const r = t.toString().match(Y);
    return r ? r[1] : "";
  }
  return "";
}
const b = ae, H = (e) => e;
let f = H;
process.env.NODE_ENV !== "production" && (f = typeof console < "u" ? function(n, t = F.logLevel) {
  F.silent === !1 && console[t](`[VueTypes warn]: ${n}`);
} : H);
const x = (e, n) => le.call(e, n), ce = Number.isInteger || function(e) {
  return typeof e == "number" && isFinite(e) && Math.floor(e) === e;
}, $ = Array.isArray || function(e) {
  return X.call(e) === "[object Array]";
}, w = (e) => X.call(e) === "[object Function]", D = (e) => b(e) && x(e, "_vueTypes_name"), J = (e) => b(e) && (x(e, "type") || ["_vueTypes_name", "validator", "default", "required"].some((n) => x(e, n)));
function A(e, n) {
  return Object.defineProperty(e.bind(n), "__original", { value: e });
}
function O(e, n, t = !1) {
  let r, o = !0, i = "";
  r = b(e) ? e : { type: e };
  const s = D(r) ? r._vueTypes_name + " - " : "";
  if (J(r) && r.type !== null) {
    if (r.type === void 0 || r.type === !0 || !r.required && n === void 0)
      return o;
    $(r.type) ? (o = r.type.some((a) => O(a, n, !0) === !0), i = r.type.map((a) => q(a)).join(" or ")) : (i = q(r), o = i === "Array" ? $(n) : i === "Object" ? b(n) : i === "String" || i === "Number" || i === "Boolean" || i === "Function" ? function(a) {
      if (a == null)
        return "";
      const u = a.constructor.toString().match(Y);
      return u ? u[1] : "";
    }(n) === i : n instanceof r.type);
  }
  if (!o) {
    const a = `${s}value "${n}" should be of type "${i}"`;
    return t === !1 ? (f(a), !1) : a;
  }
  if (x(r, "validator") && w(r.validator)) {
    const a = f, u = [];
    if (f = (c) => {
      u.push(c);
    }, o = r.validator(n), f = a, !o) {
      const c = (u.length > 1 ? "* " : "") + u.join(`
* `);
      return u.length = 0, t === !1 ? (f(c), o) : c;
    }
  }
  return o;
}
function p(e, n) {
  const t = Object.defineProperties(n, { _vueTypes_name: { value: e, writable: !0 }, isRequired: { get() {
    return this.required = !0, this;
  } }, def: { value(o) {
    return o === void 0 ? (x(this, "default") && delete this.default, this) : w(o) || O(this, o, !0) === !0 ? (this.default = $(o) ? () => [...o] : b(o) ? () => Object.assign({}, o) : o, this) : (f(`${this._vueTypes_name} - invalid default value: "${o}"`), this);
  } } }), { validator: r } = t;
  return w(r) && (t.validator = A(r, t)), t;
}
function g(e, n) {
  const t = p(e, n);
  return Object.defineProperty(t, "validate", { value(r) {
    return w(this.validator) && f(`${this._vueTypes_name} - calling .validate() will overwrite the current custom validator function. Validator info:
${JSON.stringify(this)}`), this.validator = A(r, this), this;
  } });
}
function I(e, n, t) {
  const r = function(u) {
    const c = {};
    return Object.getOwnPropertyNames(u).forEach((l) => {
      c[l] = Object.getOwnPropertyDescriptor(u, l);
    }), Object.defineProperties({}, c);
  }(n);
  if (r._vueTypes_name = e, !b(t))
    return r;
  const { validator: o } = t, i = U(t, ue);
  if (w(o)) {
    let { validator: u } = r;
    u && (u = (a = (s = u).__original) !== null && a !== void 0 ? a : s), r.validator = A(u ? function(c) {
      return u.call(this, c) && o.call(this, c);
    } : o, r);
  }
  var s, a;
  return Object.assign(r, i);
}
function P(e) {
  return e.replace(/^(?!\s*$)/gm, "  ");
}
const fe = () => g("any", {}), de = () => g("function", { type: Function }), pe = () => g("boolean", { type: Boolean }), ye = () => g("string", { type: String }), he = () => g("number", { type: Number }), ve = () => g("array", { type: Array }), ge = () => g("object", { type: Object }), me = () => p("integer", { type: Number, validator: (e) => ce(e) }), be = () => p("symbol", { validator: (e) => typeof e == "symbol" });
function Oe(e, n = "custom validation failed") {
  if (typeof e != "function")
    throw new TypeError("[VueTypes error]: You must provide a function as argument");
  return p(e.name || "<<anonymous function>>", { type: null, validator(t) {
    const r = e(t);
    return r || f(`${this._vueTypes_name} - ${n}`), r;
  } });
}
function je(e) {
  if (!$(e))
    throw new TypeError("[VueTypes error]: You must provide an array as argument.");
  const n = `oneOf - value should be one of "${e.join('", "')}".`, t = e.reduce((r, o) => {
    if (o != null) {
      const i = o.constructor;
      r.indexOf(i) === -1 && r.push(i);
    }
    return r;
  }, []);
  return p("oneOf", { type: t.length > 0 ? t : void 0, validator(r) {
    const o = e.indexOf(r) !== -1;
    return o || f(n), o;
  } });
}
function _e(e) {
  if (!$(e))
    throw new TypeError("[VueTypes error]: You must provide an array as argument");
  let n = !1, t = [];
  for (let o = 0; o < e.length; o += 1) {
    const i = e[o];
    if (J(i)) {
      if (D(i) && i._vueTypes_name === "oneOf" && i.type) {
        t = t.concat(i.type);
        continue;
      }
      if (w(i.validator) && (n = !0), i.type === !0 || !i.type) {
        f('oneOfType - invalid usage of "true" or "null" as types.');
        continue;
      }
      t = t.concat(i.type);
    } else
      t.push(i);
  }
  t = t.filter((o, i) => t.indexOf(o) === i);
  const r = t.length > 0 ? t : null;
  return p("oneOfType", n ? { type: r, validator(o) {
    const i = [], s = e.some((a) => {
      const u = O(D(a) && a._vueTypes_name === "oneOf" ? a.type || null : a, o, !0);
      return typeof u == "string" && i.push(u), u === !0;
    });
    return s || f(`oneOfType - provided value does not match any of the ${i.length} passed-in validators:
${P(i.join(`
`))}`), s;
  } } : { type: r });
}
function Te(e) {
  return p("arrayOf", { type: Array, validator(n) {
    let t = "";
    const r = n.every((o) => (t = O(e, o, !0), t === !0));
    return r || f(`arrayOf - value validation error:
${P(t)}`), r;
  } });
}
function xe(e) {
  return p("instanceOf", { type: e });
}
function $e(e) {
  return p("objectOf", { type: Object, validator(n) {
    let t = "";
    const r = Object.keys(n).every((o) => (t = O(e, n[o], !0), t === !0));
    return r || f(`objectOf - value validation error:
${P(t)}`), r;
  } });
}
function we(e) {
  const n = Object.keys(e), t = n.filter((o) => {
    var i;
    return !((i = e[o]) === null || i === void 0 || !i.required);
  }), r = p("shape", { type: Object, validator(o) {
    if (!b(o))
      return !1;
    const i = Object.keys(o);
    if (t.length > 0 && t.some((s) => i.indexOf(s) === -1)) {
      const s = t.filter((a) => i.indexOf(a) === -1);
      return f(s.length === 1 ? `shape - required property "${s[0]}" is not defined.` : `shape - required properties "${s.join('", "')}" are not defined.`), !1;
    }
    return i.every((s) => {
      if (n.indexOf(s) === -1)
        return this._vueTypes_isLoose === !0 || (f(`shape - shape definition does not include a "${s}" property. Allowed keys: "${n.join('", "')}".`), !1);
      const a = O(e[s], o[s], !0);
      return typeof a == "string" && f(`shape - "${s}" property validation error:
 ${P(a)}`), a === !0;
    });
  } });
  return Object.defineProperty(r, "_vueTypes_isLoose", { writable: !0, value: !1 }), Object.defineProperty(r, "loose", { get() {
    return this._vueTypes_isLoose = !0, this;
  } }), r;
}
const ke = ["name", "validate", "getter"], Se = /* @__PURE__ */ (() => {
  var e;
  return (e = class {
    static get any() {
      return fe();
    }
    static get func() {
      return de().def(this.defaults.func);
    }
    static get bool() {
      return pe().def(this.defaults.bool);
    }
    static get string() {
      return ye().def(this.defaults.string);
    }
    static get number() {
      return he().def(this.defaults.number);
    }
    static get array() {
      return ve().def(this.defaults.array);
    }
    static get object() {
      return ge().def(this.defaults.object);
    }
    static get integer() {
      return me().def(this.defaults.integer);
    }
    static get symbol() {
      return be();
    }
    static get nullable() {
      return { type: null };
    }
    static extend(n) {
      if ($(n))
        return n.forEach((u) => this.extend(u)), this;
      const { name: t, validate: r = !1, getter: o = !1 } = n, i = U(n, ke);
      if (x(this, t))
        throw new TypeError(`[VueTypes error]: Type "${t}" already defined`);
      const { type: s } = i;
      if (D(s))
        return delete i.type, Object.defineProperty(this, t, o ? { get: () => I(t, s, i) } : { value(...u) {
          const c = I(t, s, i);
          return c.validator && (c.validator = c.validator.bind(c, ...u)), c;
        } });
      let a;
      return a = o ? { get() {
        const u = Object.assign({}, i);
        return r ? g(t, u) : p(t, u);
      }, enumerable: !0 } : { value(...u) {
        const c = Object.assign({}, i);
        let l;
        return l = r ? g(t, c) : p(t, c), c.validator && (l.validator = c.validator.bind(l, ...u)), l;
      }, enumerable: !0 }, Object.defineProperty(this, t, a);
    }
  }).defaults = {}, e.sensibleDefaults = void 0, e.config = F, e.custom = Oe, e.oneOf = je, e.instanceOf = xe, e.oneOfType = _e, e.arrayOf = Te, e.objectOf = $e, e.shape = we, e.utils = { validate: (n, t) => O(t, n, !0) === !0, toType: (n, t, r = !1) => r ? g(n, t) : p(n, t) }, e;
})();
function Z(e = { func: () => {
}, bool: !0, string: "", number: 0, array: () => [], object: () => ({}), integer: 0 }) {
  var n;
  return (n = class extends Se {
    static get sensibleDefaults() {
      return N({}, this.defaults);
    }
    static set sensibleDefaults(t) {
      this.defaults = t !== !1 ? N({}, t !== !0 ? t : e) : {};
    }
  }).defaults = N({}, e), n;
}
class Ve extends Z() {
}
const Ne = Z({
  func: void 0,
  bool: void 0,
  string: void 0,
  number: void 0,
  object: void 0,
  integer: void 0
});
Ne.extend([
  {
    name: "style",
    getter: !0,
    type: [String, Object],
    default: void 0
  },
  {
    name: "VNodeChild",
    getter: !0,
    type: void 0
  }
]);
const Ee = Q({
  name: `${ie}ImportExcel`,
  components: {},
  props: {
    // 日期时间格式。如果不提供或者提供空值，将返回原始Date对象
    dateFormat: {
      type: String
    },
    // 时区调整。实验性功能，仅为了解决读取日期时间值有偏差的问题。目前仅提供了+08:00时区的偏差修正值
    // https://github.com/SheetJS/sheetjs/issues/1470#issuecomment-501108554
    timeZone: {
      type: Number,
      default: 8
    }
  },
  emits: ["success", "error"],
  setup(e, { emit: n }) {
    const t = C(null), r = C(!1);
    function o(l) {
      if (!l || !l["!ref"])
        return [];
      const d = [], y = T.utils.decode_range(l["!ref"]), j = y.s.r;
      for (let h = y.s.c; h <= y.e.c; ++h) {
        const v = l[T.utils.encode_cell({ c: h, r: j })];
        let _ = "UNKNOWN " + h;
        v && v.t && (_ = T.utils.format_cell(v)), d.push(_);
      }
      return d;
    }
    function i(l) {
      const d = [], { dateFormat: y, timeZone: j } = e;
      for (const h of l.SheetNames) {
        const v = l.Sheets[h], _ = o(v);
        let k = T.utils.sheet_to_json(v, {
          raw: !0,
          dateNF: y
          //Not worked
        });
        k = k.map((m) => {
          for (let S in m)
            m[S] instanceof Date && (j === 8 && m[S].setSeconds(m[S].getSeconds() + 43), y && (m[S] = se(m[S]).format(y)));
          return m;
        }), d.push({
          header: _,
          results: k,
          meta: {
            sheetName: h
          }
        });
      }
      return d;
    }
    function s(l) {
      return r.value = !0, new Promise((d, y) => {
        const j = new FileReader();
        j.onload = async (h) => {
          try {
            const v = h.target && h.target.result, _ = T.read(v, {
              type: "array",
              cellDates: !0
            }), k = i(_);
            n("success", k), d("");
          } catch (v) {
            y(v), n("error");
          } finally {
            r.value = !1;
          }
        }, j.readAsArrayBuffer(l);
      });
    }
    async function a(l) {
      const d = L(t);
      d && (d.value = ""), await s(l);
    }
    function u(l) {
      const d = l && l.target.files, y = d && d[0];
      y && a(y);
    }
    function c() {
      const l = L(t);
      l && l.click();
    }
    return { handleUpload: c, handleInputClick: u, inputRef: t };
  }
}), De = (e, n) => {
  const t = e.__vccOpts || e;
  for (const [r, o] of n)
    t[r] = o;
  return t;
};
function Pe(e, n, t, r, o, i) {
  return W(), ee("div", null, [
    te(R("input", {
      ref: "inputRef",
      type: "file",
      accept: ".xlsx, .xls",
      onChange: n[0] || (n[0] = (...s) => e.handleInputClick && e.handleInputClick(...s))
    }, null, 544), [
      [ne, !1]
    ]),
    R("div", {
      onClick: n[1] || (n[1] = (...s) => e.handleUpload && e.handleUpload(...s))
    }, [
      re(e.$slots, "default")
    ])
  ]);
}
const E = /* @__PURE__ */ De(Ee, [["render", Pe]]), { utils: z, writeFile: G } = T, K = "excel-list.xlsx";
function qe({
  data: e,
  header: n,
  filename: t = K,
  json2sheetOpts: r = {},
  write2excelOpts: o = { bookType: "xlsx" }
}) {
  const i = [...e];
  n && (i.unshift(n), r.skipHeader = !0);
  const s = z.json_to_sheet(i, r), a = {
    SheetNames: [t],
    Sheets: {
      [t]: s
    }
  };
  G(a, t, o);
}
function B(e) {
  if ([null, void 0].includes(e))
    return 20;
  if (/.*[\u4e00-\u9fa5]+.*$/.test(e)) {
    const n = e.match(/[\u4e00-\u9fa5]/g).length, t = e.length - n;
    return n * 2.1 + t * 1.1;
  } else
    return e.toString().length * 1.1;
}
const Fe = (e, n, t, r = !0) => {
  if (r) {
    const o = [], i = n;
    e.forEach((s) => {
      var u, c;
      let a = 0;
      for (const l in s) {
        switch (o[a] == null && (o[a] = []), typeof s[l]) {
          case "string":
          case "number":
          case "boolean":
            (u = o[a]) == null || u.push(B(s[l]));
            break;
          case "object":
          case "function":
            (c = o[a]) == null || c.push(0);
            break;
        }
        a++;
      }
    }), t["!cols"] = [], o.forEach((s, a) => {
      s == null || s.push(B(i[a])), t["!cols"].push({ wch: Math.max(...s) });
    });
  }
};
function Ie({
  data: e,
  header: n,
  filename: t = K,
  write2excelOpts: r = { bookType: "xlsx" }
}) {
  const o = [...e];
  n && o.unshift(n);
  const i = z.aoa_to_sheet(o);
  Fe(e, n, i, !0);
  const s = {
    SheetNames: [t],
    Sheets: {
      [t]: i
    }
  };
  G(s, t, r);
}
E.install = function(e, n) {
  e.component(n || E.name, E);
};
const Be = {
  title: "Excel 导入导出",
  category: "高级组件",
  status: "100%",
  install(e) {
    e.component(E.name, E);
  }
};
export {
  E as ImportExcel,
  Ie as aoaToSheetXlsx,
  Be as default,
  qe as jsonToSheetXlsx
};
