<?php

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\App;

class StatusResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        $lang = $request->header('Accept-Language') ?? 'ru';

        // Set the application locale to the retrieved language
        App::setLocale($lang);

        return [
            'slug' => $this->slug,
            'translation' => trans('admin.statuses.' . $this->slug),
            'font_color' => $this->font_color,
            'bg_color' => $this->bg_color,
        ];
    }
}
