import StringUtil from './StringUtil';
export const ChannelID = {
    JD: 1, 
    YHD: 2, 
    JMALL: 3, 
    YAO: 1, 
}
export const AppType = {
    PC: 1, 
    M: 2, 
    PROMOTION: 3, 
    SHOP_CATEGORY: 4, 
    TAB_UPDATE: 5, 
    SCENE_GUIDE: 6, 
    MINI_APP: 7, 
    TAB_SERVICE: 8, 
    FOUND_TAG: 9, 
    VR: 12, 
    MODULE_HOME: 14, 
    FLASH_BUY: 13, 
    MODULE_PROMOTION: 15, 
}
export const ChannelType = {
    JD: 6, 
    YHD: 4, 
    JMALL: 5, 
    YAO: 8, 
}
export const ShopType = {
    JD: 0, 
    YHD: 1, 
    JMALL: 2, 
    MEDICAL: 3, 
    SAM: 4, 
    YAO: 5, 
}
export const PageType = {
    DEFAULT: 0, 
    INDEX_PAGE: 1, 
    PROMOTION_PAGE: 3, 
    SEARCH_RESULT_PAGE: 5, 
    MORE_PRODUCT_PAGE: 6, 
    MORE_COUPON_PAGE: 7, 
    CATEGORY_LIST_PAGE: 8, 
    CATEGORY_NAVIGATE_PAGE: 9, 
    BLANK_PAGE: 10, 
}
export const IsYhdF = () => {
    return getChannelType() == ChannelType.YHD
}
export const IsJDShop = () => {
    if ($('title').text().indexOf('店铺装修-装修工作台') != -1) {
        return true
    } else {
        return false
    }
}
export const IsYaoB2B = () => {
    let flag = false
    if (
        window.page_data &&
        window.page_data.yaoB2B != 'false' &&
        window.page_data.yaoB2B != undefined
    ) {
        flag = window.page_data.yaoB2B
    }
    return flag
}
export const IsSamShop = () => {
    let flag = false
    if (window.page_data && window.page_data.samShop) {
        let isBoolean = `${window.page_data.samShop}`
        flag = isBoolean.toLowerCase() === 'true'
    }
    return flag
}
export const getChannelType = () => {
    let projectType = StringUtil.getQueryString('projectType')
    if (projectType != undefined && parseInt(projectType) > 0) {
        console.log('')
    } else {
        if (window.page_data && window.page_data.projectType != undefined) {
            projectType = window.page_data.projectType
        }
    }
    if (projectType == undefined) {
        projectType = ChannelType.JD
    }
    return projectType
}
export const isLingEntryOpen = () => {
    if (window && window.page_data) {
        if (window.page_data.lingEntryOpen == null) {
            return true
        } else if (
            window.page_data.lingEntryOpen != null &&
            window.page_data.lingEntryOpen == true
        ) {
            return true
        } else {
            return false
        }
    } else {
        return true
    }
}
export const getChannelName = (prefix = false) => {
    let type = getChannelType()
    let result = '松果'
    if (type == ChannelType.JD) {
        result = '松果'
    } else if (type == ChannelType.JMALL) {
        if (prefix) {
            result = '京商城小程序'
        } else {
            result = '小程序'
        }
    } else if (type == ChannelType.YHD) {
        result = '1号店'
    } else if (type == ChannelType.YAO) {
        result = '医药城'
    }
    return result
}
export const getChannelId = () => {
    let channelType = getChannelType()
    switch (
        parseInt(channelType) 
    ) {
        case ChannelType.JD:
            return ChannelID.JD
        case ChannelType.YHD:
            return ChannelID.YHD
        case ChannelType.JMALL:
            return ChannelID.JMALL
        
        default:
            return ChannelID.JD
    }
}
export const getShopType = () => {
    let channelType = getChannelType()
    switch (parseInt(channelType)) {
        case ChannelType.JD: 
            if (IsYaoB2B()) {
                return ShopType.YAO
            } else if (IsSamShop()) {
                return ShopType.SAM
            } else {
                return ShopType.JD
            }
        case ChannelType.YAO:
            return ShopType.YAO
        case ChannelType.YHD:
            return ShopType.YHD
        case ChannelType.JMALL:
            return ShopType.JMALL
        default:
            return ShopType.JD
    }
}
export const IsModuleDecorate = () => {
    let flag = false
    const moduleDecorateAppTypes = new Set([
        AppType.MODULE_HOME,
        AppType.MODULE_PROMOTION,
    ])
    if (
        window.page_data &&
        moduleDecorateAppTypes.has(window.page_data.appType)
    ) {
        flag = true
    }
    return flag
}