<?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, $with_undefined = true)
    {
        $src = self::getThumbSrc($image, $with_undefined);
        return $src ? "<img src='$src'>" : '';
    }

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

    public static function getPreview($image, $with_undefined = true)
    {
        $src = self::getPreviewSrc($image, $with_undefined);
        return $src ? "<img src='$src' class='img-fluid'>" : '';
    }

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

    public static function getNormal($image, $with_undefined = true)
    {
        $src = self::getNormalSrc($image, $with_undefined);
        return $src ? "<img src='$src'>" : '';
    }

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

    public static function getImage($image, $with_undefined = true)
    {
        $src = self::getImageSrc($image, $with_undefined);
        return $src ? "<img src='$src' class='img-fluid'>" : '';
    }

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

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