import './card-agent.css';
import {Image} from "antd";
import {errorImage} from "../../util/CommonUtil.ts";
import {AgentMedalEnum, IAgent} from "../../interfaces/card/ICardProj.ts";
import {downloadUrl} from "../../util/AjaxUtils.ts";

export default function CardAgent(props: IAgent) {

    const renderMedal = () => {
        if (props.medal == AgentMedalEnum.GOLD) {
            return <span className="card-agent-medal gold">金牌</span>;
        }
        if (props.medal == AgentMedalEnum.SILVER) {
            return <span className="card-agent-medal silver">银牌</span>;
        }
        if (props.medal == AgentMedalEnum.BRONZE) {
            return <span className="card-agent-medal bronze">铜牌</span>;
        }
        return <span className="card-agent-medal">普通</span>;
    }

    return (
        <div className={props.selected ? 'card-agent selected' : 'card-agent'} onClick={() => {
            props.handleSelect();
        }}>
            <div className="card-agent-head">
                {props.logo ? <Image width={30} src={downloadUrl(props.logo.split(',')[0], false)} preview={false} fallback={errorImage}/> : <></>}
                <span className="card-agent-title">{props.name}</span>
                {renderMedal()}
            </div>
            <div className="card-agent-body">
                <div className="card-agent-body-content" dangerouslySetInnerHTML={{__html: props.desc}}></div>
                <Image width={140} height={100} src={props.certificateImg} preview={false} fallback={errorImage}/>
            </div>
        </div>
    )
}