import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
import * as __WEBPACK_EXTERNAL_MODULE__ant_design_icons__ from "@ant-design/icons";
import * as __WEBPACK_EXTERNAL_MODULE_antd__ from "antd";
import * as __WEBPACK_EXTERNAL_MODULE__icon_index_mjs__ from "../../../icon/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__index_module_mjs__ from "./index.module.mjs";
function AIChatModal(param) {
    let { mRef, onGenerateLoad, onReloadWrite } = param;
    const [showModal, setShowModal] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(false);
    const [message, setMessage] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)('');
    const [requestMessage, setRequestMessage] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)('');
    const [responseMessage, setResponseMessage] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)('');
    const [sendAllow, setSendAllow] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(false);
    const [showLoad, setShowLoad] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(false);
    const [loading, setLoading] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(false);
    const [loadingText, setLoadingText] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)('');
    const [welcomeText, setWelcomeText] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)('TachyAI为您服务~');
    const [status, setStatus] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(false);
    const [statusInfo, setStatusInfo] = (0, __WEBPACK_EXTERNAL_MODULE_react__.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, __WEBPACK_EXTERNAL_MODULE_react__.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, __WEBPACK_EXTERNAL_MODULE_react__.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, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
        className: "".concat(__WEBPACK_EXTERNAL_MODULE__index_module_mjs__["default"].AIChatModal, " ").concat(showModal ? __WEBPACK_EXTERNAL_MODULE__index_module_mjs__["default"].showModal : __WEBPACK_EXTERNAL_MODULE__index_module_mjs__["default"].hideModal),
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("div", {
            className: __WEBPACK_EXTERNAL_MODULE__index_module_mjs__["default"].modalContent,
            children: [
                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("div", {
                    className: __WEBPACK_EXTERNAL_MODULE__index_module_mjs__["default"].modalHeader,
                    children: [
                        /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("div", {
                            className: __WEBPACK_EXTERNAL_MODULE__index_module_mjs__["default"].title,
                            children: [
                                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("svg", {
                                    className: __WEBPACK_EXTERNAL_MODULE__index_module_mjs__["default"].marsailogo,
                                    viewBox: "0 0 1024 1024",
                                    version: "1.1",
                                    xmlns: "http://www.w3.org/2000/svg",
                                    children: [
                                        /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.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, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.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, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("span", {
                                    children: "TachyAI"
                                })
                            ]
                        }),
                        /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("button", {
                            className: __WEBPACK_EXTERNAL_MODULE__index_module_mjs__["default"].closeButton,
                            onClick: handleHideModal,
                            children: "\xd7"
                        })
                    ]
                }),
                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("div", {
                    className: __WEBPACK_EXTERNAL_MODULE__index_module_mjs__["default"].modalBody,
                    children: [
                        /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("div", {
                            className: __WEBPACK_EXTERNAL_MODULE__index_module_mjs__["default"].chatContent,
                            children: [
                                !requestMessage && !responseMessage && /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                                    className: __WEBPACK_EXTERNAL_MODULE__index_module_mjs__["default"].welcomeText,
                                    children: welcomeText
                                }),
                                requestMessage && /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("div", {
                                    className: __WEBPACK_EXTERNAL_MODULE__index_module_mjs__["default"].chatItem,
                                    children: [
                                        /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("div", {
                                            className: __WEBPACK_EXTERNAL_MODULE__index_module_mjs__["default"].chatInfo,
                                            children: [
                                                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                                                    className: __WEBPACK_EXTERNAL_MODULE__index_module_mjs__["default"].chatName,
                                                    children: "User"
                                                }),
                                                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                                                    className: __WEBPACK_EXTERNAL_MODULE__index_module_mjs__["default"].avatar,
                                                    children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__icon_index_mjs__.Icon, {
                                                        type: "useroutlined"
                                                    })
                                                })
                                            ]
                                        }),
                                        /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                                            className: __WEBPACK_EXTERNAL_MODULE__index_module_mjs__["default"].chatText,
                                            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                                                className: __WEBPACK_EXTERNAL_MODULE__index_module_mjs__["default"].chatMessage,
                                                children: requestMessage
                                            })
                                        })
                                    ]
                                }),
                                responseMessage && /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("div", {
                                    className: __WEBPACK_EXTERNAL_MODULE__index_module_mjs__["default"].chatResponce,
                                    children: [
                                        /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("div", {
                                            className: __WEBPACK_EXTERNAL_MODULE__index_module_mjs__["default"].chatInfo,
                                            children: [
                                                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                                                    className: __WEBPACK_EXTERNAL_MODULE__index_module_mjs__["default"].avatar,
                                                    children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__icon_index_mjs__.Icon, {
                                                        type: "robotoutlined"
                                                    })
                                                }),
                                                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                                                    className: __WEBPACK_EXTERNAL_MODULE__index_module_mjs__["default"].chatName,
                                                    children: "TachyAI"
                                                })
                                            ]
                                        }),
                                        /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                                            className: __WEBPACK_EXTERNAL_MODULE__index_module_mjs__["default"].chatText,
                                            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                                                className: __WEBPACK_EXTERNAL_MODULE__index_module_mjs__["default"].chatMessage,
                                                children: responseMessage
                                            })
                                        })
                                    ]
                                }),
                                showLoad && /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("div", {
                                    className: __WEBPACK_EXTERNAL_MODULE__index_module_mjs__["default"].chatLoad,
                                    children: [
                                        /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                                            className: __WEBPACK_EXTERNAL_MODULE__index_module_mjs__["default"].chatText,
                                            children: loadingText
                                        }),
                                        loading && /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                                            className: __WEBPACK_EXTERNAL_MODULE__index_module_mjs__["default"].load,
                                            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Spin, {
                                                size: "small"
                                            })
                                        })
                                    ]
                                }),
                                status && /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                                    className: __WEBPACK_EXTERNAL_MODULE__index_module_mjs__["default"].chatLoad,
                                    children: statusInfo.reload ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Alert, {
                                        type: statusInfo.type,
                                        showIcon: true,
                                        message: statusInfo.msg,
                                        action: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Popover, {
                                            placement: "top",
                                            content: "重新写入代码",
                                            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Button, {
                                                style: {
                                                    marginLeft: '5px'
                                                },
                                                type: "primary",
                                                size: "small",
                                                shape: "circle",
                                                icon: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__ant_design_icons__.ReloadOutlined, {}),
                                                onClick: onReloadWrite
                                            })
                                        })
                                    }) : /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Alert, {
                                        type: statusInfo.type,
                                        showIcon: true,
                                        message: statusInfo.msg
                                    })
                                })
                            ]
                        }),
                        /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                            className: __WEBPACK_EXTERNAL_MODULE__index_module_mjs__["default"].chatExamples,
                            children: examples.map((item)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("button", {
                                    className: __WEBPACK_EXTERNAL_MODULE__index_module_mjs__["default"].chatExampleItem,
                                    onClick: ()=>handleClickExample(item),
                                    children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("span", {
                                        children: item.name
                                    })
                                }, item.id))
                        }),
                        /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("div", {
                            className: __WEBPACK_EXTERNAL_MODULE__index_module_mjs__["default"].chatInput,
                            children: [
                                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                                    className: __WEBPACK_EXTERNAL_MODULE__index_module_mjs__["default"].chatOtherInfo,
                                    children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Popover, {
                                        placement: "top",
                                        title: popTitle,
                                        content: popContent,
                                        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__ant_design_icons__.BellOutlined, {})
                                    })
                                }),
                                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                                    className: __WEBPACK_EXTERNAL_MODULE__index_module_mjs__["default"].inputBox,
                                    children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("input", {
                                        maxLength: 80,
                                        type: "text",
                                        placeholder: "可以在这里描述你需要的内容",
                                        value: message,
                                        onChange: handleInputChange
                                    })
                                }),
                                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                                    className: __WEBPACK_EXTERNAL_MODULE__index_module_mjs__["default"].sendBtn,
                                    children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Button, {
                                        disabled: !sendAllow,
                                        shape: "circle",
                                        type: "primary",
                                        icon: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__ant_design_icons__.ArrowUpOutlined, {}),
                                        onClick: handleRequestMessage
                                    })
                                })
                            ]
                        })
                    ]
                })
            ]
        })
    });
}
export { AIChatModal as default };
