import React from 'react';
require('./index.css')
export default class PopupComponent extends React.Component{
    constructor(props){
        super(props);
        this.getDefaultPopup = this.getDefaultPopup.bind(this);
    }

    getDefaultPopup(){
        let props = this.props;
        let {popupInfo} = props;
        let arrButton = popupInfo.popupButtons ? popupInfo.popupButtons : []
        let dom = arrButton.map((a,k)=>{
            return a;
        });
        let text = Array.isArray(popupInfo.popupText) ? popupInfo.popupText.map((text,key)=>{
            return <p>
                {text}
            </p>
        }) : popupInfo.popupText
        return (
            <div className={"defaultPopup col333"} style={popupInfo.style}>
                {
                    popupInfo.iconInfo ? <div className={`icon iconfont ${popupInfo.iconInfo}`}/> : null
                }
                {
                    popupInfo.imageInfo && popupInfo.imageInfo.image ? <div className={"image"} style={popupInfo.imageInfo.imageStyle}>
                        <img src={popupInfo.imageInfo.image} alt=""/>
                    </div> : null
                }
                <div className={"defaultPopupText font30"}>
                    {text}
                </div>
                <div className={"defaultPopupButtons font32"}>
                    {dom}
                </div>
            </div>
        )
    }

    render(){
        let {popupInfo} = this.props;
        return (
            <div className={"popupComponent " + (popupInfo.showPopup ? ' ' : 'hide ') + popupInfo.classNames}>
                {popupInfo.popupChild ? popupInfo.popupChild :
                    this.getDefaultPopup()
                }
            </div>
        )
    }
}