<?php

namespace Tricks\MediaLibraryOverrides\ResponsiveImages\WidthCalculator;

use Exception;
use Illuminate\Support\Collection;
use Spatie\MediaLibrary\ResponsiveImages\WidthCalculator\FileSizeOptimizedWidthCalculator;
use Throwable;

class StaticWidthsCalculator extends FileSizeOptimizedWidthCalculator
{
    // matches https://image.nuxtjs.org/api/options#screens
    public const DEFAULT_NUXT_SCREENS = [
        320,
        640,
        768,
        1024,
        1280,
        1536,
    ];

    /**
     * @return Collection<int|string, mixed>
     * @throws Throwable
     */
    public function calculateWidths(int $fileSize, int $width, int $height): Collection
    {
        $screens = config('media-library.nuxt-screens', self::DEFAULT_NUXT_SCREENS);

        throw_unless(is_array($screens), new Exception('media-library.nuxt-screens is not an array.'));

        return collect($screens);
    }
}
