<?php

namespace App\Domain\Website\Blocks;

use App\Domain\Website\Enums\BlockCategory;

/**
 * Base for blocks that render live ERP records (branches, programs, trainers…).
 *
 * These are what make a site "data-driven": the client edits a branch once in the
 * ERP and the website follows, instead of maintaining a second copy of the truth.
 */
abstract class DataBlockType extends BlockType
{
    public function category(): BlockCategory
    {
        return BlockCategory::Data;
    }

    /** Extra fields specific to the concrete data block. */
    protected function extraFields(): array
    {
        return [];
    }

    /** Filter controls offered for this source, e.g. by branch or activity. */
    protected function filterFields(): array
    {
        return [];
    }

    public function fields(): array
    {
        return array_merge([
            BlockField::text('title', 'العنوان'),
            BlockField::textarea('subtitle', 'العنوان الفرعي'),
        ], $this->filterFields(), [
            BlockField::number('limit', 'عدد العناصر')->default(0)
                ->help('صفر = عرض الكل'),
            BlockField::select('columns', 'عدد الأعمدة', [
                '1' => '1', '2' => '2', '3' => '3', '4' => '4',
            ])->default('3'),
            BlockField::toggle('show_search', 'إظهار مربع بحث'),
            BlockField::toggle('show_image', 'إظهار الصور')->default(true),
            BlockField::toggle('link_items', 'ربط العناصر بصفحاتها')->default(true),
            BlockField::text('empty_message', 'رسالة عند عدم وجود بيانات'),
            BlockField::repeater('buttons', 'أزرار أسفل القسم', [
                BlockField::text('label', 'النص'),
                BlockField::link('url', 'الرابط'),
            ])->max(2),
        ], $this->extraFields());
    }
}
