'use server';

import React, { useState } from 'react';

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

import { analysisResponses } from '../(dashboard)/analysis-results/test/test-responses';
import { loadAnalyses } from '../_lib/server/load-analyses';
import { loadRecommendations } from '../_lib/server/load-recommendations';
import OrderAnalysesCards, { OrderAnalysisCard } from './order-analyses-cards';

export default async function Recommendations({
  account,
}: {
  account: AccountWithParams;
}) {
  const { analyses, countryCode } = await loadAnalyses();
  const [isLoadingTimeSlots, setIsLoadingTimeSlots] = useState(false);
  const analysisResults = analysisResponses;
  console.log('selectedDate', isLoadingTimeSlots);
  const analysisRecommendations = await loadRecommendations(
    analysisResults,
    analyses,
    account,
  );
  const orderAnalyses = analyses.filter((analysis) =>
    analysisRecommendations.includes(analysis.title),
  );
  console.log('analysisRecommendations', analysisRecommendations);
  if (orderAnalyses.length < 1) {
    return null;
  }

  return (
    <div>
      <h4>Medreport soovitab teile</h4>
      <OrderAnalysesCards analyses={orderAnalyses} countryCode={countryCode} />
    </div>
  );
}
