import { i18n } from "../../../public/i18n";
import {addContentPath} from '../../../util/index.js'

export const card_width = 500;
export const card_height = 475;

export const getImageInfo = (url, callback) => {
    var img = new Image();
    img.src = addContentPath(url);
    if (img.complete) {
        // 如果图片被缓存，则直接返回缓存数据
        callback(img.width, img.height);
    } else {
        img.onload = function() {
            callback(img.width, img.height);
        }
    }

}

export const getFontOptions = () => {
    const isWindows = function() {
        return /windows|win32/i.test(navigator.userAgent);
    }();

    const en = ["inherit", "SimSun", "SimHei", "KaiTi", "FangSong", "Microsoft Yahei"],
        ch = ["inherit", "STSong", "STHeiti", "STKaiti", "STFangsong", "Microsoft Yahei"]

    let names = [i18n.label.default(), "宋体", "黑体", "楷体", "仿宋", "微软雅黑"]
    if (window.e9_locale.userLanguage != '7') {
        names = en
    }
    
    if (isWindows) {
        return en.map((v, i) => ({ value: v, name: names[i] }))
    } else {
        return ch.map((v, i) => ({ value: v, name: names[i] }))
    }
}