import { d as v } from "./index-D-hoanpz.js";
import { resolveComponent as n, resolveDirective as S, createElementBlock as c, openBlock as r, withDirectives as k, createVNode as s, withCtx as a, createTextVNode as i, toDisplayString as p, createElementVNode as h, normalizeClass as D, Fragment as y, renderList as L, withModifiers as P } from "vue";
import { _ as H } from "./install-BuMO14Rb.js";
const U = {
  name: "WtTableColumnSelect",
  model: {
    prop: "headers",
    event: "change"
  },
  /**
   * @emits {Array} change - Fires when headers are changed. Emits mutated headers
   */
  props: {
    /**
     * Each header should have following schema: { value: String, show: Boolean, text: String }
     * @type {Array}
     * @required
     * @model headers
     */
    headers: {
      type: Array,
      required: !0,
      description: "Each header should have following schema: { value: String, show: Boolean, text: String }"
    },
    /**
     * Header values to exclude from selection
     * @type {Array}
     * @default []
     */
    staticHeaders: {
      type: Array,
      default: () => [],
      description: "Header values to exclude from selection"
    }
  },
  emits: [
    "change"
  ],
  data: () => ({
    draft: [],
    // headers draft
    search: "",
    isColumnSelectPopup: !1
  }),
  computed: {
    changeableDraft() {
      return this.draft.filter(
        (e) => !this.staticHeaders.includes(e.value) && this.shownColLabel(e)?.toLowerCase().includes(this.search?.toLowerCase())
      ).sort((e, t) => this.shownColLabel(e)?.localeCompare(this.shownColLabel(t)));
    }
  },
  watch: {
    isColumnSelectPopup: {
      handler() {
        this.fillHeadersDraft();
      }
    }
  },
  methods: {
    shownColLabel({ text: e, locale: t }) {
      return !e && t ? typeof t == "string" ? this.$t(t) : this.$t(...t) : e;
    },
    openPopup() {
      this.isColumnSelectPopup = !0;
    },
    close() {
      this.isColumnSelectPopup = !1;
    },
    fillHeadersDraft() {
      this.draft = v(this.headers);
    },
    setShownColumns() {
      this.$emit("change", this.draft), this.close();
    }
  }
}, x = { class: "wt-table-column-select" }, V = { class: "wt-table-column-select__popup-list-wrap" }, B = ["onClickCapture"];
function E(e, t, I, N, T, l) {
  const m = n("wt-icon-btn"), _ = n("wt-icon"), w = n("wt-input-text"), f = n("wt-checkbox"), u = n("wt-button"), C = n("wt-popup"), b = S("tooltip");
  return r(), c("div", x, [
    k(s(m, {
      icon: "column-select",
      onClick: l.openPopup
    }, null, 8, ["onClick"]), [
      [b, e.$t("webitelUI.tableColumnSelect.title")]
    ]),
    s(C, {
      shown: e.isColumnSelectPopup,
      class: "wt-table-column-select__popup",
      onClose: l.close
    }, {
      title: a(() => [
        i(p(e.$t("webitelUI.tableColumnSelect.title")), 1)
      ]),
      main: a(() => [
        s(w, {
          class: "wt-table-column-select__popup-search",
          "model-value": e.search,
          "onUpdate:modelValue": t[0] || (t[0] = (o) => e.search = o)
        }, {
          prefix: a(() => [
            s(_, { icon: "search" })
          ]),
          _: 1
        }, 8, ["model-value"]),
        h("div", V, [
          h("ul", {
            class: D([{
              "wt-table-column-select__popup-list--md": l.changeableDraft.length > 10 && l.changeableDraft.length <= 20,
              "wt-table-column-select__popup-list--lg": l.changeableDraft.length > 20
            }, "wt-table-column-select__popup-list"])
          }, [
            (r(!0), c(y, null, L(l.changeableDraft, (o, g) => (r(), c("li", {
              key: g,
              class: "wt-table-column-select__popup-item",
              onClickCapture: P((d) => o.show = !o.show, ["prevent"])
            }, [
              s(f, {
                label: l.shownColLabel(o),
                selected: o.show,
                "onUpdate:selected": (d) => o.show = d
              }, null, 8, ["label", "selected", "onUpdate:selected"])
            ], 40, B))), 128))
          ], 2)
        ])
      ]),
      actions: a(() => [
        s(u, { onClick: l.setShownColumns }, {
          default: a(() => [
            i(p(e.$t("reusable.add")), 1)
          ], void 0, !0),
          _: 1
        }, 8, ["onClick"]),
        s(u, {
          color: "secondary",
          onClick: l.close
        }, {
          default: a(() => [
            i(p(e.$t("reusable.cancel")), 1)
          ], void 0, !0),
          _: 1
        }, 8, ["onClick"])
      ]),
      _: 1
    }, 8, ["shown", "onClose"])
  ]);
}
const z = /* @__PURE__ */ H(U, [["render", E], ["__scopeId", "data-v-1a2815ed"]]);
export {
  z as default
};
