import './proj-create.css'
import {Link, useNavigate} from "react-router-dom";
import {Breadcrumb, message} from "antd";
import CardProjType from "../../components/card/CardProjType.tsx";
import {IProjCharge, ProjAdditionalType, ProjChargeType} from "../../interfaces/proj/IProj.ts";
import {useEffect, useState} from "react";
import {get} from "../../util/AjaxUtils.ts";

export default function ProjCreate() {
    const [messageApi, contextHolder] = message.useMessage();
    const [charge, setCharge] = useState<IProjCharge>({
        proj: {
            all: 0,
            materialAgent: 0,
            materialAgentUrgent: 0,
            material: 0,
            free: 0,
        },
        additional: {
            pkg: 0,
            videoDemo: 0
        }
    });
    const nav = useNavigate();
    const height = window.innerHeight - 150;

    useEffect(() => {
        get({
            messageApi: messageApi,
            url: '/api/proj/charge/get',
            onSuccess({data}) {
                setCharge(data);
            }
        })
    }, [])

    return (
        <>
            {contextHolder}
            <Breadcrumb
                items={[
                    {title: <Link to={'/'}>首页</Link>},
                    {title: '创建项目'},
                ]}
            />
            <div style={{height: `${height}px`, overflow: 'auto'}}>
                <div className="proj-create">
                    <CardProjType
                        head={'全托管'}
                        bodyLineArray={[
                            {
                                title: '提供的服务：',
                                contents: [
                                    '提供系统搭建',
                                    '系统可在线运行三年',
                                    '软著材料编写',
                                    '软著申报',
                                    '包下证',
                                    '提供系统演示视频文件',
                                    '提供系统安装包',
                                ]
                            },
                            {
                                title: '使用流程：',
                                contents: [
                                    '编写软著名称',
                                    '对搭建系统进行核验',
                                    '接受证书',
                                ]
                            }
                        ]}
                        buyArray={[
                            {
                                id: ProjChargeType.ALL,
                                price: charge.proj.all,
                                handleClick: () => {
                                    nav(`/proj-new/${ProjChargeType.ALL}`)
                                }
                            }
                        ]}
                    />
                    <CardProjType
                        head={'写材料+代理'}
                        bodyLineArray={[
                            {
                                title: '提供的服务：',
                                contents: [
                                    '提供系统搭建平台与客服指导',
                                    '系统可在线运行一年',
                                    '软著材料编写',
                                    '资料补正不限',
                                    '软著申报',
                                    '包下证',
                                ]
                            },
                            {
                                title: '使用流程：',
                                contents: [
                                    '1、按系统操作手册执行',
                                ]
                            }
                        ]}
                        chargeLineArray={[
                            {
                                id: ProjAdditionalType.PKG,
                                price: charge.additional.pkg,
                                title: `安装包 ${charge.additional.pkg / 100} 元`
                            },
                            {
                                id: ProjAdditionalType.VIDEO_DEMO,
                                price: charge.additional.videoDemo,
                                title: `系统演示视频文件 ${charge.additional.videoDemo / 100} 元`
                            }
                        ]}
                        buyArray={[
                            {
                                id: ProjChargeType.MATERIAL_AGENT,
                                label: '普件：',
                                price: charge.proj.materialAgent,
                                handleClick: (_title, additional) => {
                                    nav(`/proj-new/${ProjChargeType.MATERIAL_AGENT}?pkg=${additional.pkg}&videoDemo=${additional.videoDemo}`)
                                }
                            },
                            {
                                id: ProjChargeType.MATERIAL_AGENT_URGENT,
                                label: '加急：',
                                price: charge.proj.materialAgentUrgent,
                                handleClick: (_title, additional) => {
                                    nav(`/proj-new/${ProjChargeType.MATERIAL_AGENT_URGENT}?pkg=${additional.pkg}&videoDemo=${additional.videoDemo}`)
                                }
                            }
                        ]}
                    />
                    <CardProjType
                        head={'写材料'}
                        bodyLineArray={[
                            {
                                title: '提供的服务：',
                                contents: [
                                    '提供系统搭建',
                                    '系统可在线运行三年',
                                    '软著材料编写',
                                    '软著申报',
                                    '包下证',
                                    '提供系统演示视频文件',
                                    '提供系统安装包',
                                ]
                            },
                            {
                                title: '使用流程：',
                                contents: [
                                    '编写软著名称',
                                    '对搭建系统进行核验',
                                    '接受证书',
                                ]
                            }
                        ]}
                        chargeLineArray={[
                            {
                                id: ProjAdditionalType.PKG,
                                price: charge.additional.pkg,
                                title: `安装包 ${charge.additional.pkg / 100} 元`
                            },
                            {
                                id: ProjAdditionalType.VIDEO_DEMO,
                                price: charge.additional.videoDemo,
                                title: `系统演示视频文件 ${charge.additional.videoDemo / 100} 元`
                            }
                        ]}
                        buyArray={[
                            {
                                id: ProjChargeType.MATERIAL,
                                price: charge.proj.material,
                                handleClick: () => {
                                    nav(`/proj-new/${ProjChargeType.MATERIAL}`)
                                }
                            }
                        ]}
                    />
                    <CardProjType
                        head={'免费试用'}
                        bodyLineArray={[
                            {
                                title: '提供的服务：',
                                contents: [
                                    '提供系统搭建平台与客服指导',
                                    '系统可在线存储三天',
                                ]
                            },
                            {
                                title: '使用流程：',
                                contents: [
                                    '按系统操作手册执行',
                                ]
                            }
                        ]}
                        buyArray={[
                            {
                                id: ProjChargeType.FREE,
                                price: charge.proj.free,
                                handleClick: () => {
                                    nav(`/proj-new/${ProjChargeType.FREE}`)
                                }
                            }
                        ]}
                    />
                </div>
            </div>
        </>
    )
}