"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__, {
    FormTab: ()=>FormTab,
    default: ()=>form_tab_rslib_entry_
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const schema_namespaceObject = require("@tachybase/schema");
const external_antd_namespaceObject = require("antd");
const external_classnames_namespaceObject = require("classnames");
var external_classnames_default = /*#__PURE__*/ __webpack_require__.n(external_classnames_namespaceObject);
const index_js_namespaceObject = require("../__builtins__/index.js");
const external_hooks_index_js_namespaceObject = require("../../hooks/index.js");
const useTabs = ()=>{
    const tabsField = (0, schema_namespaceObject.useField)();
    const schema = (0, schema_namespaceObject.useFieldSchema)();
    const tabs = [];
    schema.mapProperties((schema, name)=>{
        var _schema_xcomponent;
        const field = tabsField.query(tabsField.address.concat(name)).take();
        if ((null == field ? void 0 : field.display) === 'none' || (null == field ? void 0 : field.display) === 'hidden') return;
        if ((null === (_schema_xcomponent = schema['x-component']) || void 0 === _schema_xcomponent ? void 0 : _schema_xcomponent.indexOf('TabPane')) > -1) {
            var _field_componentProps, _schema_xcomponentprops;
            const key = (null == field ? void 0 : null === (_field_componentProps = field.componentProps) || void 0 === _field_componentProps ? void 0 : _field_componentProps.key) || (null == schema ? void 0 : null === (_schema_xcomponentprops = schema['x-component-props']) || void 0 === _schema_xcomponentprops ? void 0 : _schema_xcomponentprops.key) || name;
            tabs.push({
                name,
                props: {
                    ...null == schema ? void 0 : schema['x-component-props'],
                    ...null == field ? void 0 : field.componentProps,
                    key
                },
                schema
            });
        }
    });
    return tabs;
};
const useTabExtraContent = ()=>{
    const tabsField = (0, schema_namespaceObject.useField)();
    const schema = (0, schema_namespaceObject.useFieldSchema)();
    const tabs = [];
    schema.mapProperties((schema, name)=>{
        var _schema_xcomponent;
        const field = tabsField.query(tabsField.address.concat(name)).take();
        if ((null == field ? void 0 : field.display) === 'none' || (null == field ? void 0 : field.display) === 'hidden') return;
        if ((null === (_schema_xcomponent = schema['x-component']) || void 0 === _schema_xcomponent ? void 0 : _schema_xcomponent.indexOf('TabExtraContent')) > -1) {
            var _field_componentProps, _schema_xcomponentprops;
            const key = (null == field ? void 0 : null === (_field_componentProps = field.componentProps) || void 0 === _field_componentProps ? void 0 : _field_componentProps.key) || (null == schema ? void 0 : null === (_schema_xcomponentprops = schema['x-component-props']) || void 0 === _schema_xcomponentprops ? void 0 : _schema_xcomponentprops.key) || name;
            tabs.push({
                name,
                props: {
                    ...null == schema ? void 0 : schema['x-component-props'],
                    ...null == field ? void 0 : field.componentProps,
                    key
                },
                schema
            });
        }
    });
    return tabs;
};
const FeedbackBadge = (0, schema_namespaceObject.observer)((props)=>{
    const field = (0, schema_namespaceObject.useField)();
    const compile = (0, external_hooks_index_js_namespaceObject.useCompile)();
    const errors = field.form.queryFeedbacks({
        type: 'error',
        address: "".concat(field.address.concat(props.name), ".*")
    });
    if (errors.length) return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Badge, {
        size: "small",
        className: "errors-badge",
        count: errors.length,
        children: compile(props.tab)
    });
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(jsx_runtime_namespaceObject.Fragment, {
        children: compile(props.tab)
    });
});
const createFormTab = (defaultActiveKey)=>{
    const formTab = (0, schema_namespaceObject.model)({
        activeKey: defaultActiveKey,
        setActiveKey (key) {
            formTab.activeKey = key;
        }
    });
    return (0, schema_namespaceObject.markRaw)(formTab);
};
const FormTab = (0, schema_namespaceObject.observer)((param)=>{
    let { formTab, ...props } = param;
    const tabs = useTabs();
    const tabExtraContent = useTabExtraContent();
    const _formTab = (0, external_react_namespaceObject.useMemo)(()=>formTab ? formTab : createFormTab(), []);
    const prefixCls = (0, index_js_namespaceObject.usePrefixCls)('formily-tab', props);
    const activeKey = props.activeKey || (null == _formTab ? void 0 : _formTab.activeKey);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Tabs, {
        ...props,
        tabBarExtraContent: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(jsx_runtime_namespaceObject.Fragment, {
            children: tabExtraContent.map((param, key)=>{
                let { schema, name } = param;
                return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(schema_namespaceObject.RecursionField, {
                    schema: schema,
                    name: name
                }, key);
            })
        }),
        className: external_classnames_default()(prefixCls, props.className),
        activeKey: activeKey,
        onChange: (key)=>{
            var _props_onChange, _formTab_setActiveKey;
            null === (_props_onChange = props.onChange) || void 0 === _props_onChange || _props_onChange.call(props, key);
            null == _formTab || null === (_formTab_setActiveKey = _formTab.setActiveKey) || void 0 === _formTab_setActiveKey || _formTab_setActiveKey.call(_formTab, key);
        },
        items: tabs.map((param, key)=>{
            let { props, schema, name } = param;
            return {
                key,
                label: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(FeedbackBadge, {
                    name: name,
                    tab: props.tab
                }),
                ...props,
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(schema_namespaceObject.RecursionField, {
                    schema: schema,
                    name: name
                })
            };
        })
    });
});
const TabPane = (param)=>{
    let { children } = param;
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_react_namespaceObject.Fragment, {
        children: children
    });
};
const TabExtraContent = (param)=>{
    let { children } = param;
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_react_namespaceObject.Fragment, {
        children: children
    });
};
FormTab.TabPane = TabPane;
FormTab.TabExtraContent = TabExtraContent;
FormTab.createFormTab = createFormTab;
const form_tab_rslib_entry_ = FormTab;
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
});
