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

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

	// 채널 기능 OFF: 사이드바 미노출이므로 채널 목록 조회 생략
	let initialChannels: ChannelListItem[] = [];
	if (FEATURE_CHANNEL) {
		const res = await fetchJson<ChannelListResponse>('/api/channel/list');
		initialChannels = (res.data?.channels ?? []).map((ch, idx) => ({
			...ch,
			_offlineRank: idx
		}));
	}

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