@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.navigateTo as uni_navigateTo
import io.dcloud.uniapp.extapi.offGyroscopeChange as uni_offGyroscopeChange
import io.dcloud.uniapp.extapi.onGyroscopeChange as uni_onGyroscopeChange
import io.dcloud.uniapp.extapi.startGyroscope as uni_startGyroscope
import io.dcloud.uniapp.extapi.stopGyroscope as uni_stopGyroscope
open class GenPagesAPIGyroscopeGyroscope : 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)
    }
    companion object {
        @Suppress("UNUSED_PARAMETER", "UNUSED_VARIABLE")
        var setup: (__props: GenPagesAPIGyroscopeGyroscope) -> Any? = fun(__props): Any? {
            val __ins = getCurrentInstance()!!
            val _ctx = __ins.proxy as GenPagesAPIGyroscopeGyroscope
            val _cache = __ins.renderCache
            val activeInterval = ref<GyroscopeInterval>("normal")
            val statusText = ref("未启动")
            val axisX = ref("0.0000")
            val axisY = ref("0.0000")
            val axisZ = ref("0.0000")
            val lastAction = ref("等待调用")
            val lastStatus = ref("未执行")
            val lastPayload = ref("请先绑定监听后开始")
            val logItems = ref(_uA<String>())
            val primaryBound = ref(false)
            val extraBound = ref(false)
            val intervalOptions = _uA(
                IntervalOption__1(value = "game", label = "game"),
                IntervalOption__1(value = "ui", label = "ui"),
                IntervalOption__1(value = "normal", label = "normal")
            ) as UTSArray<IntervalOption__1>
            val statusItems = computed(fun(): UTSArray<DisplayItem__1> {
                return _uA(
                    DisplayItem__1(label = "监听状态", value = statusText.value),
                    DisplayItem__1(label = "当前频率", value = activeInterval.value)
                )
            }
            )
            val axisItems = computed(fun(): UTSArray<DisplayItem__1> {
                return _uA(
                    DisplayItem__1(label = "X", value = axisX.value),
                    DisplayItem__1(label = "Y", value = axisY.value),
                    DisplayItem__1(label = "Z", value = axisZ.value)
                )
            }
            )
            val resultItems = computed(fun(): UTSArray<DisplayItem__1> {
                return _uA(
                    DisplayItem__1(label = "最近动作", value = lastAction.value),
                    DisplayItem__1(label = "状态", value = lastStatus.value),
                    DisplayItem__1(label = "说明", value = lastPayload.value)
                )
            }
            )
            fun gen_pushLog_fn(line: String): Unit {
                logItems.value.unshift(line)
                if (logItems.value.length > 10) {
                    logItems.value.splice(10)
                }
                console.log("logItems.value.length", logItems.value.length)
            }
            val pushLog = ::gen_pushLog_fn
            fun gen_updateResult_fn(action: String, status: String, payload: String): Unit {
                lastAction.value = action
                lastStatus.value = status
                lastPayload.value = payload
                pushLog("" + action + " -> " + status)
            }
            val updateResult = ::gen_updateResult_fn
            fun gen_formatAxisValue_fn(value: Number): String {
                return value.toFixed(4)
            }
            val formatAxisValue = ::gen_formatAxisValue_fn
            val primaryListener: OnGyroscopeChangeCallback = fun(result){
                axisX.value = formatAxisValue(result.x)
                axisY.value = formatAxisValue(result.y)
                axisZ.value = formatAxisValue(result.z)
                statusText.value = "监听中 (" + activeInterval.value + ")"
            }
            val extraListener: OnGyroscopeChangeCallback = fun(result){
                pushLog("额外监听 -> " + formatAxisValue(result.x) + ", " + formatAxisValue(result.y) + ", " + formatAxisValue(result.z))
            }
            fun gen_selectInterval_fn(interval: GyroscopeInterval): Unit {
                activeInterval.value = interval
                updateResult("selectInterval", "已切换", interval)
            }
            val selectInterval = ::gen_selectInterval_fn
            fun gen_handleIntervalChange_fn(event: UniRadioGroupChangeEvent): Unit {
                selectInterval(event.detail.value as GyroscopeInterval)
            }
            val handleIntervalChange = ::gen_handleIntervalChange_fn
            fun gen_registerSingleListener_fn(): Unit {
                if (!primaryBound.value) {
                    uni_onGyroscopeChange(primaryListener)
                    primaryBound.value = true
                }
                updateResult("onGyroscopeChange(primary)", "已绑定", "主监听已注册")
            }
            val registerSingleListener = ::gen_registerSingleListener_fn
            fun gen_registerExtraListener_fn(): Unit {
                if (!extraBound.value) {
                    uni_onGyroscopeChange(extraListener)
                    extraBound.value = true
                }
                updateResult("onGyroscopeChange(extra)", "已绑定", "额外监听已注册")
            }
            val registerExtraListener = ::gen_registerExtraListener_fn
            fun gen_removeSingleListener_fn(): Unit {
                uni_offGyroscopeChange(primaryListener)
                primaryBound.value = false
                updateResult("offGyroscopeChange(listener)", "已解绑", "仅移除主监听")
            }
            val removeSingleListener = ::gen_removeSingleListener_fn
            fun gen_removeAllListeners_fn(): Unit {
                uni_offGyroscopeChange(null)
                primaryBound.value = false
                extraBound.value = false
                updateResult("offGyroscopeChange()", "已解绑", "所有监听函数已移除")
            }
            val removeAllListeners = ::gen_removeAllListeners_fn
            fun gen_navigateToPanorama_fn() {
                uni_navigateTo(NavigateToOptions(url = "/pages/API/gyroscope/panorama"))
            }
            val navigateToPanorama = ::gen_navigateToPanorama_fn
            fun gen_startListening_fn(): Unit {
                if (!primaryBound.value) {
                    registerSingleListener()
                }
                uni_startGyroscope(StartGyroscopeOptions(interval = activeInterval.value, success = fun(res){
                    val errMsg: String = if (res.errMsg != null) {
                        res.errMsg as String
                    } else {
                        "startGyroscope:ok"
                    }
                    statusText.value = "监听中 (" + activeInterval.value + ")"
                    updateResult("startGyroscope", "成功", errMsg)
                }
                , fail = fun(error){
                    statusText.value = "启动失败"
                    updateResult("startGyroscope", "失败 (" + error.errCode + ")", if (error.errMsg != null) {
                        error.errMsg
                    } else {
                        "startGyroscope:fail"
                    }
                    )
                }
                ))
            }
            val startListening = ::gen_startListening_fn
            fun gen_stopListening_fn(): Unit {
                uni_stopGyroscope(StopGyroscopeOptions(success = fun(res){
                    val errMsg: String = if (res.errMsg != null) {
                        res.errMsg as String
                    } else {
                        "stopGyroscope:ok"
                    }
                    statusText.value = "已停止"
                    updateResult("stopGyroscope", "成功", errMsg)
                }
                , fail = fun(error){
                    updateResult("stopGyroscope", "失败 (" + error.errCode + ")", if (error.errMsg != null) {
                        error.errMsg
                    } else {
                        "stopGyroscope:fail"
                    }
                    )
                }
                ))
            }
            val stopListening = ::gen_stopListening_fn
            onUnload(fun(){
                uni_offGyroscopeChange(null)
                uni_stopGyroscope(null)
            }
            )
            return fun(): Any? {
                val _component_radio = resolveComponent("radio")
                val _component_radio_group = resolveComponent("radio-group")
                return _cE("scroll-view", _uM("style" to _nS(_uM("flex" to "1", "padding" to "6px"))), _uA(
                    _cE("text", _uM("class" to "uni-h2"), "陀螺仪 API"),
                    _cE("text", _uM("class" to "margin-v"), "演示 `uni.startGyroscope`、`uni.stopGyroscope`、`uni.onGyroscopeChange`、`uni.offGyroscopeChange` 的完整用法。"),
                    _cE("text", _uM("class" to "margin-v"), "`x / y / z` 表示各轴角速度。"),
                    _cE("text", _uM("class" to "uni-h3"), "实时状态"),
                    _cE("view", _uM("class" to "log-list"), _uA(
                        _cE(Fragment, null, RenderHelpers.renderList(unref(statusItems), fun(item, __key, __index, _cached): Any {
                            return _cE("text", _uM("class" to "log-item", "key" to item.label), _tD(item.label) + "：" + _tD(item.value), 1)
                        }
                        ), 128),
                        _cE(Fragment, null, RenderHelpers.renderList(unref(axisItems), fun(item, __key, __index, _cached): Any {
                            return _cE("text", _uM("class" to "log-item", "key" to item.label), _tD(item.label) + "：" + _tD(item.value), 1)
                        }
                        ), 128)
                    )),
                    _cE("text", _uM("class" to "uni-h3"), "调用结果"),
                    _cE("view", _uM("class" to "log-list"), _uA(
                        _cE(Fragment, null, RenderHelpers.renderList(unref(resultItems), fun(item, __key, __index, _cached): Any {
                            return _cE("text", _uM("class" to "log-item", "key" to item.label), _tD(item.label) + "：" + _tD(item.value), 1)
                        }
                        ), 128)
                    )),
                    _cE("text", _uM("class" to "uni-h3"), "开始 / 停止"),
                    _cE("text", _uM("class" to "margin-v"), "先注册监听函数，再按不同 interval 启动；停止后会继续保留已绑定监听，直到显式 off。"),
                    _cV(_component_radio_group, _uM("class" to "option-group", "onChange" to handleIntervalChange), _uM("default" to withSlotCtx(fun(): UTSArray<Any> {
                        return _uA(
                            _cE(Fragment, null, RenderHelpers.renderList(intervalOptions, fun(item, __key, __index, _cached): Any {
                                return _cE("view", _uM("class" to "option-item", "key" to item.value), _uA(
                                    _cV(_component_radio, _uM("value" to item.value, "checked" to (unref(activeInterval) == item.value)), _uM("default" to withSlotCtx(fun(): UTSArray<Any> {
                                        return _uA(
                                            _cE("text", _uM("class" to "option-text"), _tD(item.label), 1)
                                        )
                                    }
                                    ), "_" to 2), 1032, _uA(
                                        "value",
                                        "checked"
                                    ))
                                ))
                            }
                            ), 64)
                        )
                    }
                    ), "_" to 1)),
                    _cE("button", _uM("id" to "btn-start-gyroscope", "class" to "margin-v", "type" to "primary", "onClick" to startListening), "开始监听"),
                    _cE("button", _uM("id" to "btn-stop-gyroscope", "class" to "margin-v", "onClick" to stopListening), "停止监听"),
                    _cE("button", _uM("id" to "btn-bind-primary-listener", "class" to "margin-v", "onClick" to registerSingleListener), "绑定主监听"),
                    _cE("button", _uM("id" to "btn-bind-extra-listener", "class" to "margin-v", "onClick" to registerExtraListener), "再绑一个监听"),
                    _cE("button", _uM("id" to "btn-remove-primary-listener", "class" to "margin-v", "onClick" to removeSingleListener), "off 指定监听"),
                    _cE("button", _uM("id" to "btn-remove-all-listeners", "class" to "margin-v", "onClick" to removeAllListeners), "off 全部监听"),
                    _cE("button", _uM("id" to "btn-open-panorama", "class" to "margin-v", "onClick" to navigateToPanorama), "跳转全景示例"),
                    _cE("text", _uM("class" to "uni-h3"), "监听日志"),
                    _cE("view", _uM("class" to "log-list"), _uA(
                        _cE(Fragment, null, RenderHelpers.renderList(unref(logItems), fun(item, __key, __index, _cached): Any {
                            return _cE("text", _uM("class" to "log-item", "key" to item), _tD(item), 1)
                        }
                        ), 128)
                    ))
                ), 4)
            }
        }
        val styles: Map<String, Map<String, Map<String, Any>>> by lazy {
            _nCS(_uA(
                styles0
            ))
        }
        val styles0: Map<String, Map<String, Map<String, Any>>>
            get() {
                return _uM("margin-v" to _pS(_uM("marginTop" to 5, "marginRight" to 0, "marginBottom" to 5, "marginLeft" to 0)), "notice" to _pS(_uM("color" to "#550000", "fontSize" to 14, "fontStyle" to "italic")), "option-group" to _pS(_uM("marginTop" to 5, "marginRight" to 0, "marginBottom" to 5, "marginLeft" to 0, "display" to "flex", "flexDirection" to "row", "flexWrap" to "wrap")), "option-item" to _pS(_uM("display" to "flex", "flexDirection" to "row", "alignItems" to "center", "marginTop" to 8, "marginRight" to 18)), "option-text" to _pS(_uM("fontSize" to 14)), "error-list" to _pS(_uM("marginTop" to 5, "marginRight" to 0, "marginBottom" to 5, "marginLeft" to 0, "display" to "flex", "flexDirection" to "column")), "error-item" to _pS(_uM("marginTop" to 5, "marginRight" to 0, "marginBottom" to 5, "marginLeft" to 0, "display" to "flex", "flexDirection" to "row", "flexWrap" to "wrap")), "error-text" to _pS(_uM("fontSize" to 14)), "mini-button" to _pS(_uM("marginTop" to 5)), "log-list" to _pS(_uM("marginTop" to 5, "marginRight" to 0, "marginBottom" to 5, "marginLeft" to 0, "paddingTop" to 10, "paddingRight" to 10, "paddingBottom" to 10, "paddingLeft" to 10, "borderTopWidth" to 1, "borderRightWidth" to 1, "borderBottomWidth" to 1, "borderLeftWidth" to 1, "borderTopStyle" to "solid", "borderRightStyle" to "solid", "borderBottomStyle" to "solid", "borderLeftStyle" to "solid", "borderTopColor" to "#cccccc", "borderRightColor" to "#cccccc", "borderBottomColor" to "#cccccc", "borderLeftColor" to "#cccccc", "display" to "flex", "flexDirection" to "column")), "log-item" to _pS(_uM("fontSize" to 14, "marginTop" to 4, "marginRight" to 0, "marginBottom" to 4, "marginLeft" to 0)))
            }
        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()
    }
}
