import { config } from "../config/config"
import { log } from "./log"
import { tools } from "./tools"

export class sdkUtil {
		
	public static login(cb:Function) {
		switch (tools.platform){
			case config.Platform.H5:
			    cb && cb(null)
			    break
			case config.Platform.WEIXIN:
			    wx.login({
					success(res) {
					    let code = res.code
						log.Debug("wx_code",code)
						cb && cb({'code':code})
					},
					fail(e) { log.Debug(`wx_login 调用失败:`,e) }
			    })
				break;
			case config.Platform.TOUTIAO:
			    tt.login({
					force: true,
					success(res) {
					    let code = res.code
					    let anonymousCode = res.anonymousCode
					    log.Debug("tt_code",code,'tt_anonymousCode',anonymousCode)
						cb && cb({'code':code,'anonymousCode':anonymousCode})
					},
					fail(e) { log.Debug(`tt_login 调用失败:`,e) }
			    });
			    break;
			default:
				break;
		}
	}

    /**
	 * 添加桌面
	 */
	public static addShortcut(cb:Function) {
		switch (tools.platform){
			case config.Platform.WEIXIN:
			    wx.addShortcut({
					success() {
					    console.log("添加桌面成功");
					    cb && cb()
					},
					fail(err) {
					  console.log("添加桌面失败", err.errMsg);
					},
			    });
				break;
			case config.Platform.TOUTIAO:
			    tt.addShortcut({
					success() {
					    console.log("添加桌面成功");
					    cb && cb()
					},
					fail(err) {
					  console.log("添加桌面失败", err.errMsg);
					},
			    });
			    break;
			default:
			    cb && cb()
				break;
		}
	}
}