import { defineComponent as T, ref as V, watch as $, openBlock as m, createElementBlock as c, normalizeClass as C, unref as e, createElementVNode as a, toDisplayString as r, createVNode as n, createCommentVNode as f, withModifiers as d, withCtx as v } from "vue";
import { Space as x, Popconfirm as B } from "@aplus-frontend/antdv";
import { ApField as F } from "../../../ap-field/index.mjs";
import "../../../ap-form/ap-form.vue.mjs";
import "../../../config-provider/index.mjs";
import { useToken as L } from "../../../config-provider/hooks/use-token.mjs";
import "../../ap-tag/index.mjs";
import { useViewInject as M } from "../hooks/use-view-provide.mjs";
import P from "../icons/line-delete.vue.mjs";
import Y from "../style/index.mjs";
import { SYSTEM_VIEW_KEY as K } from "../utils/enum.mjs";
import { useNamespace as j } from "../../../config-provider/hooks/use-namespace.mjs";
import { useLocale as A } from "../../../config-provider/hooks/use-locale.mjs";
import O from "../../ap-tag/ap-tag.vue.mjs";
import N from "../../../ap-form/ap-form.vue2.mjs";
const U = { class: "menu-list-content-name" }, W = ["title"], q = {
  key: 0,
  class: "menu-list-content-default"
}, G = { class: "menu-list-content-action-delete" }, H = { class: "menu-list-content-edit" }, ve = /* @__PURE__ */ T({
  __name: "menu-list-content",
  props: {
    view: {}
  },
  setup(h) {
    const { b: l } = j("ap-view"), y = Y("ap-view"), { token: D } = L(), { t: o } = A(), t = h, {
      currentViewKey: S,
      changeCurrentViewKey: b,
      viewListCRUD: p,
      tableKey: w,
      menuOpen: k
    } = M(), s = V(!1), _ = V(), g = () => {
      b(t.view.viewKey), k.value = !1;
    }, E = () => {
      p?.changeView?.({
        ...t.view,
        tableKey: w.value,
        isDefault: !0
      });
    }, z = () => {
      p?.removeView?.({
        tableKey: w.value,
        viewKey: t.view.viewKey
      });
    }, I = async () => {
      const u = await _.value?.validate?.();
      p?.changeView?.({
        ...t.view,
        tableKey: w.value,
        viewName: u?.viewName || t.view.viewName
      }), s.value = !1;
    };
    return $(
      () => k.value,
      (u) => {
        u && (s.value = !1);
      }
    ), (u, i) => s.value === !1 ? (m(), c("div", {
      key: 0,
      class: C({
        [e(l)()]: !0,
        [e(l)("menu-list-content")]: !0,
        [e(l)("menu-list-content-active")]: t.view?.viewKey === e(S),
        [e(y)]: !0
      }),
      onClick: g
    }, [
      a("div", U, [
        a("span", {
          title: t.view?.viewName
        }, r(t.view?.viewName), 9, W)
      ]),
      t.view?.viewKey !== e(K) && t.view?.isDefault ? (m(), c("div", q, [
        n(e(O), {
          text: e(o)("ap.apView.default"),
          size: "small",
          color: e(D).colorPrimary
        }, null, 8, ["text", "color"])
      ])) : f("", !0),
      t.view?.viewKey !== e(K) ? (m(), c("div", {
        key: 1,
        class: "menu-list-content-action",
        onClick: i[1] || (i[1] = d(() => {
        }, ["stop"]))
      }, [
        n(e(x), { size: 8 }, {
          default: v(() => [
            a("div", {
              class: "menu-list-content-action-text",
              onClick: i[0] || (i[0] = d((R) => s.value = !0, ["stop"]))
            }, r(e(o)("ap.apView.rename")), 1),
            t.view?.isDefault ? f("", !0) : (m(), c("div", {
              key: 0,
              class: "menu-list-content-action-text",
              onClick: E
            }, r(e(o)("ap.apView.setDefault")), 1)),
            a("div", G, [
              n(e(B), {
                title: e(o)("ap.apView.deleteTip"),
                "ok-text": e(o)("ap.apView.ok"),
                onConfirm: z
              }, {
                default: v(() => [
                  n(P)
                ]),
                _: 1
              }, 8, ["title", "ok-text"])
            ])
          ]),
          _: 1
        })
      ])) : f("", !0)
    ], 2)) : (m(), c("div", {
      key: 1,
      class: C([e(l)("menu-list-content"), e(l)("menu-list-content-edit"), e(y)]),
      onClick: i[3] || (i[3] = d(() => {
      }, ["stop"]))
    }, [
      n(N, {
        ref_key: "formRef",
        ref: _,
        "initial-values": {
          viewName: t.view?.viewName
        }
      }, {
        default: v(() => [
          a("div", H, [
            n(e(x), { size: 8 }, {
              default: v(() => [
                n(N.FormItem, { name: "viewName" }, {
                  default: v(() => [
                    n(e(F).Text, { maxlength: 20 })
                  ]),
                  _: 1
                }),
                a("div", {
                  class: "menu-list-content-action-text",
                  onClick: I
                }, r(e(o)("ap.apView.save")), 1),
                a("div", {
                  class: "menu-list-content-action-text",
                  onClick: i[2] || (i[2] = (R) => s.value = !1)
                }, r(e(o)("ap.apView.cancel")), 1)
              ]),
              _: 1
            })
          ])
        ]),
        _: 1
      }, 8, ["initial-values"])
    ], 2));
  }
});
export {
  ve as default
};
