<?php
/**
 * ITSWEBER CMS – Blog Preview Section
 *
 * Shows a preview of recent blog posts 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 BlogPreviewSection extends AbstractSection
{
    public static function typeKey(): string    { return 'blog_preview'; }
    public static function label(): string      { return 'Blog-Vorschau'; }
    public static function category(): string   { return 'preview'; }
    public static function description(): string { return 'Vorschau der neuesten Blog-Beiträge mit Link zum Blog'; }

    public static function iconSvg(): string
    {
        return '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">'
             . '<path d="M4 4h16a2 2 0 012 2v12a2 2 0 01-2 2H4a2 2 0 01-2-2V6a2 2 0 012-2z"/>'
             . '<line x1="6" y1="8" x2="18" y2="8"/>'
             . '<line x1="6" y1="12" x2="14" y2="12"/>'
             . '<line x1="6" y1="16" x2="10" y2="16"/>'
             . '</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_date'          => $request->input('show_date') ? 1 : 0,
            'show_category'      => $request->input('show_category') ? 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'              => 'Aktuelles',
            'subtitle'           => 'Neuigkeiten aus unserem Blog',
            'count'              => 3,
            'cta_text'           => '',
            'cta_url'            => '',
            'show_date'          => 0,
            'show_category'      => 0,
            'color_scheme'       => '',
            'text_align'         => '',
            'section_text_color' => '',
        ];
    }
}
