import { fetchGenerationMix } from '@/actions/generation.js';
import { GenerationChart } from '@/components/charts/generation-chart.js';

const DEFAULT_REGION = 'PJM';
const DEFAULT_TIME_RANGE = '30d' as const;

export async function GenerationChartSection() {
  const result = await fetchGenerationMix(DEFAULT_REGION, DEFAULT_TIME_RANGE);

  if (!result.ok) {
    return (
      <div className="flex h-96 items-center justify-center rounded-lg border border-dashed border-border">
        <p className="text-sm text-destructive">{result.error}</p>
      </div>
    );
  }

  return (
    <GenerationChart initialData={result.data} initialRegion={DEFAULT_REGION} initialTimeRange={DEFAULT_TIME_RANGE} />
  );
}
