<?php

declare(strict_types=1);

namespace Builder\Core\Extensions\Settings\Pages;

use Builder\Core\Foundation\Definition\Field;
use Builder\Core\Foundation\Definition\FieldBuilder;
use Builder\Core\Foundation\Definition\Section;
use Builder\Core\Foundation\Settings\BuilderSettings;

/**
 * Built-in general settings page with site name and admin email.
 */
final class GeneralSettings extends BuilderSettings
{
    public string $site_name = '';

    public ?string $admin_email = null;

    public static function group(): string
    {
        return 'general';
    }

    public function getLabel(): string
    {
        return (string) __('builder::builder.general_settings.label');
    }

    public function getIcon(): string
    {
        return 'Settings';
    }

    public function getPriority(): int
    {
        return 10;
    }

    public function fields(): FieldBuilder
    {
        return FieldBuilder::make()
            ->add(
                Section::make('general')
                    ->label(__('builder::builder.general_settings.label'))
                    ->priority(0)
                    ->fields([
                        Field::text('site_name')->label(__('builder::builder.general_settings.site_name')),
                        Field::email('admin_email')->label(__('builder::builder.general_settings.admin_email')),
                    ]),
            );
    }

    public function rules(): array
    {
        return [
            'site_name' => ['required', 'string', 'max:255'],
            'admin_email' => ['nullable', 'email', 'max:255'],
        ];
    }
}
