<?php

namespace App\View\Components;

use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\File;
use Illuminate\View\Component;

/**
 * Componente para añadir las traducciones al frontend
 */
class Translations extends Component
{
    /**
     * Create a new component instance.
     */
    public function __construct()
    {
        //
    }

    /**
     * Get the view / contents that represent the component.
     */
    public function render(): View|Closure|string
    {
        $translations = [];
        $locale = app()->getLocale();

        $translationsFilePath = resource_path("lang/$locale/translations.php");
        if (File::exists($translationsFilePath)) {
            $translations = File::getRequire($translationsFilePath);
        }
        return view('components.translations', ['translations' => $translations]);
    }
}
