import * as React from 'react';
import { Popup } from '@cainiaofe/cn-domain-popup';
import { getPopupContainer } from '../../../../../../../utils/floating-layer.js';
import { AiFieldConfigPanel } from '../../../../toolbar/components/add-field/ai-field/ai-field-config-panel';
import { useModel } from '../../../../../../../utils/mobx-react-simpler/index.js';
export const AiFieldConfigPanelPopup = ({ visible, onVisibleChange, headerRef, editingAiColumn, savingAiColumn, executingColumnTask, handleEditAiConfigSave, handleEditAiConfigCancel, }) => {
    const dataModel = useModel('dataModel');
    const virtualReference = React.useMemo(() => ({
        getBoundingClientRect: () => {
            var _a;
            const rect = (_a = headerRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
            return (rect ||
                {
                    x: 0,
                    y: 0,
                    top: 0,
                    left: 0,
                    right: 0,
                    bottom: 0,
                    width: 0,
                    height: 0,
                });
        },
    }), [headerRef]);
    React.useEffect(() => {
        if (!visible) {
            return;
        }
        const handleClose = () => {
            onVisibleChange(false);
        };
        window.addEventListener('resize', handleClose);
        return () => {
            window.removeEventListener('resize', handleClose);
        };
    }, [onVisibleChange, visible]);
    if (!visible || !headerRef.current) {
        return null;
    }
    return (React.createElement(Popup, { visible: visible, onVisibleChange: onVisibleChange, virtualReference: virtualReference, align: "bl", offset: 8, canCloseByOutSideClick: false, container: getPopupContainer },
        React.createElement(AiFieldConfigPanel, { isEditStatus: true, fieldType: editingAiColumn.fieldType || 'generate-text', fieldLabel: editingAiColumn.columnName, columnCode: editingAiColumn.columnCode, tableId: dataModel.tableId, rawData: dataModel.rawData, initialPromptTemplate: editingAiColumn.promptTemplate, saving: savingAiColumn, executing: executingColumnTask, onSave: handleEditAiConfigSave, onCancel: handleEditAiConfigCancel })));
};
export default AiFieldConfigPanelPopup;
