import { formilyReact } from '@cainiaofe/cn-ui';
import React, { useEffect } from 'react';
import { mapStatus } from '../../mapStatus.js';
const { connect, useFieldSchema, mapProps } = formilyReact;
export const Select = connect((props) => {
    var _a, _b, _c, _d;
    const fieldSchema = useFieldSchema();
    const ComponentUI = (_c = (_b = (_a = window === null || window === void 0 ? void 0 : window.cnLowCodeUtils) === null || _a === void 0 ? void 0 : _a.filterItem) === null || _b === void 0 ? void 0 : _b.getRunTimeItem) === null || _c === void 0 ? void 0 : _c.call(_b, 'Select');
    if (!(ComponentUI === null || ComponentUI === void 0 ? void 0 : ComponentUI.formComponent)) {
        return null;
    }
    useEffect(() => {
        const dom = document.querySelector('#cn-ui-page-scroll-container > div.cn-next-overlay-wrapper.v2.opened > div > span');
        if (dom) {
            dom.click();
        }
    }, []);
    // 解决低码中绑定数据源时，由于异步加载导致dataSource为空的问题
    const dataSource = (fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.enum) || ((_d = fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema['x-component-props']) === null || _d === void 0 ? void 0 : _d.dataSource) || [];
    const extraProps = {};
    if (dataSource.length > 0) {
        extraProps.dataSource = dataSource;
    }
    const FormComponent = ComponentUI.formComponent;
    return (React.createElement(FormComponent, { ...extraProps, ...props, className: "cn-ai-table-schema-field__item--full-width", popupContainer: document.getElementById(fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.name) }));
}, mapProps(mapStatus, {
    dataSource: true,
}));
Select.displayName = 'CnAsyncSelcet';
