@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
import io.dcloud.uniapp.extapi.navigateTo as uni_navigateTo
import uts.sdk.modules.utsOpenSchema.openSchema
import io.dcloud.uniapp.extapi.setClipboardData as uni_setClipboardData
import io.dcloud.uniapp.extapi.showModal as uni_showModal
open class GenUniModulesUniLinkComponentsUniLinkUniLink : VueComponent {
    constructor(__ins: ComponentInternalInstance) : super(__ins) {}
    open var href: String by `$props`
    open var target: String by `$props`
    open var blankFallback: String by `$props`
    companion object {
        @Suppress("UNUSED_PARAMETER", "UNUSED_VARIABLE")
        var setup: (__props: GenUniModulesUniLinkComponentsUniLinkUniLink) -> Any? = fun(__props): Any? {
            val __ins = getCurrentInstance()!!
            val _ctx = __ins.proxy as GenUniModulesUniLinkComponentsUniLinkUniLink
            val _cache = __ins.renderCache
            val LINK_WEBVIEW_PAGE_PATH = "/uni_modules/uni-link/pages/link-webview"
            val props = __props
            fun emit(event: String, vararg do_not_transform_spread: Any?) {
                __ins.emit(event, *do_not_transform_spread)
            }
            val appLanguage = (uni_getAppBaseInfo(null).appLanguage ?: "en").toLowerCase()
            fun gen_resolveLocaleType_fn(): LocaleType {
                if (appLanguage.indexOf("zh-hant") == 0 || appLanguage.indexOf("zh-tw") == 0 || appLanguage.indexOf("zh-hk") == 0 || appLanguage.indexOf("zh-mo") == 0) {
                    return "zh-Hant"
                }
                if (appLanguage.indexOf("zh") == 0) {
                    return "zh-Hans"
                }
                if (appLanguage.indexOf("fr") == 0) {
                    return "fr"
                }
                if (appLanguage.indexOf("la") == 0 || appLanguage.indexOf("lat") == 0) {
                    return "la"
                }
                return "en"
            }
            val resolveLocaleType = ::gen_resolveLocaleType_fn
            fun gen_getLocaleMessages_fn(): LocaleMessages {
                val localeType = resolveLocaleType()
                if (localeType == "zh-Hans") {
                    return LocaleMessages(emptyHref = "链接地址不能为空", popupBlocked = "浏览器拦截了新窗口", internalOpenFailed = "应用中未找到uni-link组件下的link-webview页面", copiedOpenInBrowserPrefix = "已复制链接，请使用外部浏览器打开：", copyFailedOpenInBrowser = "复制链接失败，请手动复制链接并使用外部浏览器打开")
                }
                if (localeType == "zh-Hant") {
                    return LocaleMessages(emptyHref = "連結地址不能為空", popupBlocked = "瀏覽器封鎖了新視窗", internalOpenFailed = "應用中未找到 uni-link 組件下的 link-webview 頁面", copiedOpenInBrowserPrefix = "已複製連結，請使用外部瀏覽器開啟：", copyFailedOpenInBrowser = "複製連結失敗，請手動複製連結並使用外部瀏覽器開啟")
                }
                if (localeType == "fr") {
                    return LocaleMessages(emptyHref = "L’URL ne peut pas être vide", popupBlocked = "Le navigateur a bloqué la nouvelle fenêtre", internalOpenFailed = "Échec de l'ouverture de la page @uni_modules/uni-link/pages/link-webview", copiedOpenInBrowserPrefix = "Le lien a été copié. Veuillez l’ouvrir dans un navigateur externe :", copyFailedOpenInBrowser = "Échec de la copie du lien. Veuillez le copier manuellement et l’ouvrir dans un navigateur externe.")
                }
                if (localeType == "la") {
                    return LocaleMessages(emptyHref = "Inscriptio nexus vacua esse non potest", popupBlocked = "Navigator fenestram novam prohibuit", internalOpenFailed = "Pagina aperiri non potuit @uni_modules/uni-link/pages/link-webview", copiedOpenInBrowserPrefix = "Nexus descriptus est. Quaeso eum in navigatro externo aperi:", copyFailedOpenInBrowser = "Descriptio nexus defecit. Quaeso nexum manu describe et in navigatro externo aperi.")
                }
                return LocaleMessages(emptyHref = "The link URL cannot be empty", popupBlocked = "The browser blocked the new window", internalOpenFailed = "Failed to open page @uni_modules/uni-link/pages/link-webview", copiedOpenInBrowserPrefix = "The link has been copied. Please open it in an external browser:", copyFailedOpenInBrowser = "Failed to copy the link. Please copy it manually and open it in an external browser.")
            }
            val getLocaleMessages = ::gen_getLocaleMessages_fn
            fun gen_showPrompt_fn(content: String) {
                uni_showModal(ShowModalOptions(content = content, showCancel = false))
            }
            val showPrompt = ::gen_showPrompt_fn
            fun gen_copyLinkAndPrompt_fn(url: String) {
                val messages = getLocaleMessages()
                uni_setClipboardData(SetClipboardDataOptions(data = url, showToast = false, success = fun(_){
                    showPrompt(messages.copiedOpenInBrowserPrefix + "\n" + url)
                }
                , fail = fun(_){
                    showPrompt(messages.copyFailedOpenInBrowser)
                }
                ))
            }
            val copyLinkAndPrompt = ::gen_copyLinkAndPrompt_fn
            fun gen_reportOpenError_fn(message: String) {
                emit("error", message)
            }
            val reportOpenError = ::gen_reportOpenError_fn
            fun gen_openInBuiltInWebview_fn(url: String) {
                uni_navigateTo(NavigateToOptions(url = "" + LINK_WEBVIEW_PAGE_PATH + "?url=" + encodeURIComponent(url), success = fun(_){}, fail = fun(_){
                    reportOpenError(getLocaleMessages().internalOpenFailed)
                }
                ))
            }
            val openInBuiltInWebview = ::gen_openInBuiltInWebview_fn
            fun gen_openURL_fn() {
                val url = props.href.trim()
                if (url.length == 0) {
                    reportOpenError(getLocaleMessages().emptyHref)
                    return
                }
                if (props.target == "_self") {
                    openInBuiltInWebview(url)
                } else {
                    try {
                        openSchema(url)
                    }
                     catch (error: Throwable) {
                        if (props.blankFallback == "turn-self") {
                            openInBuiltInWebview(url)
                        } else if (props.blankFallback == "copy-link-modal") {
                            copyLinkAndPrompt(url)
                        } else {
                            reportOpenError((error as UTSError).message)
                        }
                    }
                }
            }
            val openURL = ::gen_openURL_fn
            return fun(): Any? {
                return _cE("text", _uM("style" to _nS(_uM("text-decoration-line" to "underline")), "onClick" to openURL), _uA(
                    renderSlot(_ctx.`$slots`, "default")
                ), 4)
            }
        }
        var name = "UniLink"
        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("error" to null)
        var props = _nP(_uM("href" to _uM("type" to "String", "required" to false, "default" to ""), "target" to _uM("type" to "String", "required" to false, "default" to "_self"), "blankFallback" to _uM("type" to "String", "required" to true, "default" to "turn-self")))
        var propsNeedCastKeys = _uA(
            "href",
            "target",
            "blankFallback"
        )
        var components: Map<String, CreateVueComponent> = _uM()
    }
}
