<?php
/**
 * ITSWEBER CMS – Process Steps Section
 *
 * Numbered process/workflow steps.
 * Migriert aus plugins/process-steps-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 ProcessStepsSection extends AbstractSection
{
    public static function typeKey(): string    { return 'process_steps'; }
    public static function label(): string      { return 'Prozess-Schritte'; }
    public static function category(): string   { return 'content'; }
    public static function description(): string { return 'Nummerierte Prozess- oder Workflow-Schritte'; }

    public static function iconSvg(): string
    {
        return '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">'
             . '<circle cx="6" cy="6" r="3"/>'
             . '<circle cx="6" cy="18" r="3"/>'
             . '<line x1="6" y1="9" x2="6" y2="15"/>'
             . '<line x1="11" y1="6" x2="20" y2="6"/>'
             . '<line x1="11" y1="18" x2="20" y2="18"/>'
             . '</svg>';
    }

    public function buildData(Request $request): array
    {
        $stepTitles = $request->input('step_title', []);
        $stepTexts  = $request->input('step_text', []);

        $steps = [];
        if (is_array($stepTitles)) {
            foreach ($stepTitles as $i => $stepTitle) {
                $t = trim((string) $stepTitle);
                if ($t !== '') {
                    $steps[] = [
                        'title' => $t,
                        'text'  => trim((string) ($stepTexts[$i] ?? '')),
                    ];
                }
            }
        }
        $steps = array_slice($steps, 0, 8);

        $data = [
            'title'              => trim((string) ($request->input('title', '') ?? '')),
            'subtitle'           => trim((string) ($request->input('subtitle', '') ?? '')),
            'color_scheme'       => self::sanitizeToken((string) ($request->input('color_scheme', '') ?? ''), self::allowedColorScheme()),
            'section_text_color' => self::sanitizeToken((string) ($request->input('section_text_color', '') ?? ''), self::allowedSectionTextColor()),
            'columns'            => self::sanitizeToken((string) ($request->input('columns', '') ?? ''), self::allowedColumns()),
            'steps'              => $steps,
        ];

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

    public function defaultData(): array
    {
        return [
            'title' => 'So arbeiten wir',
            'subtitle' => 'In wenigen Schritten zum Erfolg',
            'color_scheme' => '', 'section_text_color' => '',
            'columns' => '',
            'steps' => [
                ['title' => 'Beratung', 'text' => 'Gemeinsam analysieren wir Ihre Anforderungen und Ziele.'],
                ['title' => 'Konzept', 'text' => 'Wir erstellen einen massgeschneiderten Plan fuer Ihr Projekt.'],
                ['title' => 'Umsetzung', 'text' => 'Professionelle Realisierung mit regelmaessigen Updates.'],
                ['title' => 'Ergebnis', 'text' => 'Ihr fertiges Projekt wird uebergeben und Sie werden eingewiesen.'],
            ],
        ];
    }

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