<?php
/**
 * ITSWEBER CMS – Hero Banner Section
 *
 * Full-width hero with background image/video, CTAs, portrait image.
 * Single-instance only (one hero per page).
 *
 * @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 HeroSection extends AbstractSection
{
    public static function typeKey(): string    { return 'hero'; }
    public static function label(): string      { return 'Hero Banner'; }
    public static function category(): string   { return 'header'; }
    public static function allowMultiple(): bool { return true; }
    public static function description(): string { return 'Vollbreiter Hero-Bereich mit Bild, Video und Call-to-Actions'; }

    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="14" rx="2"/>'
             . '<line x1="6" y1="8" x2="14" y2="8"/>'
             . '<line x1="6" y1="11" x2="11" y2="11"/>'
             . '<rect x="6" y="13" width="5" height="2" rx="1"/>'
             . '</svg>';
    }

    public function buildData(Request $request): array
    {
        $allowedTextColor       = ['', 'auto', 'white', 'black', 'red', 'green', 'blue', 'light', 'dark'];
        $allowedHeadingSize     = ['', 'sm', 'md', 'lg', 'xl'];
        $allowedHeadingWeight   = ['', 'normal', 'medium', 'bold', 'black'];
        $allowedBodySize        = ['', 'sm', 'md', 'lg'];
        $allowedLayoutMode      = ['', 'full', 'boxed', 'split'];
        $allowedTextAlign       = ['', 'left', 'right'];
        $allowedOverlayStrength = ['', 'light', 'medium', 'heavy'];
        $allowedHeroHeight      = ['', 'tall'];
        $allowedPortraitStyle   = ['', 'elevated', 'flat'];
        $allowedPortraitShape   = ['', 'circle', 'rounded', 'square'];
        $allowedCtaLayout       = ['', 'stacked'];
        $allowedVideoBgMode     = ['', 'autoplay', 'manual'];
        $allowedVideoBgFit      = ['', 'cover', 'contain'];
        $allowedVideoDisplay    = ['', 'background', 'inline'];
        $allowedVideoInlineSize = ['', 'sm', 'md', 'lg', 'full'];

        $data = [
            // Content fields
            'title'          => trim($request->input('title', '')),
            'eyebrow'        => trim($request->input('eyebrow', '')),
            'subtitle'       => trim($request->input('subtitle', '')),
            'image'          => trim($request->input('image', '')),
            'portrait_image' => trim($request->input('portrait_image', '')),
            'portrait_alt'   => trim($request->input('portrait_alt', '')),
            'cta_text'       => trim($request->input('cta_text', '')),
            'cta_url'        => trim($request->input('cta_url', '')),
            'cta2_text'      => trim($request->input('cta2_text', '')),
            'cta2_url'       => trim($request->input('cta2_url', '')),
            // Video background
            'video_url'         => trim($request->input('video_url', '')),
            'video_poster'      => trim($request->input('video_poster', '')),
            'video_bg_mode'     => self::sanitizeToken(trim($request->input('video_bg_mode', '')), $allowedVideoBgMode),
            'video_bg_fit'      => self::sanitizeToken(trim($request->input('video_bg_fit', '')), $allowedVideoBgFit),
            'video_display'     => self::sanitizeToken(trim($request->input('video_display', '')), $allowedVideoDisplay),
            'video_inline_size' => self::sanitizeToken(trim($request->input('video_inline_size', '')), $allowedVideoInlineSize),
            // Presentation tokens
            'text_color'       => self::sanitizeToken(trim($request->input('text_color', '')),       $allowedTextColor),
            'heading_size'     => self::sanitizeToken(trim($request->input('heading_size', '')),     $allowedHeadingSize),
            'heading_weight'   => self::sanitizeToken(trim($request->input('heading_weight', '')),   $allowedHeadingWeight),
            'body_size'        => self::sanitizeToken(trim($request->input('body_size', '')),        $allowedBodySize),
            'layout_mode'      => self::sanitizeToken(trim($request->input('layout_mode', '')),      $allowedLayoutMode),
            'text_align'       => self::sanitizeToken(trim($request->input('text_align', '')),       $allowedTextAlign),
            'overlay_strength' => self::sanitizeToken(trim($request->input('overlay_strength', '')), $allowedOverlayStrength),
            'hero_height'      => self::sanitizeToken(trim($request->input('hero_height', '')),      $allowedHeroHeight),
            'portrait_style'   => self::sanitizeToken(trim($request->input('portrait_style', '')),   $allowedPortraitStyle),
            'portrait_shape'   => self::sanitizeToken(trim($request->input('portrait_shape', '')),   $allowedPortraitShape),
            'cta_layout'       => self::sanitizeToken(trim($request->input('cta_layout', '')),       $allowedCtaLayout),
        ];

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

    public function defaultData(): array
    {
        return [
            'title' => '', 'eyebrow' => '', 'subtitle' => '',
            'image' => '', 'portrait_image' => '', 'portrait_alt' => '',
            'cta_text' => '', 'cta_url' => '', 'cta2_text' => '', 'cta2_url' => '',
            'video_url' => '', 'video_poster' => '',
            'video_bg_mode' => '', 'video_bg_fit' => '',
            'video_display' => '', 'video_inline_size' => '',
            'text_color' => '', 'heading_size' => '', 'heading_weight' => '',
            'body_size' => '', 'layout_mode' => '', 'text_align' => '',
            'overlay_strength' => '', 'hero_height' => '',
            'portrait_style' => '', 'portrait_shape' => '', 'cta_layout' => '',
        ];
    }
}
