import {formatBusinessTime} from '@/utils/tools'

/**
 * storeInfoStore 模块的 getters
 */
import { StoreInfoStoreType } from './index'

export default {
    /**
     * 门店折扣 结算方式 (1报价，2扣点)
     * @param {AnyObject} earningType (1报价，2扣点)
     */
    geterPointStore(state: StoreInfoStoreType) {
        return state.allStoreInfo.earningType === 1
    },


    /**
     * 门店折扣，门店折扣小于 50 不允许修改
     * @param {AnyObject} payPercentage 门店折扣小于 50 不允许修改
     */
    isPointStore(state: StoreInfoStoreType) {
        return state.allStoreInfo.payPercentage <= 50
    },


    /**
     * 是否显示新价格
     * @return {boolean} trun 显示新价格
     */
    isNewPriceDisplay() {
        return true
    },


    /**
     * 美团im单聊状态
     */
    imMtStatus(state: StoreInfoStoreType) {
        return state.imOnlineStatus.filter(item => item.vendorID === 1)
    },


    /**
     * 饿百im单聊状态
     */
    imEbStatus(state: StoreInfoStoreType) {
        return state.imOnlineStatus.filter(item => item.vendorID === 3)
    },


    /**
     * 单聊状态(消息)
     */
    imStatus(state: StoreInfoStoreType, getters: AnyObject) {
        let str = ''
        if (getters.imMtStatus.length > 0 && !getters.imMtStatus[0].errMsg && getters.imMtStatus[0].imStatus === 0) str = '美团'
        if (getters.imEbStatus.length > 0 && !getters.imEbStatus[0].errMsg && getters.imEbStatus[0].imStatus === 0) str = str ? str + '/淘宝闪购':'淘宝闪购'
        return str
    },


    /**
    * 门店营业状态
    * 营业状态: 1营业 0临时休息 -1休息 -2禁用
    */
    storeStatus(state: StoreInfoStoreType) {
        return state.allStoreInfo.status
    },


    /**
     * 本地营业状态与线上平台的状态是否一致
     */
     isSameStatus(state:StoreInfoStoreType,getters:AnyObject){
        let flag = true
        let status = state.allStoreInfo.status
        if(getters.platformInfo && getters.platformInfo.length>0) flag = getters.platformInfo.every((item:AnyObject) => item.status === status)
        // console.log('flag',flag)
        return flag
    },


    /**
     * 营业时间
     */
    businessHours(state:StoreInfoStoreType){
        const stateData = state.allStoreInfo
        return {
            timer1: formatBusinessTime(stateData.openTime1),
            timer2: formatBusinessTime(stateData.closeTime1),
            timer3: formatBusinessTime(stateData.openTime2),
            timer4: formatBusinessTime(stateData.closeTime2),
        }
    },


    /**
     * 手机门店休息时间
     */
    newAutoEnableAt(state:StoreInfoStoreType){
        return state.allStoreInfo.autoEnableAt
    },


    /**
     * 三方门店的所有信息
     */
    platformInfo(state:StoreInfoStoreType){
        let arr = []
        for(let i in state.platformInfo){
            if( i!== '9' ) arr.push(state.platformInfo[i])
        }
        return arr
    },

        /**
     * 门店地址信息
     */
    storeAddress(state:StoreInfoStoreType){
        return state.allStoreInfo.address || ''
    }
}