import { jsx as _jsx } from "@emotion/react/jsx-runtime";
import { useState, useEffect } from 'react';
import { createComponent } from '@meta-ui/core';
import { Type } from '@sinclair/typebox';
import { RadioGroup as BaseRadioGroup } from '@chakra-ui/react';
import Slot from '../_internal/Slot';
const StateSchema = Type.Object({
    value: Type.String(),
});
const RadioGroup = ({ defaultValue, isNumerical, slotsMap, mergeState, }) => {
    const [value, setValue] = useState(defaultValue);
    useEffect(() => {
        mergeState({ value });
    }, [value]);
    useEffect(() => {
        setValue(defaultValue);
    }, [defaultValue]);
    return (_jsx(BaseRadioGroup, Object.assign({ value: value, onChange: val => setValue(isNumerical ? Number(val) : val) }, { children: _jsx(Slot, { slotsMap: slotsMap, slot: "content" }, void 0) }), void 0));
};
const PropsSchema = Type.Object({
    defaultValue: Type.Union([Type.String(), Type.Number()]),
    isNumerical: Type.Optional(Type.Boolean()),
});
export default Object.assign(Object.assign({}, createComponent({
    version: 'chakra_ui/v1',
    metadata: {
        name: 'radio_group',
        displayName: 'RadioGroup',
        description: 'chakra-ui radio group',
        isDraggable: true,
        isResizable: true,
        exampleProperties: {
            defaultValue: 0,
            isNumerical: true,
        },
        exampleSize: [3, 3],
    },
    spec: {
        properties: PropsSchema,
        state: StateSchema,
        methods: [],
        slots: ['content'],
        styleSlots: [],
        events: [],
    },
})), { impl: RadioGroup });
//# sourceMappingURL=RadioGroup.js.map