import Layout from '@/app/component/Layout';
import { fetchJson } from '@/lib/utils/server';
import { ChannelListResponse } from '@/types/response/channel/list';
import { ChannelListItem } from '@/types/channel';

export default async function MainLayout({ children }: { children: React.ReactNode }) {

	const res = await fetchJson<ChannelListResponse>('/api/channel/list');
	const initialChannels: ChannelListItem[] = (res.data?.channels ?? []).map((ch, idx) => ({
		...ch,
		_offlineRank: idx
	}));

	return (
		<Layout initialChannels={initialChannels}>
			{children}
		</Layout>
	);
}