<?php

namespace App\Filament\Resources\MarkdownImportResource\Pages;

use App\Filament\Resources\MarkdownImportResource;
use App\Models\MarkdownImport;
use Filament\Actions\CreateAction;
use Filament\Resources\Pages\ListRecords;

class ListMarkdownImports extends ListRecords
{
    protected static string $resource = MarkdownImportResource::class;
    protected string $view = 'filament.resources.markdown-import-resource.pages.list-markdown-imports';

    protected function getHeaderActions(): array
    {
        return [
            CreateAction::make()
                ->label('导入 Markdown')
                ->icon('heroicon-o-arrow-up-tray'),
        ];
    }

    public function mount(): void
    {
        parent::mount();

        // 检查是否有处理中的记录
        $hasProcessing = MarkdownImport::where('status', 'processing')->exists();

        // 如果有待处理的记录，设置自动刷新
        if ($hasProcessing) {
            $this->dispatch('$refresh');
        }
    }
}
