// https://nuxt.com/docs/api/configuration/nuxt-config
import { IUser } from "~/models/user";
import { defineNuxtModule } from "@nuxt/kit";
// import speedkitHydrate from "nuxt-speedkit/dist/runtime/hydrate.mjs";

export type SessionData = IUser;
const ct =
	<T>() =>
	<U extends T>(u: U) =>
		u;
export default defineNuxtConfig({
	experimental: {
		watcher: "chokidar-granular",
		// noScripts: true,
		treeshakeClientOnly: false,
	},
	devtools: { enabled: false },
	modules: [
		"vue-recaptcha/nuxt",
		"@ant-design-vue/nuxt",
		"@sidebase/nuxt-auth",
		"@pinia/nuxt",
		"@vueuse/nuxt",
		// defineNuxtModule({
		// 	async setup(options, nuxt) {
		// 		nuxt.hook("components:extend", (components) => {
		// 			// console.log(components);
		// 			// components = components.map((a) => {
		// 			// 	return speedkitHydrate(() => import(a.filePath));
		// 			// });
		// 		});
		// 	},
		// }),
		// "nuxt-speedkit",
	],
	// speedkit: {
	// 	disableNuxtFontaine: true,
	// },
	css: ["~/public/fonts.css", "~/public/css/all.css"],
	auth: {
		provider: {
			type: "local",
			pages: {
				login: "/login",
			},
			token: {
				signInResponseTokenPointer: "/token",
				type: "Bearer",
				headerName: "Authorization",
				maxAgeInSeconds: 168 * 24 * 60 * 60,
				sameSiteAttribute: "lax",
			},
			sessionDataType: {} as { [Property in keyof IUser]: string },
			endpoints: {
				signUp: { path: "/register", method: "post" },
			},
		},
		globalAppMiddleware: {
			isEnabled: false,
		},
	},
	nitro: {
		esbuild: {
			options: {
				minify: true,
				// sourceMap: false,
			},
		},
	},

	// routeRules: {
	// "/**": {
	// 	cache: {
	// 		maxAge: 60,
	// 		headersOnly: true,
	// 	},
	// 	// swr: 60 * 60,
	// },
	// },
	// ssr: false,
	runtimeConfig: {
		captcha: {
			secret: process.env.CAPTCHASECRET,
			key: process.env.CAPTCHAKEY,
		},
		database: {
			user: process.env.DBUSER,
			password: process.env.DBPASS,
			uri: `mongodb://${process.env.DB}`,
		},
		jwt: process.env.JWT,
		public: {
			recaptcha: {
				v2SiteKey: process.env.CAPTCHAKEY,
			},
			// apiBase: "/api"
		},
		nodebb: {
			masterToken: process.env.nbb_bearer,
		},
	},
	// components: {
	// 	transform: (str) =>
	// },
});
