
// OPEN TASKS
function fetchOpenTasks() {
    var projectId = $('#projectId').text().trim();
    $('#epicLoader').removeClass('hidden');

    $.ajax({
        url: '/open_tasks_for_project/' + projectId + '/',
        method: 'GET',
        success: function (data) {
            $('#epicLoader').addClass('hidden');
            $('#epicRelatedTasksContainer').html(data);
        },
        error: function (error) {
            console.error('Error fetching open tasks:', error);
            $('#epicLoader').addClass('hidden');
        }
    });
}

$(document).ready(function () {
    fetchOpenTasks();
});

$('.openTasks').on('click', function () {
    $('.epicTitle').removeClass('selectedEpic');
    $('.openTasks').removeClass('selectedEpic');

    $('#epicRelatedTasksContainer').empty(); 
    console.log('empyt1')

    $(this).addClass('selectedEpic');

    fetchOpenTasks();
});



// TASKS BY EPIC
$('.epicTitle').on('click', function () {
    $('.epicTitle').removeClass('selectedEpic');
    $('.openTasks').removeClass('selectedEpic');

    var epicId = $(this).data('epic-id');

    $('#epicRelatedTasksContainer').empty(); 
    console.log('empyt2')

    $(this).addClass('selectedEpic');

    $('#epicLoader').removeClass('hidden');

    $.ajax({
        url: '/get_tasks/' + epicId + '/',
        method: 'GET',
        success: function (data) {
            $('#epicLoader').addClass('hidden');
            $('#epicRelatedTasksContainer').html(data);
        },
        error: function (error) {
            console.error('Error fetching tasks:', error);
            $('#epicLoader').addClass('hidden');
        }
    });
});
