@file:Suppress("UNCHECKED_CAST", "USELESS_CAST", "INAPPLICABLE_JVM_NAME", "UNUSED_ANONYMOUS_PARAMETER", "SENSELESS_COMPARISON", "NAME_SHADOWING", "UNNECESSARY_NOT_NULL_ASSERTION")
package uni.UNIHelloUniAppX
import io.dcloud.uniapp.*
import io.dcloud.uniapp.extapi.*
import io.dcloud.uniapp.framework.*
import io.dcloud.uniapp.runtime.*
import io.dcloud.uniapp.vue.*
import io.dcloud.uniapp.vue.shared.*
import io.dcloud.unicloud.*
import io.dcloud.uts.*
import io.dcloud.uts.Map
import io.dcloud.uts.Set
import io.dcloud.uts.UTSAndroid
import kotlin.properties.Delegates
import io.dcloud.uniapp.extapi.getUserInfo as uni_getUserInfo
import io.dcloud.uniapp.extapi.login as uni_login
import io.dcloud.uniapp.extapi.showModal as uni_showModal
open class GenPagesAPIOauthOauth : BasePage {
    constructor(__ins: ComponentInternalInstance, __renderer: String?) : super(__ins, __renderer) {
        onLoad(fun(_: OnLoadOptions) {
            stat_instance.onLoad(this)
        }
        , __ins)
        onPageShow(fun() {
            stat_instance.onShow(this)
        }
        , __ins)
        onPageHide(fun() {
            stat_instance.onHide(this)
        }
        , __ins)
        onUnload(fun() {
            stat_instance.onUnload(this)
        }
        , __ins)
    }
    open var getTestUserInfo: () -> UserInfo?
        get() {
            return unref(this.`$exposed`["getTestUserInfo"]) as () -> UserInfo?
        }
        set(value) {
            setRefValue(this.`$exposed`, "getTestUserInfo", value)
        }
    open var hwLogin: () -> Unit
        get() {
            return unref(this.`$exposed`["hwLogin"]) as () -> Unit
        }
        set(value) {
            setRefValue(this.`$exposed`, "hwLogin", value)
        }
    companion object {
        @Suppress("UNUSED_PARAMETER", "UNUSED_VARIABLE")
        var setup: (__props: GenPagesAPIOauthOauth, __setupCtx: SetupContext) -> Any? = fun(__props, __setupCtx): Any? {
            val __expose = __setupCtx.expose
            val __ins = getCurrentInstance()!!
            val _ctx = __ins.proxy as GenPagesAPIOauthOauth
            val _cache = __ins.renderCache
            val title = ref("OAuth")
            val logging = ref(false)
            val userInfo = computed(fun(): UserInfo? {
                return state.userInfo
            }
            )
            val testUserInfo = ref<UserInfo?>(null)
            val clear = fun(){
                setUserInfo(null)
                testUserInfo.value = null
                logging.value = false
            }
            val hwLogin = fun(){
                logging.value = true
                if (userInfo.value != null) {
                    return
                }
                uni_login(LoginOptions(provider = "huawei", success = fun(_) {
                    uni_getUserInfo(GetUserInfoOptions(provider = "huawei", success = fun(res) {
                        console.log("获取用户信息成功")
                        val info = UserInfo(nickName = res.userInfo.nickName, avatarUrl = res.userInfo.avatarUrl)
                        testUserInfo.value = info
                        setUserInfo(info)
                        logging.value = false
                    }
                    , fail = fun(err) {
                        clear()
                        console.log("获取用户信息错误: ", JSON.stringify(err))
                    }
                    ))
                }
                , fail = fun(err) {
                    clear()
                    console.log("获取用户信息错误: ", JSON.stringify(err))
                }
                ))
            }
            val wxLogin = fun(){
                logging.value = true
                if (userInfo.value != null) {
                    return
                }
                uni_login(LoginOptions(provider = "weixin", success = fun(res) {
                    uniCloud.importObject("uni-login-test-co", GenCloudObjUniLoginTestCo::class.java).loginByWeixin(_uO("code" to res.code, "appid" to "wxd569c7238830733b")).then(fun(res: UTSJSONObject){
                        console.log(JSON.stringify(res))
                        val info = UserInfo(nickName = res.getString("nickname") ?: "", avatarUrl = res.getString("headimgurl") ?: "")
                        testUserInfo.value = info
                        setUserInfo(info)
                        logging.value = false
                    }
                    ).`catch`(fun(err){
                        console.error(JSON.stringify(err))
                        uni_showModal(ShowModalOptions(title = "微信登录失败", content = (err as UTSError).message))
                        clear()
                    }
                    )
                }
                , fail = fun(err) {
                    uni_showModal(ShowModalOptions(title = "微信登录失败", content = err.errMsg))
                    clear()
                }
                ))
            }
            fun gen_getTestUserInfo_fn(): UserInfo? {
                return testUserInfo.value
            }
            val getTestUserInfo = ::gen_getTestUserInfo_fn
            __expose(_uM("getTestUserInfo" to getTestUserInfo, "hwLogin" to hwLogin, "setUserInfo" to setUserInfo))
            return fun(): Any? {
                val _component_page_head = resolveEasyComponent("page-head", GenComponentsPageHeadPageHeadClass)
                return _cE("scroll-view", _uM("style" to _nS(_uM("flex" to "1"))), _uA(
                    _cV(_component_page_head, _uM("title" to unref(title)), null, 8, _uA(
                        "title"
                    )),
                    _cE("view", _uM("class" to "uni-padding-wrap uni-common-mt"), _uA(
                        _cE("view", _uM("class" to "uni-container"), _uA(
                            _cE("view", _uM("class" to "uni-center"), "登录状态"),
                            if (unref(userInfo) == null) {
                                _cE("view", _uM("key" to 0), _uA(
                                    if (isTrue(unref(logging))) {
                                        _cE("view", _uM("key" to 0, "class" to "uni-center uni-common-mt"), "登录中...")
                                    } else {
                                        _cE(Fragment, _uM("key" to 1), _uA(
                                            _cE("view", _uM("class" to "uni-center uni-common-mt"), "未登录"),
                                            _cE("view", _uM("class" to "uni-center uni-common-mt"), "请点击下面按钮登录")
                                        ), 64)
                                    }
                                ))
                            } else {
                                _cE("view", _uM("key" to 1), _uA(
                                    _cE("view", _uM("class" to "uni-center uni-common-mt"), _uA(
                                        _cE("image", _uM("src" to unref(userInfo)!!.avatarUrl, "style" to _nS(_uM("width" to "60px", "height" to "60px", "border-radius" to "30px"))), null, 12, _uA(
                                            "src"
                                        ))
                                    )),
                                    _cE("view", _uM("class" to "uni-center uni-common-mt"), "Hello, " + _tD(unref(userInfo)!!.nickName), 1)
                                ))
                            }
                        )),
                        _cE("view", _uM("class" to "uni-btn-v uni-common-mt"), _uA(
                            _cE("button", _uM("class" to "uni-common-mt", "type" to "primary", "onClick" to wxLogin), "微信登录"),
                            _cE("button", _uM("class" to "uni-common-mt", "onClick" to clear), "清空")
                        ))
                    ))
                ), 4)
            }
        }
        val styles: Map<String, Map<String, Map<String, Any>>> by lazy {
            _nCS(_uA())
        }
        var inheritAttrs = true
        var inject: Map<String, Map<String, Any?>> = _uM()
        var emits: Map<String, Any?> = _uM()
        var props = _nP(_uM())
        var propsNeedCastKeys: UTSArray<String> = _uA()
        var components: Map<String, CreateVueComponent> = _uM()
    }
}
