<?php
/**
 * ITSWEBER CMS – Gallery Preview Section
 *
 * Shows a preview of gallery images 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 GalleryPreviewSection extends AbstractSection
{
    public static function typeKey(): string    { return 'gallery_preview'; }
    public static function label(): string      { return 'Galerie-Vorschau'; }
    public static function category(): string   { return 'preview'; }
    public static function description(): string { return 'Vorschau der neuesten Galerie-Bilder mit Link zur Galerie'; }

    public static function iconSvg(): string
    {
        return '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">'
             . '<rect x="2" y="3" width="20" height="18" rx="2"/>'
             . '<circle cx="8" cy="9" r="2"/>'
             . '<path d="M2 17l5-5 3 3 4-4 8 8"/>'
             . '</svg>';
    }

    public function buildData(Request $request): array
    {
        $data = [
            'title'              => trim($request->input('title', '')),
            'subtitle'           => trim($request->input('subtitle', '')),
            'count'              => max(1, min(24, (int) $request->input('count', 6))),
            'cta_text'           => trim($request->input('cta_text', '')),
            'cta_url'            => trim($request->input('cta_url', '')),
            'show_image_count'   => $request->input('show_image_count') ? 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'              => 'Galerie',
            'subtitle'           => 'Einblicke in unsere Arbeit',
            'count'              => 6,
            'cta_text'           => '',
            'cta_url'            => '',
            'show_image_count'   => 0,
            'color_scheme'       => '',
            'text_align'         => '',
            'section_text_color' => '',
        ];
    }
}
