import { defineComponent as O, ref as w, unref as n, computed as $, watch as q, openBlock as u, createElementBlock as y, normalizeClass as c, createVNode as m, withCtx as v, createElementVNode as g, toDisplayString as k, createTextVNode as G, createBlock as b, createCommentVNode as p } from "vue";
import { Flex as H, Typography as J, Divider as K } from "@aplus-frontend/antdv";
import N from "vuedraggable";
import { useInjectApTable as P } from "../../../context.mjs";
import "../../../../config-provider/index.mjs";
import "../sortable/index.vue.mjs";
import { useProvideSorterMethods as Q } from "./context.mjs";
import { useNamespace as W } from "../../../../config-provider/hooks/use-namespace.mjs";
import { useLocale as X } from "../../../../config-provider/hooks/use-locale.mjs";
import R from "../sortable/index.vue2.mjs";
const Y = { key: 0 }, Z = { key: 1 }, ee = { key: 2 }, de = /* @__PURE__ */ O({
  __name: "index",
  props: {
    value: {},
    onReset: { type: Function }
  },
  emits: ["update:value"],
  setup(V, { emit: B }) {
    const l = w([]), i = w([]), s = w([]), { b: r } = W("ap-column-setting-sorter"), { t: h } = X(), x = V, I = B, { columnsBackup: S } = P();
    Q({
      fixedToLeft: M,
      fixedToRight: U,
      unFixed: j
    });
    function F(e, t) {
      const o = t[0].findIndex(
        (a) => a.key === e.key
      );
      if (~o)
        t[0].splice(o, 1);
      else {
        const a = t[1].findIndex(
          (d) => d.key === e.key
        );
        t[1].splice(a, 1);
      }
    }
    function _(e, t) {
      const o = [...n(l.value)], a = [...n(s.value)], d = [...n(i.value)], L = {
        left: {
          target: o,
          search: [d, a]
        },
        right: {
          target: a,
          search: [d, o]
        },
        normal: {
          target: d,
          search: [o, a]
        }
      }[t];
      return t === "right" ? L.target.unshift(e) : L.target.push(e), F(
        e,
        L.search
      ), [...o, ...d, ...a];
    }
    function M(e) {
      const t = _(e, "left");
      f(t);
    }
    function U(e) {
      const t = _(e, "right");
      f(t);
    }
    function j(e) {
      const t = _(e, "normal");
      f(t);
    }
    function C(e) {
      return S?.value.find((t) => e.key === t.key) ? e.children?.length ? e.children.some((t) => t.show) : e.show : !1;
    }
    function T(e, t) {
      e.value ? e.value.push(t) : e.value = [t];
    }
    const A = $(() => {
      let e = 0;
      function t(o) {
        for (const a of o)
          a.children?.length ? t(a.children) : a.show && (e += 1);
      }
      return t(x.value), e;
    });
    function D(e) {
      f([...e, ...n(i), ...n(s)]);
    }
    function E(e) {
      f([...n(l), ...e, ...n(s)]);
    }
    function z(e) {
      f([...n(l), ...n(i), ...e]);
    }
    function f(e) {
      I("update:value", e);
    }
    return q(
      () => x.value,
      (e) => {
        if (e) {
          l.value = [], i.value = [], s.value = [];
          for (const t of e)
            t.fixed === "left" ? T(l, t) : t.fixed === "right" ? T(s, t) : T(i, t);
        }
      },
      { immediate: !0 }
    ), (e, t) => (u(), y("div", {
      class: c(n(r)())
    }, [
      m(n(H), {
        class: c(n(r)("header")),
        align: "center",
        justify: "space-between"
      }, {
        default: v(() => [
          g("span", {
            class: c(n(r)("header-title")),
            style: { flex: "1" }
          }, k(n(h)("ap.apTable.setting.selectCount", { count: A.value })), 3),
          m(n(J).Link, {
            onClick: x.onReset
          }, {
            default: v(() => [
              G(k(n(h)("ap.apTable.setting.reset")), 1)
            ]),
            _: 1
          }, 8, ["onClick"])
        ]),
        _: 1
      }, 8, ["class"]),
      m(n(K), { style: { margin: "0px" } }),
      g("div", {
        class: c(n(r)("content"))
      }, [
        l.value.length ? (u(), y("div", Y, [
          g("span", {
            class: c(n(r)("section-title"))
          }, k(n(h)("ap.apTable.setting.fixToLeft")), 3),
          m(n(N), {
            "model-value": l.value,
            "item-key": "key",
            "onUpdate:modelValue": D
          }, {
            item: v(({ element: o }) => [
              C(o) ? (u(), b(R, {
                key: 0,
                value: o
              }, null, 8, ["value"])) : p("", !0)
            ]),
            _: 1
          }, 8, ["model-value"])
        ])) : p("", !0),
        i.value.length ? (u(), y("div", Z, [
          g("span", {
            class: c(n(r)("section-title"))
          }, k(n(h)("ap.apTable.setting.unFixed")), 3),
          m(n(N), {
            "model-value": i.value,
            "item-key": "key",
            "onUpdate:modelValue": E
          }, {
            item: v(({ element: o }) => [
              C(o) ? (u(), b(R, {
                key: 0,
                value: o
              }, null, 8, ["value"])) : p("", !0)
            ]),
            _: 1
          }, 8, ["model-value"])
        ])) : p("", !0),
        s.value.length ? (u(), y("div", ee, [
          g("span", {
            class: c(n(r)("section-title"))
          }, k(n(h)("ap.apTable.setting.fixToRight")), 3),
          m(n(N), {
            "model-value": s.value,
            "item-key": "key",
            "onUpdate:modelValue": z
          }, {
            item: v(({ element: o }) => [
              C(o) ? (u(), b(R, {
                key: 0,
                value: o
              }, null, 8, ["value"])) : p("", !0)
            ]),
            _: 1
          }, 8, ["model-value"])
        ])) : p("", !0)
      ], 2)
    ], 2));
  }
});
export {
  de as default
};
