class ImageSize{
    constructor(){
    }
    
    static getTip(format){
        let result = '';
        if(format){
            let arr = format.split(',');
            let w = arr[0];
            let h = '';
            if(arr.length>=2){
                h = arr[1];
            }
            w = ImageSize.parseWH(w);
            h = ImageSize.parseWH(h);
            result += ImageSize.getWHTip(w, '宽度') + '，';
            result += ImageSize.getWHTip(h, '高度');
        }
        return result;
    }
    
    static getWHTip(wh, prefix = '', suffix='px'){
        let result = prefix;
        if(wh === null || wh.length==0){
            result += '不限';
        }
        else{
            for(let i=0; i<wh.length;i++){
                let item = wh[i];
                if(item.v1 && !item.v2){
                    result += item.v1 + suffix;
                }
                else if(!item.v1 && item.v2){
                    result += item.v2 + suffix;
                }
                else if(item.v1 === item.v2){
                    result += item.v1 + suffix;
                }
                else if(parseInt(item.v1) < parseInt(item.v2)){
                    result += item.v1 + suffix + '~' + item.v2 + suffix;
                }
                else{
                    result += item.v2 + suffix + '~' + item.v1 + suffix;
                }
                if(i<wh.length-1){
                    result += '或'
                }
            }
        }
        return result;
    }
    
    static parseWH(wh) {
        let caseObj = [];
        if(wh){
            let caseList = wh.split('|');   
            for(let i=0; i<caseList.length;i++){
                let c = caseList[i];
                if(c){
                    let r = c.split('-');
                    let whobj = {v1:'', v2:''};
                    whobj.v1 = r[0];
                    if(r.length>=2){
                        whobj.v2 = r[1];
                    }
                    caseObj.push(whobj);
                }
            }
        }
        return caseObj;
    }
}
export default ImageSize;