<?php

namespace App\Http\Controllers\Web;

use App\Http\Controllers\Controller;
use App\Models\LandingScreenshot;
use App\Models\Setting;
use App\Services\Admin\AppBrandingService;
use Illuminate\View\View;

/**
 * صفحات الموقع العامة (usemadar.org) — Landing + قانوني.
 */
final class SiteController extends Controller
{
    public function landing(): View
    {
        return view('site.landing', array_merge($this->siteContext(), ['withChrome' => false]));
    }

    public function privacy(): View
    {
        return view('site.privacy', $this->siteContext());
    }

    public function terms(): View
    {
        return view('site.terms', $this->siteContext());
    }

    /**
     * @return array{platformName: string, appUrl: string, isBeta: bool, updatedAt: string}
     */
    private function siteContext(): array
    {
        $settings = Setting::current();

        return [
            'platformName' => $settings->platform_name ?: 'MadarX',
            'appUrl' => rtrim(config('app.url'), '/'),
            'isBeta' => (bool) config('madar.public_beta'),
            'updatedAt' => now()->translatedFormat('j F Y'),
            'logoUrl' => AppBrandingService::logoUrl($settings),
            'iconUrl' => AppBrandingService::iconUrl($settings),
            'googlePlayUrl' => $settings->google_play_url,
            'appleAppStoreUrl' => $settings->apple_app_store_url,
            'screenshots' => LandingScreenshot::forLanding(),
        ];
    }
}
