import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE__ant_design_icons__ from "@ant-design/icons";
import * as __WEBPACK_EXTERNAL_MODULE_antd__ from "antd";
import * as __WEBPACK_EXTERNAL_MODULE_lodash_uniq__ from "lodash/uniq";
import * as __WEBPACK_EXTERNAL_MODULE_react_i18next__ from "react-i18next";
import * as __WEBPACK_EXTERNAL_MODULE__data_source_collection_field_CollectionFieldProvider_mjs__ from "../../../data-source/collection-field/CollectionFieldProvider.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__input_EllipsisWithTooltip_mjs__ from "../input/EllipsisWithTooltip.mjs";
const ReadPretty = (props)=>{
    if (props.value) return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__ant_design_icons__.CheckOutlined, {
        style: {
            color: '#52c41a'
        }
    });
    return props.showUnchecked ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__ant_design_icons__.CloseOutlined, {
        style: {
            color: '#ff4d4f'
        }
    }) : null;
};
const InternalCheckbox = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.connect)((props)=>{
    const changeHandler = (val)=>{
        null == props || props.onChange(val);
    };
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Checkbox, {
        ...props,
        onChange: changeHandler
    });
}, (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.mapProps)({
    value: 'checked',
    onInput: 'onChange'
}), (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.mapReadPretty)(ReadPretty));
const InternalRadioGroup = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.connect)((props)=>{
    const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
    const [value, setValue] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)();
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Radio.Group, {
        ...props,
        onChange: (value)=>{
            if ('null' !== value.target.value) props.onChange(value.target.value);
            else props.onChange(null);
            setValue(value.target.value);
        },
        value: props.value || value,
        options: [
            {
                label: t('?'),
                value: 'null'
            },
            {
                label: t('Yes'),
                value: 'true'
            },
            {
                label: t('No'),
                value: 'false'
            }
        ],
        optionType: "button"
    });
}, (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.mapReadPretty)(ReadPretty));
const Checkbox = (props)=>{
    switch(props.mode){
        case 'Radio group':
            return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(InternalRadioGroup, {
                ...props
            });
        case 'Checkbox':
        default:
            return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(InternalCheckbox, {
                ...props
            });
    }
};
Checkbox.ReadPretty = ReadPretty;
Checkbox.__ANT_CHECKBOX = true;
Checkbox.Group = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.connect)(__WEBPACK_EXTERNAL_MODULE_antd__.Checkbox.Group, (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.mapProps)({
    dataSource: 'options'
}), (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.mapReadPretty)((props)=>{
    if (!(0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.isValid)(props.value)) return null;
    const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
    const collectionField = (0, __WEBPACK_EXTERNAL_MODULE__data_source_collection_field_CollectionFieldProvider_mjs__.useCollectionField)();
    const dataSource = field.dataSource || (null == collectionField ? void 0 : collectionField.uiSchema.enum) || [];
    const value = (0, __WEBPACK_EXTERNAL_MODULE_lodash_uniq__["default"])(field.value ? field.value : []);
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__input_EllipsisWithTooltip_mjs__.EllipsisWithTooltip, {
        ellipsis: props.ellipsis,
        children: dataSource.filter((option)=>value.includes(option.value)).map((option, key)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Tag, {
                color: option.color,
                icon: option.icon,
                children: option.label
            }, key))
    });
}));
const Checkbox_rslib_entry_ = Checkbox;
export { Checkbox, InternalCheckbox, InternalRadioGroup, Checkbox_rslib_entry_ as default };
