'use server';

import React from 'react';

import { AccountWithParams } from '@/packages/features/accounts/src/types/accounts';

import { loadAnalyses } from '../_lib/server/load-analyses';
import { loadRecommendations } from '../_lib/server/load-recommendations';
import OrderAnalysesCards from './order-analyses-cards';

export default async function Recommendations({
  account,
}: {
  account: AccountWithParams;
}) {
  const { analyses, countryCode } = await loadAnalyses();

  const analysisRecommendations = await loadRecommendations(analyses, account);
  const orderAnalyses = analyses.filter((analysis) =>
    analysisRecommendations.includes(analysis.title),
  );

  if (orderAnalyses.length === 0) {
    return null;
  }

  return (
    <OrderAnalysesCards analyses={orderAnalyses} countryCode={countryCode} />
  );
}
