import * as __WEBPACK_EXTERNAL_MODULE__tachybase_utils_client__ from "@tachybase/utils/client";
import * as __WEBPACK_EXTERNAL_MODULE_antd__ from "antd";
import * as __WEBPACK_EXTERNAL_MODULE_react_i18next__ from "react-i18next";
import * as __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__ from "../../schema-component/index.mjs";
const designerMode = {
    name: 'designerMode',
    useLoadMethod: ()=>{
        const { designable, setDesignable } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useDesignable)();
        const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
        return {
            title: t('Designer mode'),
            actionProps: {
                onClick: ()=>{
                    setDesignable(!designable);
                }
            }
        };
    }
};
const fullScreen = {
    name: 'fullScreen',
    useLoadMethod: (param)=>{
        let { position } = param;
        const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
        const { message } = __WEBPACK_EXTERNAL_MODULE_antd__.App.useApp();
        return {
            title: t('Fullscreen'),
            actionProps: {
                onClick: ()=>{
                    checkedAutoPage(position, message, t);
                }
            }
        };
    }
};
const disableRightMenu = {
    name: 'disableRightMenu',
    sort: 4,
    useLoadMethod: (param)=>{
        let { enable, setEnable } = param;
        const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
        return {
            title: t('Disable contextmenu'),
            actionProps: {
                onClick: ()=>{
                    setEnable(!enable);
                }
            }
        };
    }
};
const ContextMenuItemsProps_rslib_entry_hiddenScrollArea = {
    name: 'hiddenScrollArea',
    sort: 3,
    useLoadMethod: (param)=>{
        let { hiddenScrollArea, setHiddenScrollArea } = param;
        const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
        return {
            title: hiddenScrollArea ? t('Show scroll area') : t('Hidden scroll area'),
            actionProps: {
                onClick: ()=>{
                    setHiddenScrollArea(!hiddenScrollArea);
                }
            }
        };
    }
};
const checkedAutoPage = (position, message, t)=>{
    const element = document.elementFromPoint(null == position ? void 0 : position.x, null == position ? void 0 : position.y);
    const blockElement = element.closest('.ant-card');
    const gridRow = null == blockElement ? void 0 : blockElement.closest('.CardRow');
    const navbar = document.querySelector('.ant-layout-header');
    blockElement.closest('.ant-modal-body');
    const amplifierBlock = blockElement.closest('.amplifier-block');
    const navbarHeight = navbar.getBoundingClientRect();
    const classId = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_utils_client__.uid)();
    if (blockElement) {
        const page = null == blockElement ? void 0 : blockElement.closest('.ant-tb-page ');
        const drawer = null == blockElement ? void 0 : blockElement.closest('.ant-drawer-body');
        const modal = null == blockElement ? void 0 : blockElement.closest('.ant-modal-body');
        const tabNav = amplifierBlock.querySelector('.ant-tabs-nav');
        if (tabNav) tabNav.style.display = 'none';
        const parentNode = gridRow.parentNode;
        Array.from(parentNode.children).forEach((sibling)=>{
            if (sibling !== gridRow) sibling.style.display = 'none';
        });
        const autoNode = document.createElement('div');
        autoNode.style.width = amplifierBlock.getBoundingClientRect().width + 'px';
        autoNode.className = 'autoPage' + classId;
        autoNode.style.position = 'fixed';
        autoNode.style.top = '0';
        autoNode.style.zIndex = '100';
        const exitNode = document.createElement('div');
        exitNode.style.width = '100%';
        exitNode.style.height = '30px';
        exitNode.style.textAlign = 'center';
        exitNode.style.lineHeight = '30px';
        exitNode.style.backgroundColor = '#e6e6e6';
        exitNode.textContent = "".concat(t('Exit fullscreen'));
        autoNode.appendChild(exitNode);
        autoNode.addEventListener('click', ()=>{
            removeNode({
                gridRow,
                classId
            });
        });
        if (page) {
            autoNode.style.marginTop = "".concat(navbarHeight.height, "px");
            const header = document.querySelector('.ant-page-header');
            const layoutSider = document.querySelector('.ant-layout-sider');
            header.style.display = 'none';
            layoutSider.style.display = 'none';
            page.style.marginTop = '30px';
            page.insertAdjacentElement('beforebegin', autoNode);
        } else if (drawer) {
            autoNode.style.position = '';
            drawer.insertAdjacentElement('beforebegin', autoNode);
        } else if (modal) {
            autoNode.style.position = '';
            autoNode.style.width = '100%';
            modal.insertAdjacentElement('beforebegin', autoNode);
        }
    } else message.warning(t('There are no fullscreen blocks available at the current location'));
};
const removeNode = (param)=>{
    let { gridRow: blockElement, classId } = param;
    const page = null == blockElement ? void 0 : blockElement.closest('.ant-tb-page');
    const drawer = null == blockElement ? void 0 : blockElement.closest('.ant-drawer-body');
    const parentNode = blockElement.parentNode;
    const tabNav = document.querySelector('.ant-tabs-nav');
    if (tabNav) tabNav.style.display = '';
    Array.from(parentNode.children).forEach((sibling)=>{
        if (sibling !== blockElement) sibling.style.display = '';
        if (sibling.id.includes('DndDescribedBy')) sibling.style.display = 'none';
    });
    if (page) {
        page.style.marginTop = '';
        const layoutSider = document.querySelector('.ant-layout-sider');
        const header = document.querySelector('.ant-page-header');
        layoutSider.style.display = '';
        header.style.display = '';
    } else if (drawer) drawer.style.marginTop = '';
    const autoPage = document.querySelector('.autoPage' + classId);
    if (autoPage) autoPage.parentNode.removeChild(autoPage);
};
export { designerMode, disableRightMenu, fullScreen, ContextMenuItemsProps_rslib_entry_hiddenScrollArea as hiddenScrollArea };
