import './card-proj.css';
import {
    DownloadOutlined,
    EditOutlined,
    EyeOutlined,
    FolderOutlined,
    SearchOutlined,
    SettingOutlined,
    ClockCircleOutlined,
    LoadingOutlined,
    CheckOutlined,
    WarningOutlined,
    CloseCircleOutlined,
    CreditCardOutlined
} from '@ant-design/icons';
import {Button, ConfigProvider, Tag} from 'antd';
import {GenerateStatus, IProj, PayStatus} from "../../interfaces/proj/IProj.ts";

export default function CardProj(props: { item: IProj }) {
    const data = props.item;

    /**
     * 生成状态
     */
    const renderGenerateStatus = () => {
        if (data.generateStatus == GenerateStatus.PENDING) {
            return <Tag color="cyan"><ClockCircleOutlined/> 等待生成</Tag>
        }
        if (data.generateStatus == GenerateStatus.GENERATING) {
            return <Tag color="magenta"><LoadingOutlined/> 正在生成</Tag>
        }
        if (data.generateStatus == GenerateStatus.SUCCESS) {
            return <Tag color="green"><CheckOutlined/> 生成成功</Tag>
        }
        if (data.generateStatus == GenerateStatus.FAILED) {
            return <Tag color="red"><WarningOutlined/> 生成失败</Tag>
        }
        if (data.generateStatus == GenerateStatus.NONE) {
            return <Tag color="cyan">未生成</Tag>
        }
        return <Tag color="red"><CloseCircleOutlined/> 错误</Tag>
    }

    const renderOption = () => {
        if(data.payStatus == PayStatus.UNPAID) {
            return (
                <>
                    <div className="option">
                        <Button size="small" type="text"><CreditCardOutlined /> 待付款</Button>
                    </div>
                </>
            )
        }
        return (
            <>
                <div className="option">
                    <Button size="small" type="text"><SettingOutlined/> 登录界面设置</Button>
                    <Button size="small" type="text"><SettingOutlined/> 系统菜单管理(0)</Button>
                    <Button size="small" type="text"><SettingOutlined/> 菜单排序(0)</Button>
                </div>
                {
                    data.generateStatus == GenerateStatus.SUCCESS ? (
                        <div className="option">
                            <Button size="small" type="text"><DownloadOutlined/> 申请表</Button>
                            <Button size="small" type="text"><DownloadOutlined/> 操作手册</Button>
                            <Button size="small" type="text"><DownloadOutlined/> 代码压缩包</Button>
                            <Button size="small" type="text"><DownloadOutlined/> 代码文档</Button>
                        </div>
                    ) : <></>
                }
            </>
        )
    }

    return (
        <div className="card-proj">
            <div className="title">
                <div className="left">
                    <a href="/#">{data.projName}</a>
                </div>
                <div className="right">
                    <span className="context">上下文：{data.projContext}</span>
                    <span className="date">{data.gmtCreate}</span>
                    <span className="status">{renderGenerateStatus()}</span>
                </div>
            </div>
            <hr/>
            <div className="body">
                <div className="line">
                    <div className="left">
                        <span>金额￥：{data.payment / 100}</span>
                    </div>
                    <div className="right">
                        <span>
                            <EditOutlined/>
                            <a href="/#">编辑</a>
                        </span>
                        <span>
                            <SearchOutlined/>
                            <a href="/#">查看</a>
                        </span>
                        <span>
                            <EyeOutlined/>
                            <a href="/#" onClick={(e) => {
                                e.stopPropagation();
                                window.open(data.previewUrl, '_blank')
                            }}>预览</a>
                        </span>
                    </div>
                </div>
                <div className="line">
                    <div className="left"></div>
                    <div className="right">
                        <span>
                            <FolderOutlined/>
                            <a href="/#">目录</a>
                        </span>
                    </div>
                </div>
            </div>
            <hr/>
            <div className="foot">
                <ConfigProvider theme={{
                    components: {
                        Button: {
                            contentFontSizeSM: 12,
                        }
                    }
                }}>
                    {renderOption()}
                </ConfigProvider>
            </div>
        </div>
    )
}