@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.offCompassChange as uni_offCompassChange
import io.dcloud.uniapp.extapi.onCompassChange as uni_onCompassChange
import io.dcloud.uniapp.extapi.startCompass as uni_startCompass
import io.dcloud.uniapp.extapi.stopCompass as uni_stopCompass
open class GenPagesAPICompassCompass : 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 startCompassListen: () -> Unit
        get() {
            return unref(this.`$exposed`["startCompassListen"]) as () -> Unit
        }
        set(value) {
            setRefValue(this.`$exposed`, "startCompassListen", value)
        }
    companion object {
        @Suppress("UNUSED_PARAMETER", "UNUSED_VARIABLE")
        var setup: (__props: GenPagesAPICompassCompass, __setupCtx: SetupContext) -> Any? = fun(__props, __setupCtx): Any? {
            val __expose = __setupCtx.expose
            val __ins = getCurrentInstance()!!
            val _ctx = __ins.proxy as GenPagesAPICompassCompass
            val _cache = __ins.renderCache
            val statusText = ref("未启动")
            val direction = ref(0)
            val directionText = ref("北")
            val accuracyText = ref("null")
            val primaryBound = ref(false)
            val secondaryBound = ref(false)
            val lastAction = ref("等待调用")
            val lastStatus = ref("未执行")
            val lastPayload = ref("请先绑定监听并开始采集")
            val logItems = ref(_uA<LogItem>())
            val logId = ref(0)
            val infoItems = computed(fun(): UTSArray<DisplayItem> {
                return _uA(
                    DisplayItem(label = "监听状态", value = statusText.value),
                    DisplayItem(label = "主监听", value = if (primaryBound.value) {
                        "已绑定"
                    } else {
                        "未绑定"
                    }
                    ),
                    DisplayItem(label = "额外监听", value = if (secondaryBound.value) {
                        "已绑定"
                    } else {
                        "未绑定"
                    }
                    ),
                    DisplayItem(label = "accuracy", value = accuracyText.value),
                    DisplayItem(label = "最近动作", value = lastAction.value),
                    DisplayItem(label = "状态", value = lastStatus.value),
                    DisplayItem(label = "说明", value = lastPayload.value)
                )
            }
            )
            fun gen_pushLog_fn(line: String): Unit {
                logId.value = logId.value + 1
                val item = LogItem(id = logId.value, text = line)
                logItems.value.unshift(item)
                if (logItems.value.length > 10) {
                    logItems.value.splice(10)
                }
            }
            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_formatDirection_fn(value: Number): String {
                return value.toFixed(1)
            }
            val formatDirection = ::gen_formatDirection_fn
            fun formatAccuracy(value: Any?): String {
                if (value == null) {
                    return "null"
                }
                if (UTSAndroid.`typeof`(value) == "number") {
                    return (value as Number).toFixed(2)
                }
                return value as String
            }
            fun gen_resolveDirectionText_fn(value: Number): String {
                if (value >= 337.5 || value < 22.5) {
                    return "北"
                }
                if (value < 67.5) {
                    return "东北"
                }
                if (value < 112.5) {
                    return "东"
                }
                if (value < 157.5) {
                    return "东南"
                }
                if (value < 202.5) {
                    return "南"
                }
                if (value < 247.5) {
                    return "西南"
                }
                if (value < 292.5) {
                    return "西"
                }
                return "西北"
            }
            val resolveDirectionText = ::gen_resolveDirectionText_fn
            val compassStyle = computed(fun(): String {
                return "transform: rotate(" + -direction.value + "deg);"
            }
            )
            val degreeText = computed(fun(): String {
                return "" + formatDirection(direction.value) + "\u00B0"
            }
            )
            val primaryListener: OnCompassChangeCallback = fun(result: OnCompassChangeCallbackResult){
                direction.value = result.direction
                directionText.value = resolveDirectionText(result.direction)
                accuracyText.value = formatAccuracy(if (result.accuracy != null) {
                    result.accuracy
                } else {
                    null
                }
                )
                statusText.value = "监听中"
            }
            val secondaryListener: OnCompassChangeCallback = fun(result: OnCompassChangeCallbackResult){
                pushLog("额外监听 -> " + formatDirection(result.direction) + "\u00B0 / accuracy " + formatAccuracy(if (result.accuracy != null) {
                    result.accuracy
                } else {
                    null
                }
                ))
            }
            fun gen_ensurePrimaryBound_fn(): Unit {
                if (!primaryBound.value) {
                    uni_onCompassChange(primaryListener)
                    primaryBound.value = true
                }
            }
            val ensurePrimaryBound = ::gen_ensurePrimaryBound_fn
            fun gen_bindPrimaryListener_fn(): Unit {
                ensurePrimaryBound()
                updateResult("onCompassChange(primary)", "已绑定", "主监听已注册")
            }
            val bindPrimaryListener = ::gen_bindPrimaryListener_fn
            fun gen_bindSecondaryListener_fn(): Unit {
                if (!secondaryBound.value) {
                    uni_onCompassChange(secondaryListener)
                    secondaryBound.value = true
                }
                updateResult("onCompassChange(extra)", "已绑定", "额外监听已注册")
            }
            val bindSecondaryListener = ::gen_bindSecondaryListener_fn
            fun gen_removePrimaryListener_fn(): Unit {
                uni_offCompassChange(primaryListener)
                primaryBound.value = false
                updateResult("offCompassChange(primary)", "已解绑", "主监听已移除")
            }
            val removePrimaryListener = ::gen_removePrimaryListener_fn
            fun gen_removeSecondaryListener_fn(): Unit {
                uni_offCompassChange(secondaryListener)
                secondaryBound.value = false
                updateResult("offCompassChange(extra)", "已解绑", "额外监听已移除")
            }
            val removeSecondaryListener = ::gen_removeSecondaryListener_fn
            fun gen_startCompassListen_fn(): Unit {
                ensurePrimaryBound()
                uni_startCompass(StartCompassOptions(success = fun(res){
                    statusText.value = "监听中"
                    val message = if (res.errMsg != null) {
                        res.errMsg as String
                    } else {
                        "startCompass:ok"
                    }
                    updateResult("startCompass", "成功", message)
                }
                , fail = fun(error){
                    statusText.value = "启动失败"
                    val message = if (error.errMsg != null) {
                        error.errMsg
                    } else {
                        "startCompass:fail"
                    }
                    updateResult("startCompass", "失败 (" + error.errCode + ")", message)
                }
                ))
            }
            val startCompassListen = ::gen_startCompassListen_fn
            fun gen_stopCompassListen_fn(): Unit {
                uni_stopCompass(StopCompassOptions(success = fun(res){
                    statusText.value = "已停止"
                    val message = if (res.errMsg != null) {
                        res.errMsg as String
                    } else {
                        "stopCompass:ok"
                    }
                    updateResult("stopCompass", "成功", message)
                }
                , fail = fun(error){
                    val message = if (error.errMsg != null) {
                        error.errMsg
                    } else {
                        "stopCompass:fail"
                    }
                    updateResult("stopCompass", "失败 (" + error.errCode + ")", message)
                }
                ))
            }
            val stopCompassListen = ::gen_stopCompassListen_fn
            onUnload(fun(){
                uni_offCompassChange(primaryListener)
                uni_offCompassChange(secondaryListener)
                uni_stopCompass(null)
            }
            )
            __expose(_uM("startCompassListen" to startCompassListen))
            return fun(): Any? {
                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 "notice"), "演示 `uni.startCompass`、`uni.stopCompass`、`uni.onCompassChange`、`uni.offCompassChange` 的完整流程。靠近强磁场或金属物体时数据可能抖动，可做“8”字校准。Web平台需使用https"),
                    _cE("text", _uM("class" to "margin-v"), "先绑定监听，再启动采集，更容易观察回调是否生效。"),
                    _cE("text", _uM("class" to "uni-h3"), "实时信息"),
                    _cE("view", _uM("class" to "panel-list"), _uA(
                        _cE(Fragment, null, RenderHelpers.renderList(unref(infoItems), fun(item, __key, __index, _cached): Any {
                            return _cE("text", _uM("class" to "panel-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 "compass-card"), _uA(
                        _cE("view", _uM("class" to "bg-compass-line")),
                        _cE("image", _uM("class" to "bg-compass", "src" to "/static/compass.png", "style" to _nS(unref(compassStyle))), null, 4),
                        _cE("view", _uM("class" to "direction-center"), _uA(
                            _cE("text", _uM("class" to "direction-value"), _tD(unref(directionText)), 1),
                            _cE("text", _uM("class" to "direction-degree"), _tD(unref(degreeText)), 1)
                        ))
                    )),
                    _cE("view", _uM("class" to "uni-row"), _uA(
                        _cE("button", _uM("id" to "btn-bind-primary-listener", "class" to "margin-v", "onClick" to bindPrimaryListener), "注册罗盘Change"),
                        _cE("button", _uM("id" to "btn-remove-primary-listener", "class" to "margin-v", "style" to _nS(_uM("margin-left" to "3px")), "onClick" to removePrimaryListener), "注销罗盘Change", 4)
                    )),
                    _cE("view", _uM("class" to "uni-row"), _uA(
                        _cE("button", _uM("id" to "btn-start-compass", "class" to "margin-v", "type" to "primary", "onClick" to startCompassListen), "uni.startCompass"),
                        _cE("button", _uM("id" to "btn-stop-compass", "class" to "margin-v", "style" to _nS(_uM("margin-left" to "3px")), "onClick" to stopCompassListen), "uni.stopCompass", 4)
                    )),
                    _cE("text", null, "重复绑定测试"),
                    _cE("view", _uM("class" to "uni-row"), _uA(
                        _cE("button", _uM("id" to "btn-bind-secondary-listener", "class" to "margin-v", "onClick" to bindSecondaryListener), "注册罗盘Change2"),
                        _cE("button", _uM("id" to "btn-remove-secondary-listener", "class" to "margin-v", "style" to _nS(_uM("margin-left" to "3px")), "onClick" to removeSecondaryListener), "注销罗盘Change2", 4)
                    )),
                    _cE("text", _uM("class" to "uni-h3"), "监听日志"),
                    _cE("view", _uM("class" to "panel-list"), _uA(
                        _cE(Fragment, null, RenderHelpers.renderList(unref(logItems), fun(item, __key, __index, _cached): Any {
                            return _cE("text", _uM("class" to "panel-item", "key" to item.id), _tD(item.text), 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 "#6b2d16", "fontSize" to 14)), "panel-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")), "panel-item" to _pS(_uM("fontSize" to 14, "marginTop" to 4, "marginRight" to 0, "marginBottom" to 4, "marginLeft" to 0)), "compass-card" to _pS(_uM("position" to "relative", "marginTop" to 12, "marginRight" to "auto", "marginBottom" to 12, "marginLeft" to "auto", "width" to 270, "height" to 270, "display" to "flex", "flexDirection" to "column", "alignItems" to "center", "justifyContent" to "center")), "direction-center" to _pS(_uM("position" to "relative", "zIndex" to 1, "display" to "flex", "flexDirection" to "column", "alignItems" to "center")), "direction-value" to _pS(_uM("fontSize" to 30)), "direction-degree" to _pS(_uM("fontSize" to 16, "marginTop" to 6)), "bg-compass" to _pS(_uM("position" to "absolute", "top" to 0, "left" to 0, "width" to 270, "height" to 270, "transitionDuration" to "0.1s")), "bg-compass-line" to _pS(_uM("position" to "absolute", "left" to 134, "top" to -5, "width" to 3, "height" to 28, "backgroundColor" to "#1aad19", "borderTopLeftRadius" to 100, "borderTopRightRadius" to 100, "borderBottomRightRadius" to 100, "borderBottomLeftRadius" to 100, "zIndex" to 1)), "@TRANSITION" to _uM("bg-compass" to _uM("duration" to "0.1s")))
            }
        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()
    }
}
