<?php

namespace Tricks\MediaLibraryOverrides\Traits;

use Spatie\Image\Manipulations;
use Spatie\MediaLibrary\InteractsWithMedia;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
use Tricks\MediaLibraryOverrides\ResponsiveImages\WidthCalculator\StaticWidthsCalculator;

trait HasResponsiveConversions
{
    use InteractsWithMedia;
    public static string $MEDIA_CONVERSION_NUXT = 'webp';

    public function registerMediaConversions(Media $media = null): void
    {
        if ($media->mime_type !== 'image/gif') {
            $this->addMediaConversion(static::$MEDIA_CONVERSION_NUXT)
                ->width(max(config('media-library.nuxt-screens', StaticWidthsCalculator::DEFAULT_NUXT_SCREENS)))
                ->withResponsiveImages()
                ->format(Manipulations::FORMAT_WEBP);
        }
    }
}
