"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const Vue = require("vue");
const index$2 = require("../icon/index.js");
const index$1 = require("../sidebar/index.js");
const index = require("../sidebar-item/index.js");
const props = require("../utils/props.js");
const create = require("../utils/create.js");
const format = require("../utils/format.js");
const [name, bem] = create.createNamespace("tree-select");
const treeSelectProps = {
  max: props.makeNumericProp(Infinity),
  items: props.makeArrayProp(),
  height: props.makeNumericProp(300),
  selectedIcon: props.makeStringProp("success"),
  mainActiveIndex: props.makeNumericProp(0),
  activeId: {
    type: [Number, String, Array],
    default: 0
  }
};
var stdin_default = Vue.defineComponent({
  name,
  props: treeSelectProps,
  emits: ["clickNav", "clickItem", "update:activeId", "update:mainActiveIndex"],
  setup(props2, {
    emit,
    slots
  }) {
    const isActiveItem = (id) => Array.isArray(props2.activeId) ? props2.activeId.includes(id) : props2.activeId === id;
    const renderSubItem = (item) => {
      const onClick = () => {
        if (item.disabled) {
          return;
        }
        let activeId;
        if (Array.isArray(props2.activeId)) {
          activeId = props2.activeId.slice();
          const index2 = activeId.indexOf(item.id);
          if (index2 !== -1) {
            activeId.splice(index2, 1);
          } else if (activeId.length < +props2.max) {
            activeId.push(item.id);
          }
        } else {
          activeId = item.id;
        }
        emit("update:activeId", activeId);
        emit("clickItem", item);
      };
      return Vue.createVNode("div", {
        "key": item.id,
        "class": ["van-ellipsis", bem("item", {
          active: isActiveItem(item.id),
          disabled: item.disabled
        })],
        "onClick": onClick
      }, [item.text, isActiveItem(item.id) && Vue.createVNode(index$2.Icon, {
        "name": props2.selectedIcon,
        "class": bem("selected")
      }, null)]);
    };
    const onSidebarChange = (index2) => {
      emit("update:mainActiveIndex", index2);
    };
    const onClickSidebarItem = (index2) => emit("clickNav", index2);
    const renderSidebar = () => {
      const Items = props2.items.map((item) => Vue.createVNode(index.SidebarItem, {
        "dot": item.dot,
        "badge": item.badge,
        "class": [bem("nav-item"), item.className],
        "disabled": item.disabled,
        "onClick": onClickSidebarItem
      }, {
        title: () => slots["nav-text"] ? slots["nav-text"](item) : item.text
      }));
      return Vue.createVNode(index$1.Sidebar, {
        "class": bem("nav"),
        "modelValue": props2.mainActiveIndex,
        "onChange": onSidebarChange
      }, {
        default: () => [Items]
      });
    };
    const renderContent = () => {
      if (slots.content) {
        return slots.content();
      }
      const selected = props2.items[+props2.mainActiveIndex] || {};
      if (selected.children) {
        return selected.children.map(renderSubItem);
      }
    };
    return () => Vue.createVNode("div", {
      "class": bem(),
      "style": {
        height: format.addUnit(props2.height)
      }
    }, [renderSidebar(), Vue.createVNode("div", {
      "class": bem("content")
    }, [renderContent()])]);
  }
});
exports.default = stdin_default;
exports.treeSelectProps = treeSelectProps;
