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

export default defineComponent({
	name: "GnSwitch",
	inheritAttrs: false,
	props: {
		modelValue: { type: Boolean, default: false },
		label: { type: String, default: "" },
		disabled: { type: Boolean, default: false }
	},
	emits: ["update:modelValue"],
	setup(props, { attrs, emit, slots }) {
		return () => h("label", { class: cx("switch", attrs.class) }, [
			h("input", {
				...attrs,
				type: "checkbox",
				checked: props.modelValue,
				disabled: props.disabled,
				onChange: event => emit("update:modelValue", eventValue(event))
			}),
			h("span", { class: "switch-control", "aria-hidden": "true" }),
			h("span", { class: "switch-label" }, slots.default?.() || props.label)
		]);
	}
});
