<?php

namespace App\Livewire\Projects\Traits;

use App\Models\Feature;
use App\Models\Issue;
use Livewire\Attributes\On;

trait MapIssues
{
    public $openIssuesCount = 0;

    #[On('issue-created')]
    public function handleIssueCreated()
    {
        $this->openIssuesCount = Issue::where('project_id', $this->project->id)
            ->where('status', 'open')
            ->count();
    }

    #[On('issue-updated')]
    public function handleIssueUpdated()
    {
        $this->openIssuesCount = Issue::where('project_id', $this->project->id)
            ->where('status', 'open')
            ->count();
    }

    #[On('issue-deleted')]
    public function handleIssueDeleted()
    {
        $this->openIssuesCount = Issue::where('project_id', $this->project->id)
            ->where('status', 'open')
            ->count();
    }
}