<?php
/**
 * ITSWEBER CMS – HTML Freiform Section
 *
 * Free-form HTML content section with WYSIWYG editor.
 * Migriert aus plugins/html-section.
 *
 * @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 HtmlSection extends AbstractSection
{
    public static function typeKey(): string    { return 'html_section'; }
    public static function label(): string      { return 'HTML Freiform'; }
    public static function category(): string   { return 'media'; }
    public static function description(): string { return 'Freier HTML-Inhalt mit WYSIWYG-Editor'; }

    public static function iconSvg(): string
    {
        return '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">'
             . '<polyline points="10 18 4 12 10 6"/>'
             . '<polyline points="14 6 20 12 14 18"/>'
             . '</svg>';
    }

    public function buildData(Request $request): array
    {
        $allowedTextAlign = ['', 'left', 'center', 'right'];

        $data = [
            'title'              => trim((string) ($request->input('title', '') ?? '')),
            'subtitle'           => trim((string) ($request->input('subtitle', '') ?? '')),
            'content_html'       => (string) ($request->input('content_html', '') ?? ''),
            'color_scheme'       => self::sanitizeToken((string) ($request->input('color_scheme', '') ?? ''), self::allowedColorScheme()),
            'text_align'         => self::sanitizeToken((string) ($request->input('text_align', '') ?? ''), $allowedTextAlign),
            'max_width'          => self::sanitizeToken((string) ($request->input('max_width', '') ?? ''), self::allowedMaxWidth()),
            'section_text_color' => self::sanitizeToken((string) ($request->input('section_text_color', '') ?? ''), self::allowedSectionTextColor()),
        ];

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

    public function defaultData(): array
    {
        return [
            'title' => 'Eigener Inhalt',
            'subtitle' => '',
            'content_html' => '<div style="padding:2rem;background:#f8fafc;border:2px dashed #cbd5e1;border-radius:8px;text-align:center;color:#64748b;"><p><strong>HTML-Section</strong></p><p>Fuegen Sie hier Ihren eigenen HTML-Code ein.</p></div>',
            'color_scheme' => '', 'text_align' => '', 'max_width' => '',
            'section_text_color' => '',
        ];
    }

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