import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE_antd_style__ from "antd-style";
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      overflow: hidden;\n      position: relative;\n      .tb-card-item {\n        height: 100%;\n        .ant-card {\n          display: flex;\n          flex-direction: column;\n          height: 100%;\n          .ant-card-body {\n            height: 1px;\n            flex: 1;\n            display: flex;\n            flex-direction: column;\n            overflow: hidden;\n          }\n        }\n      }\n    "
    ]);
    _templateObject = function() {
        return data;
    };
    return data;
}
const FixedBlockContext = /*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].createContext({
    setFixedBlock: ()=>{},
    height: 0,
    fixedBlockUID: false,
    fixedBlockUIDRef: {
        current: false
    },
    inFixedBlock: false
});
const useFixedSchema = ()=>{
    var _field_decoratorProps;
    const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
    const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
    const { setFixedBlock, fixedBlockUID, fixedBlockUIDRef } = useFixedBlock();
    const hasSet = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(false);
    (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
        if (!fixedBlockUIDRef.current || hasSet.current) {
            var _field_decoratorProps;
            setFixedBlock(null != field && null !== (_field_decoratorProps = field.decoratorProps) && void 0 !== _field_decoratorProps && !!_field_decoratorProps.fixedBlock && fieldSchema['x-uid']);
            hasSet.current = true;
        }
    }, [
        null == field ? void 0 : null === (_field_decoratorProps = field.decoratorProps) || void 0 === _field_decoratorProps ? void 0 : _field_decoratorProps.fixedBlock
    ]);
    return fieldSchema['x-uid'] === fixedBlockUID;
};
const useFixedBlock = ()=>(0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(FixedBlockContext);
const FixedBlockWrapper = (props)=>{
    const fixedBlock = useFixedSchema();
    const { height, fixedBlockUID } = useFixedBlock();
    if (!fixedBlock && fixedBlockUID) return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.Fragment, {
        children: props.children
    });
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
        className: "tb-fixed-block",
        style: {
            height: fixedBlockUID ? "calc(100vh - ".concat(height, ")") : void 0
        },
        children: props.children
    });
};
const useStyles = (0, __WEBPACK_EXTERNAL_MODULE_antd_style__.createStyles)((param)=>{
    let { css } = param;
    return {
        fixedBlockCss: css(_templateObject())
    };
});
const FixedBlock = (props)=>{
    const { height } = props;
    const { styles } = useStyles();
    const [fixedBlockUID, _setFixedBlock] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(false);
    const fixedBlockUIDRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(fixedBlockUID);
    const setFixedBlock = (v)=>{
        fixedBlockUIDRef.current = v;
        _setFixedBlock(v);
    };
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(FixedBlockContext.Provider, {
        value: {
            inFixedBlock: true,
            height,
            setFixedBlock,
            fixedBlockUID,
            fixedBlockUIDRef
        },
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
            className: fixedBlockUID ? styles.fixedBlockCss : '',
            style: {
                height: fixedBlockUID ? "calc(100vh - ".concat(height, ")") : void 0
            },
            children: props.children
        })
    });
};
const FixedBlock_rslib_entry_ = FixedBlock;
export { FixedBlockWrapper, FixedBlock_rslib_entry_ as default, useFixedBlock, useFixedSchema };
