"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.n = function(module) {
        var getter = module && module.__esModule ? function() {
            return module['default'];
        } : function() {
            return module;
        };
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
(()=>{
    __webpack_require__.d = function(exports1, definition) {
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = function(obj, prop) {
        return Object.prototype.hasOwnProperty.call(obj, prop);
    };
})();
(()=>{
    __webpack_require__.r = function(exports1) {
        if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    default: ()=>AIChatModal
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const icons_namespaceObject = require("@ant-design/icons");
const external_antd_namespaceObject = require("antd");
const index_js_namespaceObject = require("../../../icon/index.js");
const external_index_module_js_namespaceObject = require("./index.module.js");
var external_index_module_js_default = /*#__PURE__*/ __webpack_require__.n(external_index_module_js_namespaceObject);
function AIChatModal(param) {
    let { mRef, onGenerateLoad, onReloadWrite } = param;
    const [showModal, setShowModal] = (0, external_react_namespaceObject.useState)(false);
    const [message, setMessage] = (0, external_react_namespaceObject.useState)('');
    const [requestMessage, setRequestMessage] = (0, external_react_namespaceObject.useState)('');
    const [responseMessage, setResponseMessage] = (0, external_react_namespaceObject.useState)('');
    const [sendAllow, setSendAllow] = (0, external_react_namespaceObject.useState)(false);
    const [showLoad, setShowLoad] = (0, external_react_namespaceObject.useState)(false);
    const [loading, setLoading] = (0, external_react_namespaceObject.useState)(false);
    const [loadingText, setLoadingText] = (0, external_react_namespaceObject.useState)('');
    const [welcomeText, setWelcomeText] = (0, external_react_namespaceObject.useState)('TachyAI为您服务~');
    const [status, setStatus] = (0, external_react_namespaceObject.useState)(false);
    const [statusInfo, setStatusInfo] = (0, external_react_namespaceObject.useState)({
        type: 'success',
        msg: '生成完成',
        reload: false
    });
    const examples = [
        {
            id: "1",
            name: '信息表单',
            message: '实现表单组件，展示学生的姓名、年龄、班级和成绩'
        },
        {
            id: "2",
            name: '登录组件',
            message: '帮我实现一个登录组件，含有用户名和密码输入框，以及登录按钮'
        },
        {
            id: "3",
            name: '日期组件',
            message: '帮我实现一个日期组件，含有日期选择器和时间选择器，以及日期格式化功能'
        }
    ];
    const popTitle = '温馨提示';
    const popContent = "TachyAI 是你搭建应用过程的得力助手。";
    (0, external_react_namespaceObject.useEffect)(()=>{
        message ? setSendAllow(true) : setSendAllow(false);
    }, [
        message
    ]);
    const openModal = ()=>{
        setShowModal(true);
    };
    const handleClickExample = (item)=>{
        setMessage(item.message);
    };
    const handleHideModal = ()=>{
        setMessage('');
        setShowModal(false);
    };
    const reloadStatus = async ()=>{
        setStatus(false);
        setShowLoad(true);
        setLoading(true);
        setLoadingText('正在重新写入代码，请稍后');
    };
    const cancelLoad = ()=>{
        setShowLoad(false);
        setLoading(false);
        setStatus(true);
        setStatusInfo({
            type: 'info',
            msg: '取消写入',
            reload: true
        });
    };
    const writeCompleted = async ()=>{
        setShowLoad(false);
        setLoading(false);
        setStatus(true);
        setStatusInfo({
            type: 'success',
            msg: '生成完成',
            reload: false
        });
    };
    const writeError = async ()=>{
        setShowLoad(false);
        setLoading(false);
        setStatus(true);
        setStatusInfo({
            type: 'error',
            msg: '代码写入出错了',
            reload: false
        });
    };
    const requestError = async ()=>{
        setShowLoad(false);
        setLoading(false);
        setStatus(true);
        setStatusInfo({
            type: 'error',
            msg: '请求出错了',
            reload: false
        });
    };
    const changeLoadInfo = async (text)=>{
        setLoadingText(text);
        setShowLoad(true);
        setLoading(true);
    };
    (0, external_react_namespaceObject.useImperativeHandle)(mRef, ()=>({
            openModal,
            handleHideModal,
            cancelLoad,
            reloadStatus,
            writeCompleted,
            writeError,
            changeLoadInfo,
            requestError
        }));
    const handleInputChange = (e)=>{
        setMessage(e.target.value);
    };
    const handleRequestMessage = async ()=>{
        setStatus(false);
        setRequestMessage(message);
        setResponseMessage('');
        setMessage('');
        setShowLoad(false);
        setLoading(false);
        setTimeout(async ()=>{
            setResponseMessage('好的，TachyAI为您服务~');
            await onGenerateLoad(message);
        }, 1000);
    };
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
        className: "".concat(external_index_module_js_default().AIChatModal, " ").concat(showModal ? external_index_module_js_default().showModal : external_index_module_js_default().hideModal),
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
            className: external_index_module_js_default().modalContent,
            children: [
                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
                    className: external_index_module_js_default().modalHeader,
                    children: [
                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
                            className: external_index_module_js_default().title,
                            children: [
                                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("svg", {
                                    className: external_index_module_js_default().marsailogo,
                                    viewBox: "0 0 1024 1024",
                                    version: "1.1",
                                    xmlns: "http://www.w3.org/2000/svg",
                                    children: [
                                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("path", {
                                            d: "M370.812121 400.290909c-21.721212 0-38.787879 17.066667-38.787879 38.787879V605.090909c0 21.721212 17.066667 38.787879 38.787879 38.787879s38.787879-17.066667 38.787879-38.787879V439.078788c0-21.721212-17.066667-38.787879-38.787879-38.787879zM712.145455 417.357576c-15.515152-15.515152-38.787879-15.515152-54.303031 0L589.575758 485.624242c-9.309091 9.309091-13.963636 21.721212-12.412122 34.133334-1.551515 12.412121 3.10303 24.824242 12.412122 32.581818l68.266666 68.266667c7.757576 7.757576 17.066667 10.860606 27.927273 10.860606s20.169697-4.654545 27.927273-10.860606 10.860606-17.066667 10.860606-27.927273-4.654545-20.169697-10.860606-27.927273l-46.545455-46.545454 46.545455-46.545455c13.963636-13.963636 13.963636-38.787879-1.551515-54.30303z",
                                            fill: "#7d33ff"
                                        }),
                                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("path", {
                                            d: "M788.169697 228.072727c-57.406061-27.927273-161.357576-48.09697-273.066667-49.648485-111.709091 1.551515-217.212121 20.169697-274.618182 49.648485-88.436364 41.890909-124.121212 128.775758-124.121212 297.890909 0 134.981818 37.236364 232.727273 100.848485 266.860606 82.230303 41.890909 156.70303 55.854545 296.339394 55.854546 141.187879 0 215.660606-13.963636 294.787879-54.30303 65.163636-35.684848 102.4-134.981818 102.4-268.412122 0-167.563636-37.236364-256-122.569697-297.890909z m44.993939 296.339394c0 114.812121-31.030303 183.078788-60.509091 200.145455-58.957576 29.478788-117.915152 44.993939-259.10303 44.993939-139.636364 0-200.145455-15.515152-260.654545-44.993939-29.478788-15.515152-58.957576-85.333333-58.957576-200.145455 0-134.981818 23.272727-200.145455 79.127273-229.624242 46.545455-23.272727 142.739394-40.339394 240.484848-40.339394 97.745455 1.551515 193.939394 18.618182 240.484849 40.339394 55.854545 29.478788 79.127273 94.642424 79.127272 229.624242z",
                                            fill: "#7d33ff"
                                        })
                                    ]
                                }),
                                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
                                    children: "TachyAI"
                                })
                            ]
                        }),
                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("button", {
                            className: external_index_module_js_default().closeButton,
                            onClick: handleHideModal,
                            children: "\xd7"
                        })
                    ]
                }),
                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
                    className: external_index_module_js_default().modalBody,
                    children: [
                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
                            className: external_index_module_js_default().chatContent,
                            children: [
                                !requestMessage && !responseMessage && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                                    className: external_index_module_js_default().welcomeText,
                                    children: welcomeText
                                }),
                                requestMessage && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
                                    className: external_index_module_js_default().chatItem,
                                    children: [
                                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
                                            className: external_index_module_js_default().chatInfo,
                                            children: [
                                                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                                                    className: external_index_module_js_default().chatName,
                                                    children: "User"
                                                }),
                                                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                                                    className: external_index_module_js_default().avatar,
                                                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_js_namespaceObject.Icon, {
                                                        type: "useroutlined"
                                                    })
                                                })
                                            ]
                                        }),
                                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                                            className: external_index_module_js_default().chatText,
                                            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                                                className: external_index_module_js_default().chatMessage,
                                                children: requestMessage
                                            })
                                        })
                                    ]
                                }),
                                responseMessage && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
                                    className: external_index_module_js_default().chatResponce,
                                    children: [
                                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
                                            className: external_index_module_js_default().chatInfo,
                                            children: [
                                                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                                                    className: external_index_module_js_default().avatar,
                                                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_js_namespaceObject.Icon, {
                                                        type: "robotoutlined"
                                                    })
                                                }),
                                                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                                                    className: external_index_module_js_default().chatName,
                                                    children: "TachyAI"
                                                })
                                            ]
                                        }),
                                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                                            className: external_index_module_js_default().chatText,
                                            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                                                className: external_index_module_js_default().chatMessage,
                                                children: responseMessage
                                            })
                                        })
                                    ]
                                }),
                                showLoad && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
                                    className: external_index_module_js_default().chatLoad,
                                    children: [
                                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                                            className: external_index_module_js_default().chatText,
                                            children: loadingText
                                        }),
                                        loading && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                                            className: external_index_module_js_default().load,
                                            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Spin, {
                                                size: "small"
                                            })
                                        })
                                    ]
                                }),
                                status && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                                    className: external_index_module_js_default().chatLoad,
                                    children: statusInfo.reload ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Alert, {
                                        type: statusInfo.type,
                                        showIcon: true,
                                        message: statusInfo.msg,
                                        action: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Popover, {
                                            placement: "top",
                                            content: "重新写入代码",
                                            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Button, {
                                                style: {
                                                    marginLeft: '5px'
                                                },
                                                type: "primary",
                                                size: "small",
                                                shape: "circle",
                                                icon: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icons_namespaceObject.ReloadOutlined, {}),
                                                onClick: onReloadWrite
                                            })
                                        })
                                    }) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Alert, {
                                        type: statusInfo.type,
                                        showIcon: true,
                                        message: statusInfo.msg
                                    })
                                })
                            ]
                        }),
                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                            className: external_index_module_js_default().chatExamples,
                            children: examples.map((item)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("button", {
                                    className: external_index_module_js_default().chatExampleItem,
                                    onClick: ()=>handleClickExample(item),
                                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
                                        children: item.name
                                    })
                                }, item.id))
                        }),
                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
                            className: external_index_module_js_default().chatInput,
                            children: [
                                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                                    className: external_index_module_js_default().chatOtherInfo,
                                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Popover, {
                                        placement: "top",
                                        title: popTitle,
                                        content: popContent,
                                        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icons_namespaceObject.BellOutlined, {})
                                    })
                                }),
                                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                                    className: external_index_module_js_default().inputBox,
                                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("input", {
                                        maxLength: 80,
                                        type: "text",
                                        placeholder: "可以在这里描述你需要的内容",
                                        value: message,
                                        onChange: handleInputChange
                                    })
                                }),
                                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                                    className: external_index_module_js_default().sendBtn,
                                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Button, {
                                        disabled: !sendAllow,
                                        shape: "circle",
                                        type: "primary",
                                        icon: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icons_namespaceObject.ArrowUpOutlined, {}),
                                        onClick: handleRequestMessage
                                    })
                                })
                            ]
                        })
                    ]
                })
            ]
        })
    });
}
var __webpack_export_target__ = exports;
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
    value: true
});
