import { computed, toRef, createVNode, isVNode } from "vue";
import "./styles/list.scss";
import { makePaperProps, usePaper } from "../../composables/paper/index.mjs";
import { makeDisabledProps, useDisabled } from "../../composables/disabled/index.mjs";
import { makeNestedProps, useNested } from "../../composables/nested/index.mjs";
import { provideDefaults } from "../../composables/defaults/index.mjs";
import { provideList } from "./composables/list.mjs";
import { ListChildren } from "./list-children.mjs";
import { genericComponent } from "../../utils/define-component.mjs";
import { useRender } from "../../utils/dist/index.mjs";
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: {
    nav: Boolean,
    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: () => {
          var _a, _b;
          return [(_a = slots.prepend) == null ? void 0 : _a.call(slots), createVNode(ListChildren, {
            "items": items.value
          }, _isSlot(slots) ? slots : {
            default: () => [slots]
          }), (_b = slots.append) == null ? void 0 : _b.call(slots)];
        }
      });
    });
    return {
      open,
      select,
      activate
    };
  }
});
export {
  List
};
//# sourceMappingURL=list.mjs.map
