<?php

declare(strict_types=1);

namespace Builder\Core\Foundation\Commands;

use Illuminate\Support\Str;

final class MakeWidgetCommand extends MakeBuilderFileCommand
{
    protected $signature = 'builder:make:widget
        {name : The class name of the widget (e.g. PostStatsWidget)}
        {--force : Overwrite the widget if it already exists}';

    protected $description = 'Create a new Builder widget class';

    protected function stubName(): string
    {
        return 'widget';
    }

    protected function outputSubdirectory(): string
    {
        return 'Widgets';
    }

    protected function packageStubsPath(): string
    {
        return __DIR__.'/../../../stubs';
    }

    /** @return array<string, string> */
    protected function buildReplacements(string $className): array
    {
        $base = Str::replaceLast('Widget', '', $className);

        return [
            'namespace' => 'App\\Builder\\Widgets',
            'class' => $className,
            'key' => Str::kebab($base),
            'label' => Str::headline($base),
            'component' => $className,
        ];
    }
}
