<?php

namespace App\Http\Controllers;

use Illuminate\Http\JsonResponse;

class SettingsController extends Controller
{
    // GET /api/settings/global  — branding/meta values
    public function global(): JsonResponse
    {
        return response()->json([
            'meta_title'        => config('app.name', 'Pub & Go'),
            'store_panel_color' => env('PANEL_COLOR', '#FF683A'),
            'favicon'           => asset('assets/images/favicon.ico'),
        ]);
    }

    // GET /api/settings/languages  — available UI locales
    public function languages(): JsonResponse
    {
        $langDir = resource_path('lang');
        $labels  = ['de' => 'Deutsch', 'en' => 'English', 'fr' => 'Français', 'pl' => 'Polski'];

        $slugs = array_values(array_filter(
            scandir($langDir),
            fn ($d) => $d[0] !== '.' && is_dir("$langDir/$d")
        ));

        $langs = array_map(fn ($slug) => [
            'slug'     => $slug,
            'title'    => $labels[$slug] ?? strtoupper($slug),
            'isActive' => true,
            'is_rtl'   => in_array($slug, ['ar', 'fa', 'he']),
        ], $slugs);

        return response()->json(['list' => $langs]);
    }
}
