<?php

namespace App\Http\Controllers\Athlete;

use App\Http\Controllers\Controller;
use App\Services\Athlete\ProgressChartService;
use Illuminate\View\View;

class ProgressController extends Controller
{
    public function __construct(private readonly ProgressChartService $chartService)
    {
    }

    public function index(): View
    {
        $athlete = auth()->user()->athlete;

        $assessments = $athlete->assessments()
            ->with('photos')
            ->orderBy('assessment_date') // صعودی برای نمودار
            ->get();

        $weightSeries = $this->chartService->series($assessments, 'weight_kg');
        $bmiSeries = $this->chartService->series($assessments, 'bmi');
        $bodyFatSeries = $this->chartService->series($assessments, 'body_fat_percentage');
        $photoPairs = $this->chartService->photoComparisonPairs($assessments);

        return view('athlete.progress.index', [
            'assessments' => $assessments->reverse(), // نزولی برای نمایش Timeline (جدیدترین بالا)
            'weightSeries' => $weightSeries,
            'bmiSeries' => $bmiSeries,
            'bodyFatSeries' => $bodyFatSeries,
            'photoPairs' => $photoPairs,
        ]);
    }
}
