<?php 
use Filament\Forms;
use Filament\Pages\Page;
use Filament\Actions\Action;
use Maatwebsite\Excel\Facades\Excel;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
use UnitEnum;

class ImportPriceTable extends Page
{
    use Forms\Concerns\InteractsWithForms;

	protected static ?string $navigationLabel = 'Import Pricing';

    // 👇 THIS IS THE IMPORTANT PART
	    protected static ?int $navigationSort = 1;

    /**
     * Holds form state (REQUIRED for Filament Pages)
     */
    public array $data = [];


	public static function getNavigationIcon(): ?string
	{
		return 'heroicon-o-arrow-up-tray';
	}

    // 👇 THIS IS THE IMPORTANT PART


    public $category_id;
    public $price_group;
    public $system_type;
    public $file;

    protected function getFormSchema(): array
    {
        return [
            Forms\Components\Select::make('category_id')
                ->options(\App\Models\Category::formattedList())
                ->required(),

            Forms\Components\TextInput::make('price_group')->required(),
            Forms\Components\TextInput::make('system_type'),

            Forms\Components\FileUpload::make('file')->required(),
        ];
    }

    protected function getActions(): array
    {
        return [
            Action::make('submit')
                ->label('Import Prices')

                /*
                ✅ THIS WORKS HERE
                */               
				->requiresConfirmation()
                ->modalHeading('Overwrite Price Table?')
                ->modalDescription('This file will overwrite existing prices. Continue?')
                ->modalSubmitActionLabel('Yes, Import')


                ->action(function () {

                    (new \App\Http\Controllers\PriceTableUploadController())
                        ->processUpload(
                            $this->category_id,
                            $this->price_group,
                            $this->file,
                            $this->system_type
                        );
                }),
        ];
    }
	public function sheets(): array
{
    return [
        1 => $this, // 0 = first tab, 1 = SECOND TAB (pricing)
    ];
}
}
