import { jsx, jsxs } from "react/jsx-runtime";
import react, { useMemo } from "react";
import { RecursionField, observer, useField, useFieldSchema } from "@tachybase/schema";
import { Tabs } from "antd";
import { createStyles } from "antd-style";
import classnames from "classnames";
import { useSchemaInitializerRender } from "../../../application/index.mjs";
import { Icon } from "../../../icon/index.mjs";
import { DndContext, SortableItem } from "../../common/index.mjs";
import { useDesigner } from "../../hooks/useDesigner.mjs";
import { useTabsContext } from "./context.mjs";
import { TabsDesigner } from "./Tabs.Designer.mjs";
function _tagged_template_literal(strings, raw) {
    if (!raw) raw = strings.slice(0);
    return Object.freeze(Object.defineProperties(strings, {
        raw: {
            value: Object.freeze(raw)
        }
    }));
}
function _templateObject() {
    const data = _tagged_template_literal([
        "\n      position: relative;\n      &:hover {\n        > .general-schema-designer {\n          display: block;\n        }\n      }\n      &.tb-action-link {\n        > .general-schema-designer {\n          top: -10px;\n          bottom: -10px;\n          left: -10px;\n          right: -10px;\n        }\n      }\n      > .general-schema-designer {\n        position: absolute;\n        z-index: 999;\n        top: 0;\n        bottom: 0;\n        left: 0;\n        right: 0;\n        display: none;\n        background: var(--colorBgSettingsHover);\n        border: 0;\n        top: 0;\n        bottom: 0;\n        left: 0;\n        right: 0;\n        pointer-events: none;\n        > .general-schema-designer-icons {\n          position: absolute;\n          right: 2px;\n          top: 2px;\n          line-height: 16px;\n          pointer-events: all;\n          .ant-space-item {\n            background-color: var(--colorSettings);\n            color: #fff;\n            line-height: 16px;\n            width: 16px;\n            padding-left: 1px;\n            align-self: stretch;\n          }\n        }\n      }\n    "
    ]);
    _templateObject = function() {
        return data;
    };
    return data;
}
const useStyles = createStyles((param)=>{
    let { css } = param;
    return {
        designer: css(_templateObject())
    };
});
const Tabs_Tabs = observer((props)=>{
    const fieldSchema = useFieldSchema();
    const { render } = useSchemaInitializerRender(fieldSchema['x-initializer'], fieldSchema['x-initializer-props']);
    const contextProps = useTabsContext();
    const { PaneRoot = react.Fragment } = contextProps;
    const items = useMemo(()=>{
        const result = fieldSchema.mapProperties((schema, key)=>({
                key,
                label: /*#__PURE__*/ jsx(RecursionField, {
                    name: key,
                    schema: schema,
                    onlyRenderSelf: true
                }),
                children: /*#__PURE__*/ jsx(PaneRoot, {
                    ...PaneRoot !== react.Fragment ? {
                        active: key === contextProps.activeKey
                    } : {},
                    children: /*#__PURE__*/ jsx(RecursionField, {
                        name: key,
                        schema: schema,
                        onlyRenderProperties: true
                    })
                })
            }));
        return result;
    }, [
        fieldSchema.mapProperties((s, key)=>key).join()
    ]);
    return /*#__PURE__*/ jsx(DndContext, {
        children: /*#__PURE__*/ jsx(Tabs, {
            ...contextProps,
            destroyInactiveTabPane: true,
            tabBarExtraContent: render(),
            style: props.style,
            items: items
        })
    });
}, {
    displayName: 'Tabs'
});
Tabs_Tabs.TabPane = observer((props)=>{
    const { styles } = useStyles();
    const Designer = useDesigner();
    const field = useField();
    return /*#__PURE__*/ jsxs(SortableItem, {
        className: classnames('tb-action-link', styles.designer, props.className),
        children: [
            props.icon && /*#__PURE__*/ jsx(Icon, {
                style: {
                    marginRight: 2
                },
                type: props.icon
            }),
            " ",
            props.tab || field.title,
            /*#__PURE__*/ jsx(Designer, {})
        ]
    });
}, {
    displayName: 'Tabs.TabPane'
});
Tabs_Tabs.Designer = TabsDesigner;
export { Tabs_Tabs as Tabs };
