import { defineComponent, h } from "vue";
import { cx, iconNode } from "../utils.js";

export default defineComponent({
	name: "GnNavList",
	props: {
		items: { type: Array, default: () => [] }
	},
	emits: ["select"],
	setup(props, { attrs, emit, slots }) {
		return () => h("ul", { ...attrs, class: cx("list list-nav", attrs.class) }, props.items.map(item => h("li", {
			class: cx("list-item", { "list-item-active": item.active })
		}, [
			h(item.href ? "a" : "button", {
				class: "list-action",
				href: item.href,
				type: item.href ? undefined : "button",
				onClick: event => {
					item.onSelect?.(item, event);
					emit("select", item);
				}
			}, [
				h("span", { class: "list-label" }, [
					iconNode(item.icon),
					slots.label?.({ item }) || item.label
				]),
				(item.meta || slots.meta) && h("span", { class: "list-meta" }, slots.meta?.({ item }) || item.meta)
			])
		])));
	}
});
