<?php
/**
 * ITSWEBER CMS – Site Notice Section
 *
 * Global announcement banner. Single-instance only.
 * In 3.2.0 this is managed via its own Settings page,
 * not as a regular page builder section.
 * Migriert aus plugins/site-notice.
 *
 * @author    Benny Weber (ITSWEBER)
 * @copyright © ITSWEBER – www.itsweber.de
 * @contact   kontakt@itsweber.de
 */

namespace App\Sections\Extended;

use App\Sections\AbstractSection;
use App\Core\Request;

class SiteNoticeSection extends AbstractSection
{
    public static function typeKey(): string    { return 'site_notice'; }
    public static function label(): string      { return 'Ankündigungsleiste'; }
    public static function category(): string   { return 'global'; }
    public static function allowMultiple(): bool { return false; }
    public static function description(): string { return 'Globale Hinweisleiste (Info, Warnung, Erfolg, Fehler)'; }

    public static function iconSvg(): string
    {
        return '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">'
             . '<rect x="2" y="4" width="20" height="6" rx="1.5"/>'
             . '<line x1="6" y1="7" x2="14" y2="7"/>'
             . '<circle cx="18" cy="7" r="1" fill="currentColor"/>'
             . '</svg>';
    }

    public function buildData(Request $request): array
    {
        $allowedVariant = ['info', 'success', 'warning', 'danger'];

        $linkUrl = trim((string) ($request->input('link_url', '') ?? ''));
        if ($linkUrl !== '' && !preg_match('/^(https?:\/\/|\/)/i', $linkUrl)) {
            $linkUrl = '';
        }

        $variant = (string) ($request->input('variant', 'info') ?? 'info');
        if (!in_array($variant, $allowedVariant, true)) {
            $variant = 'info';
        }

        $data = [
            'text'       => trim((string) ($request->input('text', '') ?? '')),
            'variant'    => $variant,
            'link_url'   => $linkUrl,
            'link_label' => trim((string) ($request->input('link_label', '') ?? '')),
            'active'     => $request->input('active') ? 1 : 0,
        ];

        return $data;
    }

    public function defaultData(): array
    {
        return [
            'text' => '', 'variant' => 'info',
            'link_url' => '', 'link_label' => '',
            'active' => 0,
        ];
    }

    public function styles(): array
    {
        return ['/assets/css/sections/site-notice.css'];
    }
}
