"use strict";
var __webpack_require__ = {};
(()=>{
    __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__, {
    IconPicker: ()=>IconPicker,
    default: ()=>IconPicker_rslib_entry_
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const components_namespaceObject = require("@tachybase/components");
const schema_namespaceObject = require("@tachybase/schema");
const icons_namespaceObject = require("@ant-design/icons");
const external_antd_namespaceObject = require("antd");
const external_react_i18next_namespaceObject = require("react-i18next");
const index_js_namespaceObject = require("../../../icon/index.js");
const external_popover_index_js_namespaceObject = require("../popover/index.js");
const external_IconFilterInput_js_namespaceObject = require("./IconFilterInput.js");
const external_IconList_js_namespaceObject = require("./IconList.js");
function IconField(props) {
    const { value, onChange, disabled } = props;
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const layout = (0, components_namespaceObject.useFormLayout)();
    const [visible, setVisible] = (0, external_react_namespaceObject.useState)(false);
    const [filterKey, setFilterKey] = (0, external_react_namespaceObject.useState)('');
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_antd_namespaceObject.Space.Compact, {
            children: [
                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_popover_index_js_namespaceObject.StablePopover, {
                    placement: 'bottom',
                    open: visible,
                    onOpenChange: (val)=>{
                        if (disabled) return;
                        setVisible(val);
                    },
                    content: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
                        children: [
                            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_IconFilterInput_js_namespaceObject.IconFilterInput, {
                                changeFilterKey: setFilterKey
                            }),
                            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_IconList_js_namespaceObject.IconFilterList, {
                                currentKey: value,
                                filterKey: filterKey,
                                onChange: onChange,
                                changePop: setVisible
                            })
                        ]
                    }),
                    title: t('Icon'),
                    trigger: "click",
                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Button, {
                        size: layout.size,
                        disabled: disabled,
                        children: (0, index_js_namespaceObject.hasIcon)(value) ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_js_namespaceObject.Icon, {
                            type: value
                        }) : t('Select icon')
                    })
                }),
                value && !disabled && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Button, {
                    size: layout.size,
                    icon: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icons_namespaceObject.CloseOutlined, {}),
                    onClick: (e)=>{
                        onChange(null);
                    }
                })
            ]
        })
    });
}
const IconPicker = (0, schema_namespaceObject.connect)(IconField, (0, schema_namespaceObject.mapProps)((props, field)=>({
        ...props,
        suffix: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
            children: (null == field ? void 0 : field['loading']) || (null == field ? void 0 : field['validating']) ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icons_namespaceObject.LoadingOutlined, {}) : props.suffix
        })
    })), (0, schema_namespaceObject.mapReadPretty)((props)=>{
    if (!(0, schema_namespaceObject.isValid)(props.value)) return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {});
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_js_namespaceObject.Icon, {
        type: props.value
    });
}));
const IconPicker_rslib_entry_ = IconPicker;
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
});
