<?php

declare(strict_types=1);

namespace PpPhp\Core\Designer\Descriptors;

/**
 * ButtonDescriptor
 *
 * Descriptor for button-like Designer components.
 *
 * This is the first descriptor-driven Properties Panel implementation.
 * It is intentionally focused on the common Button component so we can
 * validate the Descriptor Engine safely before expanding to other components.
 *
 * @package PPphp
 * @subpackage Designer\Descriptors
 * @since 0.7.1
 */
final class ButtonDescriptor
{
    public static function make(): ComponentDescriptor
    {
        return new ComponentDescriptor(
            type: 'button',
            name: 'Button',
            description: 'Clickable action button used for forms, navigation, toolbars and custom actions.',
            icon: 'cursor',
            groups: [
                [
                    'id' => 'identity',
                    'label' => 'Identity',
                    'icon' => 'fingerprint',
                    'fields' => [
                        [
                            'key' => 'id',
                            'label' => 'Component ID',
                            'type' => 'text',
                            'readonly' => false,
                            'help' => 'Unique Designer ID. Use letters, numbers and underscores.',
                        ],
                        [
                            'key' => 'type',
                            'label' => 'Type',
                            'type' => 'text',
                            'readonly' => true,
                            'help' => 'Component type used by the Designer renderer.',
                        ],
                    ],
                ],
                [
                    'id' => 'display',
                    'label' => 'Display',
                    'icon' => 'type',
                    'fields' => [
                        [
                            'key' => 'label',
                            'label' => 'Text / Label',
                            'type' => 'text',
                            'default' => 'Button',
                            'help' => 'Visible button text.',
                        ],
                        [
                            'key' => 'icon',
                            'label' => 'Icon',
                            'type' => 'text',
                            'default' => '',
                            'help' => 'Bootstrap icon name without the bi- prefix.',
                        ],
                        [
                            'key' => 'variant',
                            'label' => 'Variant',
                            'type' => 'select',
                            'default' => 'primary',
                            'options' => [
                                'primary' => 'Primary',
                                'secondary' => 'Secondary',
                                'success' => 'Success',
                                'danger' => 'Danger',
                                'warning' => 'Warning',
                                'info' => 'Info',
                                'light' => 'Light',
                                'dark' => 'Dark',
                                'link' => 'Link',
                            ],
                            'help' => 'Visual button style.',
                        ],
                        [
                            'key' => 'size',
                            'label' => 'Size',
                            'type' => 'select',
                            'default' => 'md',
                            'options' => [
                                'sm' => 'Small',
                                'md' => 'Medium',
                                'lg' => 'Large',
                            ],
                            'help' => 'Button size.',
                        ],
                    ],
                ],
                [
                    'id' => 'behavior',
                    'label' => 'Behavior',
                    'icon' => 'bolt',
                    'fields' => [
                        [
                            'key' => 'action',
                            'label' => 'Action',
                            'type' => 'select',
                            'default' => '',
                            'options' => [
                                '' => 'None',
                                'submit' => 'Submit Form',
                                'reset' => 'Reset Form',
                                'navigate' => 'Navigate',
                                'modal' => 'Open Modal',
                                'custom' => 'Custom Action',
                            ],
                            'help' => 'Action executed when the button is clicked.',
                        ],
                        [
                            'key' => 'href',
                            'label' => 'URL / Href',
                            'type' => 'text',
                            'default' => '',
                            'help' => 'Target URL when action is Navigate.',
                        ],
                        [
                            'key' => 'target',
                            'label' => 'Target',
                            'type' => 'select',
                            'default' => '_self',
                            'options' => [
                                '_self' => 'Same Window',
                                '_blank' => 'New Window',
                            ],
                            'help' => 'Navigation target.',
                        ],
                    ],
                ],
                [
                    'id' => 'state',
                    'label' => 'State',
                    'icon' => 'toggle-on',
                    'fields' => [
                        [
                            'key' => 'visible',
                            'label' => 'Visible',
                            'type' => 'checkbox',
                            'default' => true,
                            'help' => 'Show or hide this component.',
                        ],
                        [
                            'key' => 'disabled',
                            'label' => 'Disabled',
                            'type' => 'checkbox',
                            'default' => false,
                            'help' => 'Disable click interaction.',
                        ],
                    ],
                ],
            ]
        );
    }
}
