import { defineComponent, h } from "vue";
import GnRadio from "./GnRadio.js";

export default defineComponent({
	name: "GnRadioGroup",
	props: {
		modelValue: { type: [String, Number, Boolean], default: "" },
		name: { type: String, default: "gn-radio-group" },
		label: { type: String, default: "" },
		options: { type: Array, default: () => [] }
	},
	emits: ["update:modelValue"],
	setup(props, { emit, slots }) {
		return () => h("div", { class: "form-group", role: "radiogroup", "aria-label": props.label || undefined }, [
			props.label && h("div", { class: "label" }, props.label),
			slots.default?.() || props.options.map(option => h(GnRadio, {
				modelValue: props.modelValue,
				"onUpdate:modelValue": value => emit("update:modelValue", value),
				name: props.name,
				value: option.value,
				label: option.label,
				disabled: option.disabled
			}))
		]);
	}
});
