<?php

namespace App\PageBuilder\Components\Marketing;

use App\PageBuilder\PageComponent;
use Illuminate\Support\Str;

class FaqAccordionComponent extends PageComponent
{
    public function key(): string { return 'faq_accordion'; }
    public function category(): string { return 'marketing'; }
    public function label(): string { return 'FAQ Accordion'; }
    public function icon(): string { return 'fas fa-question-circle'; }

    public function schema(): array
    {
        return [
            'title' => ['type' => 'text'],
            'items' => [
                'type' => 'repeater',
                'item_schema' => [
                    'question' => ['type' => 'text', 'required' => true],
                    'answer' => ['type' => 'textarea', 'required' => true],
                ],
                'min' => 1, 'max' => 30,
            ],
            'options' => [
                'color' => ['type' => 'color_token', 'default' => 'transparent'],
                'padding' => ['type' => 'padding_token', 'default' => 'lg'],
                'multi_open' => ['type' => 'boolean', 'label' => 'Birden fazla açık olabilsin', 'default' => false],
                'first_open' => ['type' => 'boolean', 'label' => 'İlk soru açık başlasın', 'default' => true],
                'style' => ['type' => 'select', 'label' => 'Stil', 'options' => ['bordered', 'plain', 'card'], 'default' => 'bordered'],
            ],
        ];
    }

    public function defaults(): array
    {
        return [
            'title' => 'Sıkça Sorulan Sorular',
            'items' => [
                ['question' => 'Soru 1?', 'answer' => 'Cevap 1'],
            ],
            'options' => [
                'color' => 'transparent', 'padding' => 'lg',
                'multi_open' => false, 'first_open' => true, 'style' => 'bordered',
            ],
        ];
    }

    public function render(array $data, array $options): string
    {
        $accordionId = 'faq-' . Str::random(8);
        return view('page-builder.components.faq_accordion', compact('data', 'options', 'accordionId'))->render();
    }
}
