<?php

namespace ViartasThemes\Protera\ThemeBuilder;

use Illuminate\Contracts\View\View;
use ViartasCore\Themes\ThemeBuilder\BaseSection;
use ViartasCore\Themes\ThemeBuilder\SectionContext;

/**
 * Raw HTML insertion block (`protera.custom_html`).
 *
 * Theme-owned builder section. Stores a translatable HTML payload and echoes it
 * VERBATIM ({!! !!}) — deliberately NOT run through HTML Purifier.
 *
 * Security rationale: the only people who can reach the builder are super-admins
 * holding the `theme-builder.edit` permission (enforced by the `theme-builder`
 * middleware). The HTML is therefore trusted operator input, not user-generated
 * content, so escaping/purifying it would defeat the section's whole purpose
 * (embedding arbitrary markup/embeds). Do NOT expose this section to lower
 * privilege levels.
 */
class CustomHtmlSection extends BaseSection
{
    /**
     * Registry key — '{module}.{section}'.
     */
    public function key(): string
    {
        return 'protera.custom_html';
    }

    /**
     * Library grouping.
     */
    public function module(): string
    {
        return 'protera';
    }

    /**
     * Translatable display label.
     */
    public function label(): string
    {
        return (string) __('protera::sections.custom_html.label');
    }

    /**
     * Bootstrap icon class.
     */
    public function icon(): string
    {
        return 'bi-code-slash';
    }

    /**
     * A single translatable HTML payload, stored as-is.
     *
     * NOTE: the foundation's inline edit form (section-form.blade.php) renders
     * every translatable field as a one-line <input>, so the `rows` hint below
     * is advisory until the form gains a translatable-textarea widget. The data
     * model itself is unaffected — the value round-trips through
     * `settings[html][{locale}]` either way.
     *
     * @return array<string, array<string, mixed>>
     */
    public function settingsSchema(): array
    {
        return [
            'html' => [
                'type' => 'textarea',
                'translatable' => true,
                'rows' => 10,
                'default' => '',
            ],
        ];
    }

    /**
     * Visual-only — no data source.
     *
     * @return array<string, array<string, mixed>>
     */
    public function sources(): array
    {
        return [];
    }

    /**
     * Render the raw HTML for the active locale.
     */
    public function render(SectionContext $ctx): View
    {
        return view('theme::sections.custom-html', [
            'html' => $ctx->setting('html', ''),
        ]);
    }
}
