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_antd_style__ from "antd-style";
import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash";
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";
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      .ant-description-input {\n        line-height: 34px;\n      }\n      .ant-formily-item-feedback-layout-loose {\n        margin-bottom: 12px;\n      }\n    "
    ]);
    _templateObject = function() {
        return data;
    };
    return data;
}
const useStyles = (0, __WEBPACK_EXTERNAL_MODULE_antd_style__.createStyles)((param)=>{
    let { css } = param;
    return {
        container: css(_templateObject())
    };
});
const ListBlockContext = /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react__.createContext)({});
ListBlockContext.displayName = 'ListBlockContext';
const InternalListBlockProvider = (props)=>{
    var _service_data;
    const { resource, service } = (0, __WEBPACK_EXTERNAL_MODULE__block_provider_index_mjs__.useBlockRequestContext)();
    const { styles } = useStyles();
    const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
    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 /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(ListBlockContext.Provider, {
        value: {
            service,
            resource
        },
        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: styles.container,
                    children: props.children
                })
            })
        })
    });
};
const ListBlockProvider = (0, __WEBPACK_EXTERNAL_MODULE__application_hoc_withDynamicSchemaProps_mjs__.withDynamicSchemaProps)((props)=>{
    const { params } = props;
    const { filter: parsedFilter } = (0, __WEBPACK_EXTERNAL_MODULE__block_provider_index_mjs__.useParsedFilter)({
        filterOption: null == params ? void 0 : params.filter
    });
    const paramsWithFilter = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
            ...params,
            filter: parsedFilter
        }), [
        parsedFilter,
        params
    ]);
    if (__WEBPACK_EXTERNAL_MODULE_lodash__["default"].isEmpty(parsedFilter) && !__WEBPACK_EXTERNAL_MODULE_lodash__["default"].isEmpty(null == params ? void 0 : params.filter)) return null;
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__block_provider_index_mjs__.BlockProvider, {
        name: "list",
        ...props,
        params: paramsWithFilter,
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(InternalListBlockProvider, {
            ...props
        })
    });
});
const useListBlockContext = ()=>(0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(ListBlockContext);
const useListItemProps = ()=>({});
export { ListBlockContext, ListBlockProvider, useListBlockContext, useListItemProps };
