import { createVNode as _createVNode, isVNode as _isVNode } from "vue";
import "./styles/list.css";
import { computed, toRef } from "vue";
import { useRender } from "@veno-ui/utils";
import { genericComponent } from "../../utils";
import { makePaperProps, usePaper } from "../../composables/paper";
import { makeDisabledProps, useDisabled } from "../../composables/disabled";
import { makeNestedProps, useNested } from "../../composables/nested";
import { provideDefaults } from "../../composables/defaults";
import { provideList } from "./composables/list";
import { ListChildren } from "./list-children";
function _isSlot(s) {
  return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !_isVNode(s);
}
function parseItems(items) {
  if (!items)
    return void 0;
  return items.map((item) => {
    if (typeof item === "string")
      return {
        type: "item",
        props: {
          value: item,
          title: item
        }
      };
    const {
      $type,
      $children,
      ...props
    } = item;
    if ($type === "subheader")
      return {
        type: "subheader",
        props
      };
    if ($type === "divider")
      return {
        type: "divider",
        props
      };
    return {
      type: "item",
      props,
      children: parseItems($children)
    };
  });
}
const List = genericComponent()({
  name: "VeList",
  props: {
    /**
     * @zh 是否为导航列表
     */
    nav: Boolean,
    /**
     * @zh 数据驱动时列表项数据
     */
    items: Array,
    ...makeNestedProps({
      selectStrategy: "leaf",
      openStrategy: "multiple",
      activeStrategy: "single"
    }),
    ...makePaperProps({
      size: void 0
    }),
    ...makeDisabledProps()
  },
  emits: {
    "update:selected": (_selected) => true,
    "update:opened": (_opened) => true,
    "update:active": (_active) => true
  },
  setup(props, {
    slots
  }) {
    const items = computed(() => parseItems(props.items));
    const {
      paperClasses,
      paperStyles
    } = usePaper(props);
    const {
      disabledClasses
    } = useDisabled(props);
    const {
      open,
      select,
      activate
    } = useNested(props);
    provideList();
    provideDefaults({
      VeListItem: {
        density: toRef(props, "density")
      }
    });
    useRender(() => {
      return _createVNode(props.tag, {
        "class": ["ve-list", {
          "ve-list--nav": props.nav
        }, paperClasses.value, disabledClasses.value],
        "style": paperStyles.value
      }, {
        default: () => [slots.prepend?.(), _createVNode(ListChildren, {
          "items": items.value
        }, _isSlot(slots) ? slots : {
          default: () => [slots]
        }), slots.append?.()]
      });
    });
    return {
      open,
      select,
      activate
    };
  }
});
export {
  List
};
//# sourceMappingURL=list.mjs.map
