import { createVNode as n, ref as v, watch as w, defineComponent as L, toRefs as y } from "vue";
const k = {
  data: {
    type: Array,
    required: !0,
    default: () => []
  }
}, $ = (t) => n("svg", {
  width: "16px",
  height: "16px",
  viewBox: "0 0 16 16",
  version: "1.1",
  xmlns: "http://www.w3.org/2000/svg",
  class: ["svg-icon svg-icon-close", t.class]
}, [n("g", {
  "stroke-width": "1",
  fill: "none",
  "fill-rule": "evenodd"
}, [n("rect", {
  x: "0.5",
  y: "0.5",
  width: "15",
  height: "15",
  rx: "2",
  stroke: "#5e7ce0"
}, null), n("rect", {
  x: "4",
  y: "7",
  width: "8",
  height: "2",
  fill: "#5e7ce0"
}, null)])]), b = () => n("svg", {
  width: "16px",
  height: "16px",
  viewBox: "0 0 16 16",
  version: "1.1",
  xmlns: "http://www.w3.org/2000/svg",
  class: "svg-icon"
}, [n("g", {
  stroke: "none",
  "stroke-width": "1",
  fill: "none",
  "fill-rule": "evenodd"
}, [n("rect", {
  x: "0.5",
  y: "0.5",
  width: "15",
  height: "15",
  rx: "2",
  stroke: "#252b3a"
}, null), n("path", {
  fill: "#252b3a",
  d: "M8.75,4 L8.75,7.25 L12,7.25 L12,8.75 L8.749,8.75 L8.75,12 L7.25,12 L7.249,8.75 L4,8.75 L4,7.25 L7.25,7.25 L7.25,4 L8.75,4 Z"
}, null)])]);
function C(t) {
  const e = (r) => r.reduce(
    (l, a) => a.open ? l.concat(a, a.children ? e(a.children) : []) : l.concat(a),
    []
  ), o = v(e(t.value));
  return w(
    () => t.value,
    (r) => o.value = e(r),
    { deep: !0 }
  ), {
    openedData: o,
    toggle: (r, l) => {
      r.stopPropagation(), l.children && (l.open = !l.open, o.value = e(t.value));
    }
  };
}
const h = "g";
function u(t, e, o) {
  let d = t;
  return e && (d += `__${e}`), o && (d += `--${o}`), d;
}
function m(t, e = !1) {
  const o = e ? `.${h}-${t}` : `${h}-${t}`;
  return {
    b: () => u(o),
    e: (s) => s ? u(o, s) : "",
    m: (s) => s ? u(o, "", s) : "",
    em: (s, p) => s && p ? u(o, s, p) : ""
  };
}
const T = "G", i = /* @__PURE__ */ L({
  name: `${T}Tree`,
  props: k,
  emits: [],
  setup(t) {
    const e = m("tree"), o = v(!1), {
      data: d
    } = y(t), {
      openedData: r,
      toggle: l
    } = C(d), a = () => n("span", {
      style: "display: inline-block; width: 16px; height: 16px;"
    }, null), s = () => {
      o.value = !o.value;
    }, p = (c, x) => {
      const f = c.level ? c.level : 0;
      return n("div", {
        class: [e.e("node"), c.open && e.em("node", "open")],
        style: {
          paddingLeft: `${24 * (f - 1)}px`
        }
      }, [n("div", {
        class: [e.e("node-content")],
        onClick: () => s()
      }, [n("div", {
        class: e.em("node-content", "value-wrapper")
      }, [c.children ? c.open ? n($, {
        class: "mr-xs",
        onClick: (g) => l(g, c)
      }, null) : n(b, {
        class: "mr-xs",
        onClick: (g) => l(g, c)
      }, null) : n(a, null, null), n("span", {
        class: e.e("node-title")
      }, [c.label])])])]);
    };
    return () => n("div", {
      class: e.b()
    }, [r.value.map((c, x) => p(c))]);
  }
});
i.install = function(t, e) {
  t.component(e || i.name, i);
};
const I = {
  title: "Tree 树",
  category: "数据描述",
  status: "100%",
  install(t) {
    t.component(i.name, i);
  }
};
export {
  i as Tree,
  I as default
};
