"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.AiFieldConfigPanelPopup = void 0;
const React = __importStar(require("react"));
const cn_domain_popup_1 = require("@cainiaofe/cn-domain-popup");
const floating_layer_1 = require("../../../../../../../utils/floating-layer.js");
const ai_field_config_panel_1 = require("../../../../toolbar/components/add-field/ai-field/ai-field-config-panel");
const mobx_react_simpler_1 = require("../../../../../../../utils/mobx-react-simpler/index.js");
const AiFieldConfigPanelPopup = ({ visible, onVisibleChange, headerRef, editingAiColumn, savingAiColumn, executingColumnTask, handleEditAiConfigSave, handleEditAiConfigCancel, }) => {
    const dataModel = (0, mobx_react_simpler_1.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(cn_domain_popup_1.Popup, { visible: visible, onVisibleChange: onVisibleChange, virtualReference: virtualReference, align: "bl", offset: 8, canCloseByOutSideClick: false, container: floating_layer_1.getPopupContainer },
        React.createElement(ai_field_config_panel_1.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 })));
};
exports.AiFieldConfigPanelPopup = AiFieldConfigPanelPopup;
exports.default = exports.AiFieldConfigPanelPopup;
