@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.getAppBaseInfo as uni_getAppBaseInfo
open class GenUniModulesUniTimeFormatComponentsUniTimeFormatUniTimeFormat : VueComponent {
    constructor(__ins: ComponentInternalInstance) : super(__ins) {}
    open var timestamp: Number by `$props`
    open var format: String by `$props`
    companion object {
        @Suppress("UNUSED_PARAMETER", "UNUSED_VARIABLE")
        var setup: (__props: GenUniModulesUniTimeFormatComponentsUniTimeFormatUniTimeFormat) -> Any? = fun(__props): Any? {
            val __ins = getCurrentInstance()!!
            val _ctx = __ins.proxy as GenUniModulesUniTimeFormatComponentsUniTimeFormatUniTimeFormat
            val _cache = __ins.renderCache
            val props = __props
            val appLanguage = (uni_getAppBaseInfo(null).appLanguage ?: "en").toLowerCase()
            val formattedTime = ref<String>("")
            fun gen_padZero_fn(num: Number): String {
                return if (num < 10) {
                    "0" + num.toString(10)
                } else {
                    num.toString(10)
                }
            }
            val padZero = ::gen_padZero_fn
            fun gen_normalizeTimestamp_fn(timestamp: Number): Number {
                val absTimestamp = Math.abs(timestamp)
                if (absTimestamp > 0 && absTimestamp < 100000000000) {
                    return timestamp * 1000
                }
                return timestamp
            }
            val normalizeTimestamp = ::gen_normalizeTimestamp_fn
            fun gen_isValidDate_fn(date: Date): Boolean {
                return !isNaN(date.getTime())
            }
            val isValidDate = ::gen_isValidDate_fn
            fun gen_getLocaleKey_fn(language: String): String {
                if (language.indexOf("zh-hant") == 0 || language.indexOf("zh-tw") == 0 || language.indexOf("zh-hk") == 0 || language.indexOf("zh-mo") == 0) {
                    return "zh-hant"
                }
                if (language.indexOf("zh") == 0) {
                    return "zh-hans"
                }
                if (language.indexOf("fr") == 0) {
                    return "fr"
                }
                if (language.indexOf("la") == 0) {
                    return "la"
                }
                return "en"
            }
            val getLocaleKey = ::gen_getLocaleKey_fn
            val localeKey = getLocaleKey(appLanguage)
            fun gen_formatDateTime_fn(date: Date): String {
                val year = date.getFullYear()
                val month = padZero(date.getMonth() + 1)
                val day = padZero(date.getDate())
                val hours = padZero(date.getHours())
                val minutes = padZero(date.getMinutes())
                return "" + year + "-" + month + "-" + day + " " + hours + ":" + minutes
            }
            val formatDateTime = ::gen_formatDateTime_fn
            fun gen_formatTime_fn(date: Date): String {
                return "" + padZero(date.getHours()) + ":" + padZero(date.getMinutes())
            }
            val formatTime = ::gen_formatTime_fn
            fun gen_getNowText_fn(localeKey: String): String {
                if (localeKey == "zh-hans") {
                    return "刚刚"
                }
                if (localeKey == "zh-hant") {
                    return "刚刚"
                }
                if (localeKey == "fr") {
                    return "mnt."
                }
                if (localeKey == "la") {
                    return "nunc"
                }
                return "now"
            }
            val getNowText = ::gen_getNowText_fn
            fun gen_formatMinuteAgo_fn(localeKey: String, minutes: Number): String {
                if (localeKey == "zh-hans") {
                    return "" + minutes + "分钟前"
                }
                if (localeKey == "zh-hant") {
                    return "" + minutes + "分鐘前"
                }
                if (localeKey == "fr") {
                    return "-" + minutes + "min"
                }
                if (localeKey == "la") {
                    return "-" + minutes + "m"
                }
                return "" + minutes + "m ago"
            }
            val formatMinuteAgo = ::gen_formatMinuteAgo_fn
            fun gen_formatHourAgo_fn(localeKey: String, hours: Number): String {
                if (localeKey == "zh-hans") {
                    return "" + hours + "小时前"
                }
                if (localeKey == "zh-hant") {
                    return "" + hours + "小時前"
                }
                if (localeKey == "fr") {
                    return "-" + hours + "h"
                }
                if (localeKey == "la") {
                    return "-" + hours + "h"
                }
                return "" + hours + "h ago"
            }
            val formatHourAgo = ::gen_formatHourAgo_fn
            fun gen_formatYesterday_fn(localeKey: String, timeText: String): String {
                if (localeKey == "zh-hant" || localeKey == "zh-hans") {
                    return "昨天 " + timeText
                }
                if (localeKey == "fr") {
                    return "hier " + timeText
                }
                if (localeKey == "la") {
                    return "heri " + timeText
                }
                return "yest " + timeText
            }
            val formatYesterday = ::gen_formatYesterday_fn
            fun gen_getDayStartTimestamp_fn(date: Date): Number {
                return Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime()
            }
            val getDayStartTimestamp = ::gen_getDayStartTimestamp_fn
            fun gen_getRelativeTime_fn(targetDate: Date, currentTimestamp: Number): String {
                val targetTimestamp = targetDate.getTime()
                if (targetTimestamp > currentTimestamp) {
                    return formatDateTime(targetDate)
                }
                val nowDate = Date(currentTimestamp)
                val todayStart = getDayStartTimestamp(nowDate)
                val yesterdayStart = todayStart - 86400000
                if (targetTimestamp >= todayStart) {
                    val diffMs = currentTimestamp - targetTimestamp
                    if (diffMs < 60000) {
                        return getNowText(localeKey)
                    }
                    val diffMinutes = Math.floor(diffMs / 60000)
                    if (diffMinutes < 60) {
                        return formatMinuteAgo(localeKey, diffMinutes)
                    }
                    val diffHours = Math.floor(diffMs / 3600000)
                    return formatHourAgo(localeKey, diffHours)
                }
                if (targetTimestamp >= yesterdayStart) {
                    return formatYesterday(localeKey, formatTime(targetDate))
                }
                return formatDateTime(targetDate)
            }
            val getRelativeTime = ::gen_getRelativeTime_fn
            fun gen_refreshFormattedTime_fn() {
                val normalizedTimestamp = normalizeTimestamp(props.timestamp)
                val targetDate = Date(normalizedTimestamp)
                if (!isValidDate(targetDate)) {
                    formattedTime.value = ""
                    return
                }
                val formatType = props.format
                if (formatType == "relative") {
                    formattedTime.value = getRelativeTime(targetDate, Date.now())
                    return
                }
                val hours = padZero(targetDate.getHours())
                val minutes = padZero(targetDate.getMinutes())
                if (formatType == "time") {
                    val seconds = padZero(targetDate.getSeconds())
                    formattedTime.value = "" + hours + ":" + minutes + ":" + seconds
                    return
                }
                val year = targetDate.getFullYear()
                val month = padZero(targetDate.getMonth() + 1)
                val day = padZero(targetDate.getDate())
                if (formatType == "date") {
                    formattedTime.value = "" + year + "-" + month + "-" + day
                    return
                }
                formattedTime.value = "" + year + "-" + month + "-" + day + " " + hours + ":" + minutes
            }
            val refreshFormattedTime = ::gen_refreshFormattedTime_fn
            watch(fun(): String {
                return props.format
            }
            , fun(){
                refreshFormattedTime()
            }
            )
            watch(fun(): Number {
                return props.timestamp
            }
            , fun(){
                refreshFormattedTime()
            }
            )
            onMounted(fun(){
                refreshFormattedTime()
            }
            )
            return fun(): Any? {
                return _cE("text", _uM("class" to "time-text"), _tD(unref(formattedTime)), 1)
            }
        }
        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("time-text" to _pS(_uM("fontSize" to 12, "color" to "#999999")))
            }
        var inheritAttrs = true
        var inject: Map<String, Map<String, Any?>> = _uM()
        var emits: Map<String, Any?> = _uM()
        var props = _nP(_uM("timestamp" to _uM("type" to "Number", "required" to true), "format" to _uM("type" to "String", "required" to false, "default" to "datetime")))
        var propsNeedCastKeys = _uA(
            "format"
        )
        var components: Map<String, CreateVueComponent> = _uM()
    }
}
