import Taro from "@tarojs/taro";
import { getToken, setToken } from '@/utils/index'


// 用户未授权
export const showAuthModal = (content: string) => {
	Taro.showModal({
		title: '需要授权',
		content: content,
		showCancel: false,
		confirmText: '去授权',
		success: function (res) {
			if (res.confirm) {
				// 用户点击去授权，跳转到设置页面
				Taro.openSetting({
					success: function (data) {
						console.log(data)
						// if (data.authSetting['scope.writePhotosAlbum']) {
						// 	// 用户重新授权后，可以再次调用相关接口
						// 	// 这里可以再次尝试获取用户信息
						// }
					},
					fail: function (err) {
						console.error('打开设置失败', err);
					}
				});
			}
		}
	});
}

// 权限测试
// 'scope.writePhotosAlbum'
// 'scope.record'
export const checkPermission = async (scope: string):Promise<boolean> => {
	return new Promise((resolve) => {
		Taro.authorize({
			scope: scope,
			success(res) {
				console.log(res)
				resolve(true);
			},
			fail(err) {
				console.warn(err)
				resolve(false);
			}
		});
	});
}

export const bindPhone = async (phone: string) => {
	// const res = await authBind(EBindKind.WechatPhone, phone);
	// if (res.data) {
	// 	return res.data
	// }
	return null
}