import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import "react";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE_antd__ from "antd";
import * as __WEBPACK_EXTERNAL_MODULE_react_i18next__ from "react-i18next";
import * as __WEBPACK_EXTERNAL_MODULE__async_data_provider_index_mjs__ from "../../../../async-data-provider/index.mjs";
const PreviewTable = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.observer)(()=>{
    const { data: res, loading, error } = (0, __WEBPACK_EXTERNAL_MODULE__async_data_provider_index_mjs__.useAsyncData)();
    const { data } = res || {};
    const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
    const form = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useForm)();
    const fields = form.values.fields || [];
    const titleMp = fields.reduce((mp, field)=>{
        var _field_uiSchema;
        mp[field.name] = null == field ? void 0 : null === (_field_uiSchema = field.uiSchema) || void 0 === _field_uiSchema ? void 0 : _field_uiSchema.title;
        return mp;
    }, {});
    const columns = error ? [] : Object.keys((null == data ? void 0 : data[0]) || {}).map((col)=>{
        const title = titleMp[col];
        return {
            title: __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.Schema.compile(title || col, {
                t
            }),
            dataIndex: col,
            key: col
        };
    });
    const dataSource = error ? [] : null == data ? void 0 : data.map((record, index)=>{
        const compiledRecord = Object.entries(record).reduce((mp, param)=>{
            let [key, val] = param;
            if ('string' != typeof val) {
                mp[key] = val;
                return mp;
            }
            const compiled = __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.Schema.compile(val, {
                t
            });
            mp[key] = t(compiled);
            return mp;
        }, {});
        return {
            ...compiledRecord,
            key: index
        };
    });
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Table, {
        bordered: true,
        dataSource: dataSource,
        columns: columns,
        scroll: {
            x: 150 * columns.length,
            y: 300
        },
        loading: loading,
        rowKey: "key"
    });
}, {
    displayName: 'PreviewTable'
});
export { PreviewTable };
