let App = {}
const ua = navigator.userAgent.toUpperCase();
let isAndroid = App.isAndroid = ua.indexOf("ANDROID") != -1;
let isIos = App.isIos = ua.indexOf("IPHONE OS") != -1;
var _isHrxAppIos = ua.indexOf("HRXAPP") != -1;

App.Url = ''

App.getUser = function(callbackFun) {
    let str = {
        employeeId: 'employeeId',
        umId: 'umId',
        token: 'token',
        name: '张三',
        headerUrl: 'headerUrl',
        enviroment: 'enviroment'
    }

    if(localStorage["accessToken"]) {
        str = {
            ...str,
            umId: localStorage["umId"],
            token: localStorage["accessToken"]
        }
    }

    var params = (typeof str == "string") ? (JSON.parse(str)) : str;

    callbackFun(params)
}

App.getUM = function(callbackFun) {
    if(localStorage["umId"]) {
        callbackFun(localStorage["umId"])
    } else {
        callbackFun("wuenqi309")
    }
}

// 改变title
App.changeTitle = function(titleName) {
    console.info("phone changeTitle, titleName=" + titleName)
}

App.showLoading = function() {
    console.info("App.showLoading")
}

App.scrollToTop = function() {
    console.info("App.scrollToTop")
}

App.hideLoading = function() {
    console.info("App.hideLoading")
}

App.checkFn = function (name, cb) {
    console.log(name)
    cb(1)
}

App.back = function() {
    console.info("App.back")
}

App.backToHome = function() {
    console.info("phone backToHome")
}

App.gotoLocation = function(url, paramStr) {
    if(paramStr) {
        window.location.href = url + '?' + paramStr
    } else {
        window.location.href = url
    }
}
// 跳转本地包路径
App.gotoLocalHref = function() {
    console.info("phone gotoLocalHref")
}

// 跳转第三方页面，native会默认控制返回
App.gotoAdHref = function() {
    console.info("phone gotoLocalHref")
}


App.showAlert = function(title) {
    console.info("showAlert.title:" + title)
}

App.changeHeader = function(config) {
    console.info("changeHeader" + JSON.stringify(config))
}

/**
 * 打开H5页面，
 * @param {*} url 页面路径
 * @param {*} withBackButton 0：无， 1：左下角有个原型返回键
 * @param {*} [options] h5传给native的配置参数
 * @param {*} [options.animation] 转场动画，例如bottom-top
 * @param {*} [options.param] 传到下一个页面的参数
 */
App.pushH5Window = function(url, withBackButton, options) {
    if(/pa-office:\/\/hrx\/html\/[^/]+\//.test(url)){
        url = url.replace(/pa-office:\/\/hrx\/html\/[^/]+\//, '/')
        window.location.href = url
    } else {
        let urlList = url.split('/')
        urlList = urlList.slice(2, urlList.length);
        window.location.href = urlList.join('/')
    }
}
/**
 * 关闭当前H5页面，即返回到上一个页面
 * @param {*} animation 
 * @param {*} param 
 */
App.popH5Window = function(animation, param) {
    // window.close();
    window.history.back();
}

/**
 * 横屏
 */
App.landSpace = function(callback) {
    callApp('landSpace');
    callback && callback()
}
/**
 * 强制横屏
 */
App.forceLandSpace = function(callback) {
    callApp('landSpace');
    callback && callback()
}
/**
 * 竖屏操作
 */
App.portrait = function(callback) {
    callApp('portrait');
    callback && callback()
}

/**
 * 获取状态栏高度
 * @param {*} options 配置对象或回调函数
 * @param {function} options.success 成功回调
 */
App.getStatusBarHeight = function(callbackfun) {
    // 开发环境默认返回 44（iOS 刘海屏）或 24（普通屏）
    // const height = isIos ? 44 : 24
    // if (typeof options === 'function') {
    //     options(height)
    // } else if (options && typeof options.success === 'function') {
    //     options.success(height)
    // }
    callApp('getStatusBarHeight', callbackfun);
}

App = {
    ...App,
    // ...AppExtend
}

export default App