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_components__ from "@tachybase/components";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE__application_hoc_withDynamicSchemaProps_mjs__ from "../../../application/hoc/withDynamicSchemaProps.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__block_provider_index_mjs__ from "../../../block-provider/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__modules_blocks_data_blocks_grid_card_hooks_useGridCardBlockParams_mjs__ from "../../../modules/blocks/data-blocks/grid-card/hooks/useGridCardBlockParams.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__GridCard_Decorator_style_mjs__ from "./GridCard.Decorator.style.mjs";
const GridCardBlockContext = /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react__.createContext)({});
GridCardBlockContext.displayName = 'GridCardBlockContext';
const InternalGridCardBlockProvider = (props)=>{
    var _service_data;
    const { resource, service } = (0, __WEBPACK_EXTERNAL_MODULE__block_provider_index_mjs__.useBlockRequestContext)();
    const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
    const { wrapSSR, componentCls, hashId } = (0, __WEBPACK_EXTERNAL_MODULE__GridCard_Decorator_style_mjs__["default"])();
    const form = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>(0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.createForm)({
            readPretty: true
        }), []);
    (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
        if (!(null == service ? void 0 : service.loading)) {
            var _service_data;
            form.setValuesIn(field.address.concat('list').toString(), null == service ? void 0 : null === (_service_data = service.data) || void 0 === _service_data ? void 0 : _service_data.data);
        }
    }, [
        field.address,
        form,
        null == service ? void 0 : null === (_service_data = service.data) || void 0 === _service_data ? void 0 : _service_data.data,
        null == service ? void 0 : service.loading
    ]);
    return wrapSSR(/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(GridCardBlockContext.Provider, {
        value: {
            service,
            resource,
            columnCount: props.columnCount,
            needInfiniteScroll: props.needInfiniteScroll
        },
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_schema__.FormContext.Provider, {
            value: form,
            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_components__.FormLayout, {
                layout: 'vertical',
                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                    className: "".concat(componentCls, " ").concat(hashId),
                    children: props.children
                })
            })
        })
    }));
};
const useCompatGridCardBlockParams = (props)=>{
    const schema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
    if (schema['x-use-decorator-props']) return props.params;
    return (0, __WEBPACK_EXTERNAL_MODULE__modules_blocks_data_blocks_grid_card_hooks_useGridCardBlockParams_mjs__.useGridCardBlockParams)(props);
};
const GridCardBlockProvider = (0, __WEBPACK_EXTERNAL_MODULE__application_hoc_withDynamicSchemaProps_mjs__.withDynamicSchemaProps)((props)=>{
    const params = useCompatGridCardBlockParams(props);
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__block_provider_index_mjs__.BlockProvider, {
        name: "grid-card",
        ...props,
        params: params,
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(InternalGridCardBlockProvider, {
            ...props
        })
    });
});
const useGridCardBlockContext = ()=>(0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(GridCardBlockContext);
const useGridCardItemProps = ()=>({});
export { GridCardBlockContext, GridCardBlockProvider, useGridCardBlockContext, useGridCardItemProps };
