"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.n = (module)=>{
        var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
(()=>{
    __webpack_require__.d = (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 = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
    __webpack_require__.r = (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__, {
    Page: ()=>Page
});
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 pro_layout_namespaceObject = require("@ant-design/pro-layout");
const core_namespaceObject = require("@dnd-kit/core");
const external_antd_namespaceObject = require("antd");
const external_antd_style_namespaceObject = require("antd-style");
const external_classnames_namespaceObject = require("classnames");
var external_classnames_default = /*#__PURE__*/ __webpack_require__.n(external_classnames_namespaceObject);
const external_react_error_boundary_namespaceObject = require("react-error-boundary");
const external_react_i18next_namespaceObject = require("react-i18next");
const external_react_router_dom_namespaceObject = require("react-router-dom");
const external_index_js_namespaceObject = require("../index.js");
const index_js_namespaceObject = require("../__builtins__/index.js");
const style_js_namespaceObject = require("../../../built-in/acl/style.js");
const useContextMenu_js_namespaceObject = require("../../../built-in/context-menu/useContextMenu.js");
const document_title_index_js_namespaceObject = require("../../../built-in/document-title/index.js");
const FilterProvider_js_namespaceObject = require("../../../filter-provider/FilterProvider.js");
const external_icon_index_js_namespaceObject = require("../../../icon/index.js");
const useGetAriaLabelOfSchemaInitializer_js_namespaceObject = require("../../../schema-initializer/hooks/useGetAriaLabelOfSchemaInitializer.js");
const theme_index_js_namespaceObject = require("../../../style/theme/index.js");
const external_common_index_js_namespaceObject = require("../../common/index.js");
const sortable_item_index_js_namespaceObject = require("../../common/sortable-item/index.js");
const DragHandlePageTab_js_namespaceObject = require("../../common/sortable-item/DragHandlePageTab.js");
const external_core_index_js_namespaceObject = require("../../core/index.js");
const external_hooks_index_js_namespaceObject = require("../../hooks/index.js");
const external_error_fallback_index_js_namespaceObject = require("../error-fallback/index.js");
const external_FixedBlock_js_namespaceObject = require("./FixedBlock.js");
var external_FixedBlock_js_default = /*#__PURE__*/ __webpack_require__.n(external_FixedBlock_js_namespaceObject);
const useShareActions_js_namespaceObject = require("./hooks/useShareActions.js");
const external_Page_style_js_namespaceObject = require("./Page.style.js");
const external_PageDesigner_js_namespaceObject = require("./PageDesigner.js");
const external_PageTabDesigner_js_namespaceObject = require("./PageTabDesigner.js");
const external_style_js_namespaceObject = require("./style.js");
const Page = (props)=>{
    var _fieldSchema_xcomponentprops, _fieldSchema_xcomponentprops1, _fieldSchema_xcomponentprops2;
    const { children, ...others } = props;
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const { title, setTitle } = (0, document_title_index_js_namespaceObject.useDocumentTitle)();
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const disablePageHeader = null == (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) ? void 0 : _fieldSchema_xcomponentprops.disablePageHeader;
    const enablePageTabs = null == (_fieldSchema_xcomponentprops1 = fieldSchema['x-component-props']) ? void 0 : _fieldSchema_xcomponentprops1.enablePageTabs;
    const enableSharePage = null == (_fieldSchema_xcomponentprops2 = fieldSchema['x-component-props']) ? void 0 : _fieldSchema_xcomponentprops2.enableSharePage;
    const [searchParams, setSearchParams] = (0, external_react_router_dom_namespaceObject.useSearchParams)();
    const [loading, setLoading] = (0, external_react_namespaceObject.useState)(false);
    const activeKey = (0, external_react_namespaceObject.useMemo)(()=>searchParams.get('tab') || Object.keys(fieldSchema.properties || {}).shift(), [
        fieldSchema.properties,
        searchParams
    ]);
    const [height, setHeight] = (0, external_react_namespaceObject.useState)(0);
    const aclStyles = (0, style_js_namespaceObject.useStyles)();
    const { wrapSSR, hashId, componentCls } = (0, external_style_js_namespaceObject.getStyles)();
    (0, external_react_namespaceObject.useEffect)(()=>{
        if (!title) setTitle(t(fieldSchema.title));
    }, [
        fieldSchema.title,
        title
    ]);
    return wrapSSR(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(FilterProvider_js_namespaceObject.FilterBlockProvider, {
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
            className: "".concat(componentCls, " ").concat(hashId, " ").concat(aclStyles.styles),
            children: [
                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_PageDesigner_js_namespaceObject.PageDesigner, {
                    title: fieldSchema.title || title
                }),
                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(PageHeader, {
                    disablePageHeader: disablePageHeader,
                    enablePageTabs: enablePageTabs,
                    activeKey: activeKey,
                    title: title,
                    fieldSchema: fieldSchema,
                    parentProps: others,
                    setHeight: setHeight,
                    setLoading: setLoading,
                    enableSharePage: enableSharePage,
                    setSearchParams: setSearchParams
                }),
                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(PageContentComponent, {
                    loading: loading,
                    disablePageHeader: disablePageHeader,
                    enablePageTabs: enablePageTabs,
                    fieldSchema: fieldSchema,
                    activeKey: activeKey,
                    height: height,
                    children: children
                })
            ]
        })
    }));
};
const PageHeader = (props)=>{
    var _fieldSchema_xcomponentprops;
    const { disablePageHeader, enablePageTabs, setHeight, activeKey, setLoading, setSearchParams, fieldSchema, title, parentProps, enableSharePage } = props;
    const { theme } = (0, theme_index_js_namespaceObject.useGlobalTheme)();
    const options = (0, external_react_namespaceObject.useContext)(schema_namespaceObject.SchemaOptionsContext);
    const compile = (0, external_hooks_index_js_namespaceObject.useCompile)();
    const [open, setOpen] = (0, external_react_namespaceObject.useState)(false);
    const [imageOpen, setImageOpen] = (0, external_react_namespaceObject.useState)(false);
    const { showScrollArea } = (0, useContextMenu_js_namespaceObject.useContextMenu)();
    const hidePageTitle = null == (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) ? void 0 : _fieldSchema_xcomponentprops.hidePageTitle;
    const pageHeaderTitle = hidePageTitle ? void 0 : fieldSchema.title || compile(title);
    const isShare = (0, external_react_router_dom_namespaceObject.useMatch)('/share/:name');
    const items = fieldSchema.mapProperties((schema)=>({
            key: schema.name,
            label: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(TabItem, {
                schema: schema
            })
        }));
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const { styles } = (0, external_style_js_namespaceObject.useStyles)();
    const { copyLink, imageAction } = (0, useShareActions_js_namespaceObject.useShareActions)({
        title: pageHeaderTitle,
        uid: ''
    });
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
        ref: (ref)=>{
            setHeight(Math.floor((null == ref ? void 0 : ref.getBoundingClientRect().height) || 0) + 1);
        },
        className: "tb-page-header-wrapper",
        children: [
            !disablePageHeader && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(pro_layout_namespaceObject.PageHeader, {
                className: external_classnames_default()('pageHeaderCss', pageHeaderTitle || enableSharePage ? '' : 'height0'),
                ghost: false,
                title: pageHeaderTitle || ' ',
                ...parentProps,
                extra: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(HeaderExtra, {
                    enablePageTabs: enablePageTabs,
                    showScrollArea: showScrollArea,
                    isShare: isShare,
                    setOpen: setOpen,
                    enableSharePage: enableSharePage
                }),
                footer: enablePageTabs && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(TabComponent, {
                    activeKey: activeKey,
                    setLoading: setLoading,
                    setSearchParams: setSearchParams,
                    showScrollArea: showScrollArea,
                    options: options,
                    theme: theme,
                    items: items
                })
            }),
            disablePageHeader && enableSharePage && !isShare && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                className: "tb-page-header-button",
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Button, {
                    icon: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icons_namespaceObject.ShareAltOutlined, {}),
                    onClick: ()=>{
                        setOpen(true);
                    },
                    children: t('Share')
                })
            }),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_antd_namespaceObject.Modal, {
                open: open,
                className: styles.firstmodal,
                title: t('Share'),
                footer: null,
                width: 500,
                onCancel: ()=>{
                    setOpen(false);
                },
                children: [
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
                        className: styles.secondmodal,
                        children: [
                            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
                                className: "tb-header-modal-list",
                                onClick: copyLink,
                                children: [
                                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_icon_index_js_namespaceObject.Icon, {
                                        type: "PaperClipOutlined"
                                    }),
                                    t('Copy link')
                                ]
                            }),
                            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
                                className: "tb-header-modal-list",
                                onClick: ()=>{
                                    setImageOpen(true);
                                },
                                children: [
                                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_icon_index_js_namespaceObject.Icon, {
                                        type: "QrcodeOutlined"
                                    }),
                                    t('Generate QR code')
                                ]
                            })
                        ]
                    }),
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Modal, {
                        className: styles.imageModal,
                        open: imageOpen,
                        footer: null,
                        onCancel: ()=>{
                            setImageOpen(false);
                        },
                        children: imageAction()
                    })
                ]
            })
        ]
    });
};
const HeaderExtra = (param)=>{
    let { enablePageTabs, showScrollArea, isShare, setOpen, enableSharePage } = param;
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
        children: [
            !isShare && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Button, {
                icon: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icons_namespaceObject.ShareAltOutlined, {}),
                onClick: ()=>{
                    setOpen(true);
                },
                style: {
                    visibility: "".concat(enableSharePage ? 'visible' : 'hidden')
                }
            }),
            !enablePageTabs && showScrollArea && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_index_js_namespaceObject.ScrollArea, {})
        ]
    });
};
const TabComponent = (props)=>{
    const { activeKey, setLoading, setSearchParams, showScrollArea, options, theme, items } = props;
    const { styles } = (0, external_Page_style_js_namespaceObject.useStyles)();
    const [hasMounted, setHasMounted] = (0, external_react_namespaceObject.useState)(false);
    const sensors = (0, core_namespaceObject.useSensors)((0, core_namespaceObject.useSensor)(core_namespaceObject.PointerSensor, {
        activationConstraint: {
            distance: 5
        }
    }));
    const handleTabClick = (activeKey)=>{
        setLoading(true);
        setSearchParams([
            [
                'tab',
                activeKey
            ]
        ]);
        setTimeout(()=>{
            setLoading(false);
        }, 50);
    };
    (0, external_react_namespaceObject.useEffect)(()=>{
        setTimeout(()=>{
            setHasMounted(true);
        });
    }, []);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_common_index_js_namespaceObject.DndContext, {
        sensors: sensors,
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Tabs, {
            className: styles.tabComponentClass,
            type: "card",
            size: 'small',
            animated: hasMounted,
            activeKey: activeKey,
            items: items,
            onTabClick: handleTabClick,
            tabBarExtraContent: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(TabBarExtraContent, {
                theme: theme,
                showScrollArea: showScrollArea,
                options: options
            })
        })
    });
};
const TabItem = (props)=>{
    const { schema } = props;
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const { styles } = (0, external_Page_style_js_namespaceObject.useStyles)();
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(sortable_item_index_js_namespaceObject.SortableItem, {
        id: schema.name,
        schema: schema,
        className: external_classnames_default()('tb-action-link', 'designerCss', props.className, styles.tabItemClass),
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(DragHandlePageTab_js_namespaceObject.DragHandlePageTab, {
            children: [
                schema['x-icon'] && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_icon_index_js_namespaceObject.Icon, {
                    style: {
                        marginRight: 8
                    },
                    type: schema['x-icon']
                }),
                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
                    children: schema.title || t('Unnamed')
                }),
                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                    className: "tab-designer-wrapper",
                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_PageTabDesigner_js_namespaceObject.PageTabDesigner, {
                        schema: schema
                    })
                })
            ]
        })
    });
};
const TabBarExtraContent = (props)=>{
    const { showScrollArea, options, theme } = props;
    const dn = (0, external_hooks_index_js_namespaceObject.useDesignable)();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const { getAriaLabel } = (0, useGetAriaLabelOfSchemaInitializer_js_namespaceObject.useGetAriaLabelOfSchemaInitializer)();
    const { styles } = (0, external_Page_style_js_namespaceObject.useStyles)();
    const handleAddTab = async ()=>{
        const values = await (0, external_index_js_namespaceObject.FormDialog)(t('Add tab'), ()=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(AddTabForm, {
                options: options
            }), theme).open({
            initialValues: {}
        });
        const { title, icon } = values;
        dn.insertBeforeEnd({
            type: 'void',
            title,
            'x-icon': icon,
            'x-component': 'Grid',
            'x-initializer': 'page:addBlock',
            properties: {}
        });
    };
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
        className: (0, external_antd_style_namespaceObject.cx)(styles.tabWrapper, {
            designable: dn.designable
        }),
        children: [
            dn.designable && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Button, {
                className: "add-tab-btn",
                type: "text",
                "aria-label": getAriaLabel('tabs'),
                icon: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icons_namespaceObject.PlusOutlined, {}),
                onClick: handleAddTab
            }),
            showScrollArea && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_index_js_namespaceObject.ScrollArea, {
                className: "scroll-area-extra-content"
            })
        ]
    });
};
const AddTabForm = (props)=>{
    const { options } = props;
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_core_index_js_namespaceObject.SchemaComponentOptions, {
        scope: options.scope,
        components: {
            ...options.components
        },
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(components_namespaceObject.FormLayout, {
            layout: 'vertical',
            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_core_index_js_namespaceObject.SchemaComponent, {
                schema: {
                    properties: {
                        title: {
                            title: t('Tab name'),
                            'x-component': 'Input',
                            'x-decorator': 'FormItem',
                            required: true
                        },
                        icon: {
                            title: t('Icon'),
                            'x-component': 'IconPicker',
                            'x-decorator': 'FormItem'
                        }
                    }
                }
            })
        })
    });
};
const PageContentComponent = (props)=>{
    const handleErrors = (error)=>{
        var _window_Sentry, _window;
        null == (_window = window) || null == (_window_Sentry = _window.Sentry) || _window_Sentry.captureException(error);
        console.error(error);
    };
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
        className: "tb-page-wrapper",
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_react_error_boundary_namespaceObject.ErrorBoundary, {
            FallbackComponent: external_error_fallback_index_js_namespaceObject.ErrorFallback,
            onError: handleErrors,
            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(PageContent, {
                ...props
            })
        })
    });
};
const PageContent = (props)=>{
    const { loading, disablePageHeader, enablePageTabs, fieldSchema, activeKey, height, children } = props;
    const { token } = (0, index_js_namespaceObject.useToken)();
    if (loading) return;
    if (!disablePageHeader && enablePageTabs) return fieldSchema.mapProperties((schema)=>{
        if (schema.name !== activeKey) return null;
        return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_FixedBlock_js_default(), {
            height: "calc(".concat(height, "px + 46px + ").concat(token.marginLG, "px * 2)"),
            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_core_index_js_namespaceObject.SchemaComponent, {
                schema: new schema_namespaceObject.Schema({
                    properties: {
                        [schema.name]: schema
                    }
                })
            })
        }, schema.name);
    });
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_FixedBlock_js_default(), {
        height: "calc(".concat(height, "px + 46px + ").concat(token.marginLG, "px * 2)"),
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
            className: "pageWithFixedBlockCss tb-page-content",
            children: children
        })
    });
};
exports.Page = __webpack_exports__.Page;
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
    "Page"
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
Object.defineProperty(exports, '__esModule', {
    value: true
});
