<?php
/**
 * ITSWEBER CMS – Events Preview Section
 *
 * Shows a preview of upcoming events with configurable count and CTA.
 *
 * @author    Benny Weber (ITSWEBER)
 * @copyright © ITSWEBER – www.itsweber.de
 * @contact   kontakt@itsweber.de
 */

namespace App\Sections\Core;

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

class EventsPreviewSection extends AbstractSection
{
    public static function typeKey(): string    { return 'events_preview'; }
    public static function label(): string      { return 'Events-Vorschau'; }
    public static function category(): string   { return 'preview'; }
    public static function description(): string { return 'Vorschau kommender Events mit Link zur Events-Seite'; }

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

    public function buildData(Request $request): array
    {
        $data = [
            'title'              => trim($request->input('title', '')),
            'subtitle'           => trim($request->input('subtitle', '')),
            'count'              => max(1, min(12, (int) $request->input('count', 3))),
            'cta_text'           => trim($request->input('cta_text', '')),
            'cta_url'            => trim($request->input('cta_url', '')),
            'show_image'         => $request->input('show_image') ? 1 : 0,
            'color_scheme'       => self::sanitizeToken(trim($request->input('color_scheme', '')), self::allowedColorScheme()),
            'text_align'         => self::sanitizeToken(trim($request->input('text_align', '')),   self::allowedSectionAlign()),
            'section_text_color' => self::sanitizeToken(trim($request->input('section_text_color', '')), self::allowedSectionTextColor()),
        ];

        return $this->mergeThemeExtras($data, $request);
    }

    public function defaultData(): array
    {
        return [
            'title' => '', 'subtitle' => '', 'count' => 3,
            'cta_text' => '', 'cta_url' => '', 'show_image' => 0,
            'color_scheme' => '', 'text_align' => '', 'section_text_color' => '',
        ];
    }
}
