<?php
/// file: app/Helpers/Seo.php

declare(strict_types=1);

namespace App\Helpers;

use App\Core\Config;
use App\Models\SeoMeta;

final class Seo
{
    /** @return array<string, string> */
    public static function page(string $pageKey, array $overrides = []): array
    {
        $row = SeoMeta::forPage($pageKey);
        $appName = (string) Config::get('app.name', 'SANEKSA');
        $base = [
            'title' => $appName,
            'description' => '',
            'og_title' => $appName,
            'og_description' => '',
            'og_image' => '',
            'robots' => 'index,follow',
        ];
        if (is_array($row)) {
            $base['title'] = (string) ($row['title'] ?: $base['title']);
            $base['description'] = (string) ($row['description'] ?? '');
            $base['og_title'] = (string) ($row['og_title'] ?: $base['og_title']);
            $base['og_description'] = (string) ($row['og_description'] ?? $base['description']);
            $base['og_image'] = (string) ($row['og_image'] ?? '');
            $base['robots'] = (string) ($row['robots'] ?? 'index,follow');
        }
        foreach ($overrides as $k => $v) {
            if (is_string($v) && $v !== '') {
                $base[$k] = $v;
            }
        }
        return $base;
    }
}
