import { jsx } from "react/jsx-runtime";
import "react";
import { useField, useFieldSchema } from "@tachybase/schema";
import { useTranslation } from "react-i18next";
import { useBlockRequestContext } from "../../../block-provider/BlockProvider.mjs";
import { SchemaSettingsSwitchItem } from "../../../schema-settings/index.mjs";
import { useDesignable } from "../../hooks/index.mjs";
import { useFixedBlock } from "./FixedBlock.mjs";
import { useIsBlockInPage } from "./hooks/useIsBlockInPage.mjs";
const FixedBlockDesignerItem = ()=>{
    var _fieldSchema_xdecoratorprops;
    const field = useField();
    const { t } = useTranslation();
    const fieldSchema = useFieldSchema();
    const { dn } = useDesignable();
    const { inFixedBlock } = useFixedBlock();
    const { isBlockInPage } = useIsBlockInPage();
    const { service } = useBlockRequestContext();
    if (!isBlockInPage() || !inFixedBlock) return null;
    return /*#__PURE__*/ jsx(SchemaSettingsSwitchItem, {
        title: t('Fix block'),
        checked: null == (_fieldSchema_xdecoratorprops = fieldSchema['x-decorator-props']) ? void 0 : _fieldSchema_xdecoratorprops.fixedBlock,
        onChange: async (fixedBlock)=>{
            var _service_refresh;
            const decoratorProps = {
                ...fieldSchema['x-decorator-props'],
                fixedBlock
            };
            await dn.emit('patch', {
                schema: {
                    ['x-uid']: fieldSchema['x-uid'],
                    'x-decorator-props': decoratorProps
                }
            });
            field.decoratorProps = fieldSchema['x-decorator-props'] = decoratorProps;
            null == service || null == (_service_refresh = service.refresh) || _service_refresh.call(service);
        }
    });
};
export { FixedBlockDesignerItem };
