<?php

namespace App\Http\Resources\Gallery;

use Illuminate\Http\Resources\Json\JsonResource;

class GallerySection extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        $out = [
            'uid'             => $this->uid,
            'name'            => $this->name,
            'description'     => $this->description,
            'position'        => $this->position,
            'settings'        => $this->settings ? $this->settings : $this->getDefaultSettings(),
            'items'           => GalleryItem::collection($this->whenLoaded('galleryItems'))
        ];

        return $out;
    }

    protected function getDefaultSettings() {
        return [
            'layout' => 'grid',
            'layoutOptions' => [
                'width' => 'medium',
                'imageSize' => 'medium',
                'imageSpacing' => 'medium'
            ]
        ];
    }
}
