import {
	util
} from './modules/util.js'
import prototypes from './modules/prototypes.js'
import {
	PageAnimationTypeIn,
	PageAnimationTypeOut
} from './modules/PageAnimationType.js'

import { env } from '@/env'

import { throttle, debounce } from 'uview-plus'

const sys = uni.getSystemInfoSync();

const $w = {
	uni,
	sys,
	statusBarHeight: sys.statusBarHeight,
	...sys.safeAreaInsets,
	...util,
	...uni.$u,
	t: throttle,
	d: debounce,
	url: (uri = "") => {
		if (Array.isArray(uri)) {
			for (let i = 0; i < uri.length; i++) {
				uri[i] = $w.https(uri[i]);
			}
			return uri;
		} else {
			return $w.https(uri);
		}
	},
	https: (uri = "") => {
		if (uri.toString().includes("://")) {
			if (uri.includes("?")) {
				return uri + "&" + uni.$v.substr(1);
			} else {
				return uri + uni.$v;
			}
		} else if (uri.startsWith("//")) {
			if (uri.includes("?")) {
				return "https:" + uri + "&" + uni.$v.substr(1);
			} else {
				return "https:" + uri + uni.$v;
			}
		} else {
			return env.baseResources + uri + uni.$v;
		}
	}
};




const wComponents = {
	install(Vue) {
		prototypes();
		Vue.config.globalProperties.$w = $w;
		uni.$w = $w;
	}
}

export {
	util,
	$w,
	wComponents,
	PageAnimationTypeIn,
	PageAnimationTypeOut
}