"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const index = require("../../../hooks/use-namespace/index.js");
const index$1 = require("../../../hooks/use-id/index.js");
const constants = require("./constants.js");
const Vue = require("vue");
const useCollapseItem = (props) => {
  const collapse = Vue.inject(constants.collapseContextKey);
  const { namespace } = index.useNamespace("collapse");
  const focusing = Vue.ref(false);
  const isClick = Vue.ref(false);
  const idInjection = index$1.useIdInjection();
  const id = Vue.computed(() => idInjection.current++);
  const name = Vue.computed(() => {
    return props.name ?? `${namespace.value}-id-${idInjection.prefix}-${Vue.unref(id)}`;
  });
  const isActive = Vue.computed(() => collapse == null ? void 0 : collapse.activeNames.value.includes(Vue.unref(name)));
  const handleFocus = () => {
    setTimeout(() => {
      if (!isClick.value) focusing.value = true;
      else isClick.value = false;
    }, 50);
  };
  const handleHeaderClick = (e) => {
    var _a;
    if (props.disabled) return;
    if ((_a = e.target) == null ? void 0 : _a.closest("input, textarea, select")) return;
    collapse == null ? void 0 : collapse.handleItemClick(Vue.unref(name));
    focusing.value = false;
    isClick.value = true;
  };
  const handleEnterClick = (e) => {
    var _a;
    if ((_a = e.target) == null ? void 0 : _a.closest("input, textarea, select")) return;
    e.preventDefault();
    collapse == null ? void 0 : collapse.handleItemClick(Vue.unref(name));
  };
  return {
    focusing,
    id,
    isActive,
    handleFocus,
    handleHeaderClick,
    handleEnterClick
  };
};
const useCollapseItemDOM = (props, { focusing, isActive, id }) => {
  const ns = index.useNamespace("collapse");
  const rootKls = Vue.computed(() => [
    ns.b("item"),
    ns.is("active", Vue.unref(isActive)),
    ns.is("disabled", props.disabled)
  ]);
  const headKls = Vue.computed(() => [
    ns.be("item", "header"),
    ns.is("active", Vue.unref(isActive)),
    { focusing: Vue.unref(focusing) && !props.disabled }
  ]);
  const arrowKls = Vue.computed(() => [ns.be("item", "arrow"), ns.is("active", Vue.unref(isActive))]);
  return {
    itemTitleKls: Vue.computed(() => [ns.be("item", "title")]),
    arrowKls,
    headKls,
    rootKls,
    itemWrapperKls: Vue.computed(() => ns.be("item", "wrap")),
    itemContentKls: Vue.computed(() => ns.be("item", "content")),
    scopedContentId: Vue.computed(() => ns.b(`content-${Vue.unref(id)}`)),
    scopedHeadId: Vue.computed(() => ns.b(`head-${Vue.unref(id)}`))
  };
};
exports.useCollapseItem = useCollapseItem;
exports.useCollapseItemDOM = useCollapseItemDOM;
