<?php

declare(strict_types=1);

namespace App\Filament\Components\Form;

use Filament\Actions\Action;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Components\Utilities\Get;
use Filament\Schemas\Components\Utilities\Set;

class SlugTextInput extends TextInput
{
    public static function create(): static
    {
        return parent::make('slug')
            ->label('نامک')
            ->suffixAction(
                Action::make('generateSlug')
                    ->icon('heroicon-m-arrow-path')
                    ->action(function (Get $get, Set $set) {
                        $title = $get('title');
                        $name = $get('name');

                        $source = $title ?? $name;

                        $set('slug', str($source)->slug());
                    })
            )
            ->columnSpan(6);
    }
}
