import Style from "ol/style/Style";
import Fill from "ol/style/Fill";
import Stroke from "ol/style/Stroke";
import Text from "ol/style/Text";
import Icon from "ol/style/Icon";
import no_img from '../../../assets/status/no_img.png'
import Circle from "ol/style/Circle";



let cacheMiniStyle = {}
export function miniStyle(f){
    let code = f.get("code");
    let index = code.indexOf("-")
    if(index > -1){
        code = code.substring(index+1, code.length)
    }
    let key = f.get("noImg") + code
    let cache = cacheMiniStyle[key]
    if(cache){
        return cache
    }

    let strokeColor = "#3B9DCE"
    let fillColor = "#ffffff30"
    let fontStrokeColor = "#FFFFFF"
    let fontFillColor = "#ef063c"

    if(f.get("noImg")){
        fontFillColor = "#cccccc00"
        fontStrokeColor = "#FFFFFF00"
    }


    let style = new Style({
        image: new Circle({
            radius: 5,                             // 半径
            stroke: new Stroke({           // 边界样式
                color: strokeColor,                    // 边界颜色
                width: 1                           // 边界宽度
            }),
            fill: new Fill({               // 填充样式
                color: fillColor                      // 填充颜色
            })
        }),

        text: new Text({
            text:code,
            stroke: new Stroke({
                color: fontStrokeColor,
                width: 2,
            }),
            fill: new Fill({
                color: fontFillColor,
            }),
            font: "12px sans-serif",
            offsetY:-8
        }),
    });
    cacheMiniStyle[key] = style;
    return style
}


let cacheMiniSelectStyle2 = {}
export function miniSelectStyle(f){
    let code = f.get("code");
    let index = code.indexOf("-")
    if(index > -1){
        code = code.substring(index+1, code.length)
    }
    let key = f.get("noImg") + code

    let cache = cacheMiniSelectStyle2[key]
    if(cache){
        return cache
    }

    let fontFillColor = "#ef063c"

    if(f.get("noImg")){
        fontFillColor = "#cccccc00"
    }


    let style = new Style({
        image: new Circle({
            radius: 5,                             // 半径
            stroke: new Stroke({           // 边界样式
                color: "#ffffff",                    // 边界颜色
                width: 1                           // 边界宽度
            }),
            fill: new Fill({               // 填充样式
                color: "#1AA3FF"                       // 填充颜色
            })
        }),


        text: new Text({
            text:code,
            stroke: new Stroke({
                color: "#FFFFFF",
                width: 2,
            }),
            fill: new Fill({
                color: fontFillColor,
            }),
            font: "20px sans-serif",
            offsetY:-20
        }),
    });
    cacheMiniSelectStyle2[key] = style;
    return style
}

let cacheMiniStyle2 = {}

export function miniStyle2(f){

    let cache = cacheMiniStyle2[f.get("noImg")]
    if(cache){
        return cache
    }

    let strokeColor = "#5ed907"
    let fillColor = "#ffffff30"

    if(f.get("noImg")){
        strokeColor = "#31270f"
    }



    let style = new Style({
        image: new Circle({
            radius: 5,                             // 半径
            stroke: new Stroke({           // 边界样式
                color: strokeColor,                    // 边界颜色
                width: 1                           // 边界宽度
            }),
            fill: new Fill({               // 填充样式
                color: fillColor                      // 填充颜色
            })
        })
    });
    cacheMiniStyle2[f.get("noImg")] = style;
    return style
}