<?php

namespace App\Traits\Repository;

use App\Repositories\Core\Medias;

trait Imageable
{
    public static function storeImages($model, $files)
    {
        return Medias::storeImages($model, $files);
    }

    public static function getImages($id)
    {
        return Medias::getImages(self::get($id));
    }

    public static function getThumb($image, $undefined = true)
    {
        $src = self::getThumbSrc($image, $undefined);

        return $src ? "<img src='{$src}'>" : '';
    }

    public static function getThumbSrc($image, $undefined = true)
    {
        return $image ? Medias::getThumbSrc($image) : ($undefined ? '/img/visuel-non-disponible.jpg' : '');
    }

    public static function getPreview($image, $undefined = true)
    {
        $src = self::getPreviewSrc($image, $undefined);

        return $src ? "<img src='{$src}' class='img-fluid'>" : '';
    }

    public static function getPreviewSrc($image, $undefined = true)
    {
        return $image ? Medias::getPreviewSrc($image) : ($undefined ? self::getUnknown() : '');
    }

    public static function getNormal($image, $undefined = true)
    {
        $src = self::getNormalSrc($image, $undefined);

        return $src ? "<img src='{$src}'>" : '';
    }

    public static function getNormalSrc($image, $undefined = true)
    {
        return $image ? Medias::getNormalSrc($image) : ($undefined ? self::getUnknown() : '');
    }

    public static function getZoomSrc($image, $undefined = true)
    {
        return $image ? Medias::getZoomSrc($image) : ($undefined ? self::getUnknown() : '');
    }

    public static function getImage($image, $undefined = true)
    {
        $src = self::getImageSrc($image, $undefined);

        return $src ? "<img src='{$src}' class='img-fluid'>" : '';
    }

    public static function getImageSrc($image, $undefined = true)
    {
        return $image ? Medias::getImageSrc($image) : ($undefined ? self::getUnknown() : '');
    }

    public static function getUnknown()
    {
        return '/img/visuel-non-disponible.jpg';
    }

    public static function deleteImage($id, $index)
    {
        return Medias::deleteImage(self::get($id), $index);
    }
}
