import { redirect } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
import {
	countTransaksiBulanIni,
	getAllPaket,
	getMemberEntitlements,
	getMemberLangganan
} from '$lib/server/langganan';

export const load: PageServerLoad = async ({ locals }) => {
	if (!locals.member) {
		throw redirect(303, '/login');
	}

	const [paketList, langganan, entitlements, transaksiBulanIni] = await Promise.all([
		getAllPaket(true),
		getMemberLangganan(locals.member.id),
		getMemberEntitlements(locals.member.id),
		countTransaksiBulanIni(locals.member.id)
	]);

	return {
		member: locals.member,
		paketList,
		langganan,
		entitlements,
		transaksiBulanIni
	};
};
