<?php

namespace App\Filament\Resources\Manage\Journalists\Pages;

use App\Enums\RoleEnum;
use App\Enums\VerificationStatus;
use App\Filament\Resources\Manage\Journalists\Actions\CreateJournalistAction;
use App\Filament\Resources\Manage\Journalists\JournalistResource;
use Filament\Resources\Pages\ManageRecords;

class ManageJournalists extends ManageRecords
{
    protected static string $resource = JournalistResource::class;

    protected static ?string $title = 'Jurnalis';

    protected function getHeaderActions(): array
    {
        if (auth()->user()->hasRole(RoleEnum::PERUSAHAAN->value) && ! auth()->user()->company?->partnerMedia) {
            return [];
        }

        return [
            CreateJournalistAction::make()
                ->visible(fn () => ! (in_array(auth()->user()->company?->verificationRequest?->status, [VerificationStatus::PENDING, VerificationStatus::REJECTED]) || auth()->user()->company?->verificationRequest()->pending()->exists())),
        ];
    }
}
