@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
open class GenUniModulesUniNumberBoxComponentsUniNumberBoxUniNumberBox : VueComponent {
    constructor(__ins: ComponentInternalInstance) : super(__ins) {}
    open var value: Number by `$props`
    open var modelValue: Number by `$props`
    open var min: Number by `$props`
    open var max: Number by `$props`
    open var step: Number by `$props`
    open var disabled: Boolean by `$props`
    open var btnClass: Any? by `$props`
    open var inputClass: Any? by `$props`
    open var iconClass: Any? by `$props`
    companion object {
        @Suppress("UNUSED_PARAMETER", "UNUSED_VARIABLE")
        var setup: (__props: GenUniModulesUniNumberBoxComponentsUniNumberBoxUniNumberBox) -> Any? = fun(__props): Any? {
            val __ins = getCurrentInstance()!!
            val _ctx = __ins.proxy as GenUniModulesUniNumberBoxComponentsUniNumberBoxUniNumberBox
            val _cache = __ins.renderCache
            val props = __props
            fun emit(event: String, vararg do_not_transform_spread: Any?) {
                __ins.emit(event, *do_not_transform_spread)
            }
            val inputValue = ref<String>("")
            val getDecimalScale = fun(): Number {
                var scale: Number = 1
                if (Math.floor(props.step) != props.step) {
                    val stepStr = props.step.toString(10)
                    val dotIndex = stepStr.indexOf(".")
                    if (dotIndex != -1) {
                        val decimalPart = stepStr.substring(dotIndex + 1)
                        scale = Math.pow(10, decimalPart.length) as Number
                    }
                }
                return scale
            }
            val formatValue = fun(value: Number): String {
                val scale = getDecimalScale()
                val scaleStr = scale.toString(10)
                val precision = scaleStr.length - 1
                return value.toFixed(precision)
            }
            val emitChange = fun(value: Number): Unit {
                emit("update:modelValue", value)
                emit("change", value)
            }
            val initValue = fun(): Unit {
                var kVal: Number = props.value
                if (props.modelValue != 1) {
                    kVal = props.modelValue
                }
                inputValue.value = formatValue(kVal)
            }
            val minusDisabled = computed(fun(): Boolean {
                val currentVal = parseFloat(inputValue.value)
                if (isNaN(currentVal)) {
                    return true
                }
                return currentVal <= props.min || props.disabled
            }
            )
            val plusDisabled = computed(fun(): Boolean {
                val currentVal = parseFloat(inputValue.value)
                if (isNaN(currentVal)) {
                    return true
                }
                return currentVal >= props.max || props.disabled
            }
            )
            val onMinus = fun(): Unit {
                if (props.disabled) {
                    return
                }
                val scale = getDecimalScale()
                var currentVal = parseFloat(inputValue.value)
                if (isNaN(currentVal)) {
                    currentVal = props.min
                }
                var value = currentVal * scale
                val stepScaled = props.step * scale
                value -= stepScaled
                if (value < props.min * scale) {
                    return
                }
                if (value > props.max * scale) {
                    value = props.max * scale
                }
                val newValue = value / scale
                inputValue.value = formatValue(newValue)
                emitChange(newValue)
            }
            val onPlus = fun(): Unit {
                if (props.disabled) {
                    return
                }
                val scale = getDecimalScale()
                var currentVal = parseFloat(inputValue.value)
                if (isNaN(currentVal)) {
                    currentVal = props.min
                }
                var value = currentVal * scale
                val stepScaled = props.step * scale
                value += stepScaled
                if (value > props.max * scale) {
                    return
                }
                if (value < props.min * scale) {
                    value = props.min * scale
                }
                val newValue = value / scale
                inputValue.value = formatValue(newValue)
                emitChange(newValue)
            }
            val onBlur = fun(event: UniInputBlurEvent): Unit {
                emit("blur", event)
                var value = parseFloat(event.detail.value)
                if (isNaN(value)) {
                    inputValue.value = formatValue(props.value)
                    return
                }
                if (value > props.max) {
                    value = props.max
                } else if (value < props.min) {
                    value = props.min
                }
                inputValue.value = formatValue(value)
                emitChange(value)
            }
            val onFocus = fun(event: UniInputFocusEvent): Unit {
                emit("focus", event)
            }
            watch(fun(): Number? {
                return props.modelValue ?: props.value ?: null
            }
            , fun(newValue: Number?){
                if (newValue != null) {
                    inputValue.value = formatValue(newValue)
                }
            }
            )
            initValue()
            return fun(): Any? {
                return _cE("view", _uM("class" to "uni-numbox"), _uA(
                    _cE("view", _uM("class" to _nC(_uA(
                        "uni-numbox__btn uni-numbox__minus",
                        _ctx.btnClass
                    )), "onClick" to onMinus), _uA(
                        _cE("view", _uM("class" to _nC(_uA(
                            "uni-numbox__icon-line",
                            _uA(
                                _ctx.iconClass,
                                if (unref(minusDisabled)) {
                                    "uni-numbox__icon-line--disabled"
                                } else {
                                    ""
                                }
                            )
                        ))), null, 2)
                    ), 2),
                    _cE("input", _uM("class" to _nC(_uA(
                        "uni-numbox__input",
                        _ctx.inputClass
                    )), "disabled" to _ctx.disabled, "type" to if (_ctx.step < 1) {
                        "digit"
                    } else {
                        "number"
                    }
                    , "modelValue" to unref(inputValue), "onInput" to fun(`$event`: UniInputEvent){
                        trySetRefValue(inputValue, `$event`.detail.value)
                    }
                    , "onFocus" to onFocus, "onBlur" to onBlur), null, 42, _uA(
                        "disabled",
                        "type",
                        "modelValue"
                    )),
                    _cE("view", _uM("class" to _nC(_uA(
                        "uni-numbox__btn uni-numbox__plus",
                        _ctx.btnClass
                    )), "onClick" to onPlus), _uA(
                        _cE("view", _uM("class" to _nC(_uA(
                            "uni-numbox__icon-line",
                            _uA(
                                _ctx.iconClass,
                                if (unref(plusDisabled)) {
                                    "uni-numbox__icon-line--disabled"
                                } else {
                                    ""
                                }
                            )
                        ))), null, 2),
                        _cE("view", _uM("class" to _nC(_uA(
                            "uni-numbox__icon-line uni-numbox__icon-line--vertical",
                            _uA(
                                _ctx.iconClass,
                                if (unref(plusDisabled)) {
                                    "uni-numbox__icon-line--disabled"
                                } else {
                                    ""
                                }
                            )
                        ))), null, 2)
                    ), 2)
                ))
            }
        }
        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("uni-numbox" to _pS(_uM("flexDirection" to "row", "alignItems" to "center")), "uni-numbox__btn" to _pS(_uM("width" to 26, "height" to 26, "backgroundColor" to "#f5f5f5", "alignItems" to "center", "justifyContent" to "center")), "uni-numbox__minus" to _pS(_uM("borderTopLeftRadius" to 2, "borderBottomLeftRadius" to 2)), "uni-numbox__plus" to _pS(_uM("borderTopRightRadius" to 2, "borderBottomRightRadius" to 2)), "uni-numbox__icon-line" to _pS(_uM("position" to "absolute", "width" to 10, "height" to 1, "backgroundColor" to "#333333")), "uni-numbox__icon-line--vertical" to _pS(_uM("transform" to "rotate(90deg)")), "uni-numbox__icon-line--disabled" to _pS(_uM("backgroundColor" to "#c0c0c0")), "uni-numbox__input" to _pS(_uM("marginTop" to 0, "marginRight" to 2, "marginBottom" to 0, "marginLeft" to 2, "backgroundColor" to "#f5f5f5", "width" to 40, "height" to 26, "textAlign" to "center", "fontSize" to 14, "borderTopWidth" to 0, "borderRightWidth" to 0, "borderBottomWidth" to 0, "borderLeftWidth" to 0, "color" to "#333333")))
            }
        var inheritAttrs = true
        var inject: Map<String, Map<String, Any?>> = _uM()
        var emits: Map<String, Any?> = _uM("change" to null, "update:modelValue" to null, "blur" to null, "focus" to null)
        var props = _nP(_uM("value" to _uM("type" to "Number", "required" to false, "default" to 1), "modelValue" to _uM("type" to "Number", "required" to false, "default" to 1), "min" to _uM("type" to "Number", "required" to false, "default" to 0), "max" to _uM("type" to "Number", "required" to false, "default" to 100), "step" to _uM("type" to "Number", "required" to false, "default" to 1), "disabled" to _uM("type" to "Boolean", "required" to false, "default" to false), "btnClass" to _uM("required" to false, "default" to "", "externalClasses" to true, "skipCheck" to true), "inputClass" to _uM("required" to false, "default" to "", "externalClasses" to true, "skipCheck" to true), "iconClass" to _uM("required" to false, "default" to "", "externalClasses" to true, "skipCheck" to true)))
        var propsNeedCastKeys = _uA(
            "value",
            "modelValue",
            "min",
            "max",
            "step",
            "disabled",
            "btnClass",
            "inputClass",
            "iconClass"
        )
        var components: Map<String, CreateVueComponent> = _uM()
    }
}
