<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Carbon;

class EventItemResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param \Illuminate\Http\Request $request
     * @return array
     */

    public function toArray($request)
    {
        $out = [
            'id'                  => $this->id,
            'slug'                => '/' . $this->lang_slug,
            'title'               => $this->title,
            'location'            => $this->location,
            'date'                => !empty($this->date) ? Carbon::parse($this->date)->format('d-m-Y') : '',
            'startDate'           => !empty($this->start_date) ? Carbon::parse($this->start_date)->format('d-m-Y') : '',
            'endDate'             => !empty($this->end_date) ? Carbon::parse($this->end_date)->format('d-m-Y') : '',
            'topic'               => new TopicResource($this->topic),
            'image'               => getImage($this->image, ['w800', 'w400']),
            'cta'                 => resolve_link($this->cta),
        ];

        return $out;
    }
}
