<?php

namespace App\View\Components;

use App\Enums\Status;
use Illuminate\View\Component;
use Illuminate\View\View;

class Badge extends Component
{
    /**
     * @var array|string[]
     */
    public array $colorClasses;
    public Status $status;
    public int $id;


    public function __construct($status = null, $id = 0)
    {
        $this->id ??= $id ;
        $this->status = Status::tryFrom($status) ?? Status::Success;
        $this->colorClasses = match($this->status) {
            Status::Success => ['bg' => 'bg-green-100', 'text' => 'text-green-700'],
            Status::Failed => ['bg' => 'bg-red-100', 'text' => 'text-red-700'],
            Status::Pending => ['bg' => 'bg-gray-100', 'text' => 'text-gray-600'],
        };
    }

    /**
     * Get the view / contents that represents the component.
     */
    public function render(): View
    {
        return view('components.badge');
    }
}
