<?php

namespace App\Models;

use App\Libs\Database\Eloquent\ContentTypeModel;
use App\Models\GenericBackoffice\Traits\LanguageSupportTrait;
use Grimzy\LaravelMysqlSpatial\Eloquent\SpatialTrait;


class Block extends ContentTypeModel
{
    use LanguageSupportTrait;
    use SpatialTrait;

    protected $hidden = ['languages', "websites"];
    protected $with   = ['languages', "websites"];

    protected $dates         = []; // dates
    protected $spatialFields = ['location']; // Locations lat & longs
    protected $casts         = [];

    public const BLOCK_TYPE_WYSIWYG  = 'blockWysiwyg';
    public const BLOCK_TYPE_LOCATION = 'blockLocation';
    public const BLOCK_TYPE_SLIDER   = 'blockSlider';

    public function slider()
    {
        return $this->belongsToMany(SliderItem::class)->withPivot('position');
    }

    /**
     * Get the associated image
     */
    public function image()
    {
        return $this->belongsTo(MediaItem::class);
    }

    /**
     * Gets the display types for a block
     * @param ?string $type The type of block being displayed
     */
    public static function getDisplayTypeOptions(string $type = null): array
    {

        switch ($type) {
            case static::BLOCK_TYPE_WYSIWYG:
                return [
                    'image_top'    => 'Image above text',
                    //'image_left'   => 'Image to the left of text',
                    //'image_right'  => 'Image to the right of text',
                    'image_bottom' => 'Image below text',
                ];
                break;
            default:
                return [];
        }
    }
}
