import { connect, useRequest } from "umi";
import type { ConnectState } from "@/models/connect";
import session from "@/utils/session";
import { Button, Tooltip } from "antd";
import { useState } from "react";

type DetailProps = {
    props: any
    descText?: any
    showQuestion?: any
    showAI?: boolean
    AIFun?: any // 点击AI按钮实际调用的方法
}
const PageTitleBox = ({ props, descText, showQuestion, showAI, AIFun }: DetailProps) => {
    const { route } = props

    const [headerObj, setHeaderObj] = useState<any>()

    // 拿到headerTitle
    const { loading: headerTitleLoading, data: tableHeaderObj } = useRequest(async () => {
        const menu = session.get('menu')
        if (menu && menu.length > 0) {
            let obj: any = {}
            menu.forEach((item: any) => {
                if (item.path === route.path) {
                    obj = item
                }
            })
            console.log('obj', obj);
            setHeaderObj(obj)
            return obj
        }
        return undefined
    })

    return (
        <div>
            <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
                <span style={{ color: "#1890ff", fontSize: 14, fontWeight: 600 }}>{headerObj?.name || ''}</span>
                {
                    headerObj?.SYSTEMMODULE_DESC ?
                        <Tooltip title={headerObj?.SYSTEMMODULE_DESC}>
                            <div style={{
                                display: 'flex', alignItems: 'center', justifyContent: 'center', width: '20px', height: '20px',
                                padding: '6px', border: '1px solid #ccc', color: '#ccc', borderRadius: '50%', cursor: 'pointer', marginLeft: '4px'
                            }}>?</div>
                        </Tooltip> : ''
                }
                {descText || ''}
                {
                    showAI ?
                        <Button type="primary" style={{ marginLeft: '16px' }} onClick={() => {
                            if (AIFun) {
                                AIFun()
                            }
                        }}>AI分析</Button> : ""
                }
                {/* {
                    showQuestion ?
                        <Tooltip title={descText}>
                            <div style={{
                                display: 'flex', alignItems: 'center', justifyContent: 'center', width: '20px', height: '20px',
                                padding: '6px', border: '1px solid #ccc', color: '#ccc', borderRadius: '50%', cursor: 'pointer', marginLeft: '4px'
                            }}>?</div>
                        </Tooltip> : ''
                } */}
            </div>
        </div>
    )
}

export default connect(({ user, }: ConnectState) => ({
    currentUser: user.currentUser,
}))(PageTitleBox);
