'use server';

import React from 'react';

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

import { Trans } from '@kit/ui/makerkit/trans';

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 < 1) {
    return null;
  }

  return (
    <div>
      <h4>
        <Trans i18nKey="dashboard:recommendations.title" />
      </h4>
      <OrderAnalysesCards analyses={orderAnalyses} countryCode={countryCode} />
    </div>
  );
}
