"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const Vue = require("vue");
const index_esm = require("../../../@vant/use/dist/index.esm.js");
const useExpose = require("../composables/use-expose.js");
const props = require("../utils/props.js");
const create = require("../utils/create.js");
const constant = require("../utils/constant.js");
const [name, bem] = create.createNamespace("collapse");
const COLLAPSE_KEY = Symbol(name);
const collapseProps = {
  border: props.truthProp,
  accordion: Boolean,
  modelValue: {
    type: [String, Number, Array],
    default: ""
  }
};
var stdin_default = Vue.defineComponent({
  name,
  props: collapseProps,
  emits: ["change", "update:modelValue"],
  setup(props2, {
    emit,
    slots
  }) {
    const {
      linkChildren,
      children
    } = index_esm.useChildren(COLLAPSE_KEY);
    const updateName = (name2) => {
      emit("change", name2);
      emit("update:modelValue", name2);
    };
    const toggle = (name2, expanded) => {
      const {
        accordion,
        modelValue
      } = props2;
      if (accordion) {
        updateName(name2 === modelValue ? "" : name2);
      } else if (expanded) {
        updateName(modelValue.concat(name2));
      } else {
        updateName(modelValue.filter((activeName) => activeName !== name2));
      }
    };
    const toggleAll = (options = {}) => {
      if (props2.accordion) {
        return;
      }
      if (typeof options === "boolean") {
        options = {
          expanded: options
        };
      }
      const {
        expanded,
        skipDisabled
      } = options;
      const expandedChildren = children.filter((item) => {
        if (item.disabled && skipDisabled) {
          return item.expanded.value;
        }
        return expanded != null ? expanded : !item.expanded.value;
      });
      const names = expandedChildren.map((item) => item.itemName.value);
      updateName(names);
    };
    const isExpanded = (name2) => {
      const {
        accordion,
        modelValue
      } = props2;
      return accordion ? modelValue === name2 : modelValue.includes(name2);
    };
    useExpose.useExpose({
      toggleAll
    });
    linkChildren({
      toggle,
      isExpanded
    });
    return () => {
      var _a;
      return Vue.createVNode("div", {
        "class": [bem(), {
          [constant.BORDER_TOP_BOTTOM]: props2.border
        }]
      }, [(_a = slots.default) == null ? void 0 : _a.call(slots)]);
    };
  }
});
exports.COLLAPSE_KEY = COLLAPSE_KEY;
exports.collapseProps = collapseProps;
exports.default = stdin_default;
