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__ from "antd";
import * as __WEBPACK_EXTERNAL_MODULE_classnames__ from "classnames";
import * as __WEBPACK_EXTERNAL_MODULE__application_hoc_withDynamicSchemaProps_mjs__ from "../../../application/hoc/withDynamicSchemaProps.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__common_index_mjs__ from "../../common/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__core_index_mjs__ from "../../core/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__hooks_index_mjs__ from "../../hooks/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__hooks_mjs__ from "./hooks.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__List_Decorator_mjs__ from "./List.Decorator.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__List_Designer_mjs__ from "./List.Designer.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__List_Item_mjs__ from "./List.Item.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__List_style_mjs__ from "./List.style.mjs";
const InternalList = (props)=>{
    var _service_data, _field_value;
    const { service } = (0, __WEBPACK_EXTERNAL_MODULE__List_Decorator_mjs__.useListBlockContext)();
    const { run, params } = service;
    const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
    const Designer = (0, __WEBPACK_EXTERNAL_MODULE__hooks_index_mjs__.useDesigner)();
    const meta = null == service ? void 0 : null === (_service_data = service.data) || void 0 === _service_data ? void 0 : _service_data.meta;
    const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
    const [schemaMap] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(new Map());
    const { wrapSSR, componentCls, hashId } = (0, __WEBPACK_EXTERNAL_MODULE__List_style_mjs__["default"])();
    const getSchema = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((key)=>{
        if (!schemaMap.has(key)) schemaMap.set(key, new __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.Schema({
            type: 'object',
            properties: {
                [key]: fieldSchema.properties['item']
            }
        }));
        return schemaMap.get(key);
    }, [
        fieldSchema.properties,
        schemaMap
    ]);
    const onPaginationChange = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((page, pageSize)=>{
        run({
            ...null == params ? void 0 : params[0],
            page: page,
            pageSize: pageSize
        });
    }, [
        run,
        params
    ]);
    return wrapSSR(/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__core_index_mjs__.SchemaComponentOptions, {
        scope: {
            useListItemProps: __WEBPACK_EXTERNAL_MODULE__List_Decorator_mjs__.useListItemProps,
            useListActionBarProps: __WEBPACK_EXTERNAL_MODULE__hooks_mjs__.useListActionBarProps
        },
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)(__WEBPACK_EXTERNAL_MODULE__common_index_mjs__.SortableItem, {
            className: (0, __WEBPACK_EXTERNAL_MODULE_classnames__["default"])('tb-list', componentCls, hashId),
            children: [
                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.List, {
                    ...props,
                    pagination: !!meta && !(meta.count <= meta.pageSize) && {
                        onChange: onPaginationChange,
                        total: (null == meta ? void 0 : meta.count) || 0,
                        pageSize: (null == meta ? void 0 : meta.pageSize) || 10,
                        current: (null == meta ? void 0 : meta.page) || 1
                    },
                    loading: null == service ? void 0 : service.loading,
                    children: (null === (_field_value = field.value) || void 0 === _field_value ? void 0 : _field_value.length) ? field.value.map((item, index)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_schema__.RecursionField, {
                            basePath: field.address,
                            name: index,
                            onlyRenderProperties: true,
                            schema: getSchema(index)
                        }, index)) : null
                }),
                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(Designer, {})
            ]
        })
    }));
};
const List = (0, __WEBPACK_EXTERNAL_MODULE__application_hoc_withDynamicSchemaProps_mjs__.withDynamicSchemaProps)(InternalList);
List.Item = __WEBPACK_EXTERNAL_MODULE__List_Item_mjs__.ListItem;
List.Designer = __WEBPACK_EXTERNAL_MODULE__List_Designer_mjs__.ListDesigner;
List.Decorator = __WEBPACK_EXTERNAL_MODULE__List_Decorator_mjs__.ListBlockProvider;
export { List };
