"use strict";
const vue = require("vue");
const types = require("./types.js");
const provide = require("./provide.js");
const is = require("../_utils/is.js");
const _hoisted_1 = { class: "o-collapse" };
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  __name: "OCollapse",
  props: types.collapseProps,
  emits: ["update:modelValue", "change"],
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emits = __emit;
    const _innerValue = vue.ref(props.defaultValue);
    const computedValue = vue.computed(() => {
      const value = props.modelValue ?? _innerValue.value;
      if (!is.isArray(value)) {
        return [value];
      }
      return value;
    });
    const handleItemClick = (value, e) => {
      let realValue = [];
      if (props.accordion) {
        if (!computedValue.value.includes(value)) {
          realValue = [value];
        }
      } else {
        realValue = [...computedValue.value];
        const idx = realValue.indexOf(value);
        if (idx > -1) {
          realValue.splice(idx, 1);
        } else {
          realValue.push(value);
        }
      }
      _innerValue.value = realValue;
      emits("update:modelValue", realValue);
      emitChange(realValue, e);
    };
    const emitChange = (val, e) => {
      vue.nextTick(() => {
        if (is.isArrayEqual(val, computedValue.value)) {
          emits("change", computedValue.value, e);
        }
      });
    };
    vue.provide(provide.collapseInjectKey, {
      computedValue,
      handleItemClick
    });
    return (_ctx, _cache) => {
      return vue.openBlock(), vue.createElementBlock("div", _hoisted_1, [
        vue.renderSlot(_ctx.$slots, "default")
      ]);
    };
  }
});
module.exports = _sfc_main;
