import { useAppStore } from "@/store/useAppStore"

export const openWeb = (url) => {
    if(!url) return;
    // #ifdef WEB
    requestAnimationFrame(() => {
        window.open(url, '_blank')
    })
    // #endif
    // #ifdef APP-PLUS
    plus.runtime.openURL(url)
    // #endif
}
export const openUrl = (url) => {
    if (!url) { return }
    // #ifdef H5
    const appStore = useAppStore()
    const platform = appStore.appConfig.platform

    if (platform && platform === 'H5_GP_Guitar') {
        if (window.android) {
            window.android.openUrl({
                url: url
            })
        }
        return
    }

    // if (appStore.isNative) {
    // 	if (appStore.appId === 1901) {
    // 		window.location.href = url
    // 	} else {
    // 		requestAnimationFrame(() => {
    // 			window.open(url, '_blank')
    // 		})
    // 	}
    // }
    const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent)
    if (isIOS) {
        window.location.href = url
    } else {
        requestAnimationFrame(() => {
            window.open(url, '_blank')
        })
    }
    // #endif
    // #ifdef APP-PLUS
    // plus.runtime.openURL(url)
    plus.runtime.openURL(url)
    // #endif
}