import { jsx } from "react/jsx-runtime";
import { useEffect } from "react";
import { connect, isValid, mapProps, mapReadPretty, useField } from "@tachybase/schema";
import { Radio, Tag } from "antd";
import { useCollectionField } from "../../../data-source/collection-field/CollectionFieldProvider.mjs";
const Radio_Radio = connect(Radio, mapProps({
    value: 'checked',
    onInput: 'onChange'
}));
Radio_Radio.__ANT_RADIO = true;
Radio_Radio.Group = connect(Radio.Group, mapProps({
    dataSource: 'options'
}, (props, field)=>{
    useEffect(()=>{
        var _field_dataSource;
        const defaultOption = null == (_field_dataSource = field.dataSource) ? void 0 : _field_dataSource.find((option)=>option.value == props.value);
        if (defaultOption) field.setValue(defaultOption.value);
    }, [
        props.value,
        field.dataSource
    ]);
    return {
        ...props
    };
}), mapReadPretty((props)=>{
    if (!isValid(props.value)) return /*#__PURE__*/ jsx("div", {});
    const { value } = props;
    const field = useField();
    const collectionField = useCollectionField();
    const dataSource = field.dataSource || (null == collectionField ? void 0 : collectionField.uiSchema.enum) || [];
    return /*#__PURE__*/ jsx("div", {
        children: dataSource.filter((option)=>option.value == value).map((option, key)=>/*#__PURE__*/ jsx(Tag, {
                color: option.color,
                icon: option.icon,
                children: option.label
            }, key))
    });
}));
const radio_Radio = Radio_Radio;
export { Radio_Radio as Radio, radio_Radio as default };
