"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;
