<?php

namespace App\Filament\Resources\TextbookResource\Actions;

use App\Services\TextbookApiService;
use Filament\Actions\Action;
use Filament\Notifications\Notification;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redirect;

class DeleteTextbookAction extends Action
{
    public static function getDefaultName(): ?string
    {
        return 'delete_textbook';
    }

    protected function setUp(): void
    {
        parent::setUp();

        $this
            ->label('删除')
            ->color('danger')
            ->icon('heroicon-o-trash')
            ->requiresConfirmation()
            ->modalHeading('删除教材')
            ->modalDescription('确定要删除这个教材吗？此操作无法撤销。')
            ->url(function (Model $record) {
                // 通过URL重定向传递ID，完全绕过Action的$record传递问题
                return route('filament.admin.resources.textbooks.delete', $record->id);
            });
    }
}
