"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.n = function(module) {
        var getter = module && module.__esModule ? function() {
            return module['default'];
        } : function() {
            return module;
        };
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
(()=>{
    __webpack_require__.d = function(exports1, definition) {
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = function(obj, prop) {
        return Object.prototype.hasOwnProperty.call(obj, prop);
    };
})();
(()=>{
    __webpack_require__.r = function(exports1) {
        if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    InternalRadioGroup: ()=>InternalRadioGroup,
    InternalCheckbox: ()=>InternalCheckbox,
    Checkbox: ()=>Checkbox,
    default: ()=>Checkbox_rslib_entry_
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const schema_namespaceObject = require("@tachybase/schema");
const icons_namespaceObject = require("@ant-design/icons");
const external_antd_namespaceObject = require("antd");
const uniq_namespaceObject = require("lodash/uniq");
var uniq_default = /*#__PURE__*/ __webpack_require__.n(uniq_namespaceObject);
const external_react_i18next_namespaceObject = require("react-i18next");
const CollectionFieldProvider_js_namespaceObject = require("../../../data-source/collection-field/CollectionFieldProvider.js");
const EllipsisWithTooltip_js_namespaceObject = require("../input/EllipsisWithTooltip.js");
const ReadPretty = (props)=>{
    if (props.value) return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icons_namespaceObject.CheckOutlined, {
        style: {
            color: '#52c41a'
        }
    });
    return props.showUnchecked ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icons_namespaceObject.CloseOutlined, {
        style: {
            color: '#ff4d4f'
        }
    }) : null;
};
const InternalCheckbox = (0, schema_namespaceObject.connect)((props)=>{
    const changeHandler = (val)=>{
        null == props || props.onChange(val);
    };
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Checkbox, {
        ...props,
        onChange: changeHandler
    });
}, (0, schema_namespaceObject.mapProps)({
    value: 'checked',
    onInput: 'onChange'
}), (0, schema_namespaceObject.mapReadPretty)(ReadPretty));
const InternalRadioGroup = (0, schema_namespaceObject.connect)((props)=>{
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const [value, setValue] = (0, external_react_namespaceObject.useState)();
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.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, schema_namespaceObject.mapReadPretty)(ReadPretty));
const Checkbox = (props)=>{
    switch(props.mode){
        case 'Radio group':
            return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(InternalRadioGroup, {
                ...props
            });
        case 'Checkbox':
        default:
            return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(InternalCheckbox, {
                ...props
            });
    }
};
Checkbox.ReadPretty = ReadPretty;
Checkbox.__ANT_CHECKBOX = true;
Checkbox.Group = (0, schema_namespaceObject.connect)(external_antd_namespaceObject.Checkbox.Group, (0, schema_namespaceObject.mapProps)({
    dataSource: 'options'
}), (0, schema_namespaceObject.mapReadPretty)((props)=>{
    if (!(0, schema_namespaceObject.isValid)(props.value)) return null;
    const field = (0, schema_namespaceObject.useField)();
    const collectionField = (0, CollectionFieldProvider_js_namespaceObject.useCollectionField)();
    const dataSource = field.dataSource || (null == collectionField ? void 0 : collectionField.uiSchema.enum) || [];
    const value = uniq_default()(field.value ? field.value : []);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(EllipsisWithTooltip_js_namespaceObject.EllipsisWithTooltip, {
        ellipsis: props.ellipsis,
        children: dataSource.filter((option)=>value.includes(option.value)).map((option, key)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Tag, {
                color: option.color,
                icon: option.icon,
                children: option.label
            }, key))
    });
}));
const Checkbox_rslib_entry_ = Checkbox;
var __webpack_export_target__ = exports;
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
    value: true
});
