window.initPlaylistInteractions = (playlistId) => {
    const addBtn = document.getElementById('addTrackBtn');
    if (addBtn) {
        addBtn.addEventListener('click', async () => {
            const trackId = document.getElementById('trackId').value;
            const trackTitle = document.getElementById('trackTitle').value;
            const artist = document.getElementById('artistName').value;
            const response = await fetch(`/api/tracks/add?playlistId=${playlistId}&trackId=${trackId}&trackTitle=${encodeURIComponent(trackTitle)}&artist=${encodeURIComponent(artist)}`, {
                method: 'POST'
            });
            if (response.ok) location.reload();
            else alert('Ошибка добавления трека');
        });
    }

    document.querySelectorAll('.deleteTrackBtn').forEach(btn => {
        btn.addEventListener('click', async () => {
            const trackId = btn.getAttribute('data-track-id');
            const response = await fetch(`/api/tracks/remove?playlistId=${playlistId}&trackId=${trackId}`, {
                method: 'DELETE'
            });
            if (response.ok) location.reload();
            else alert('Ошибка удаления трека');
        });
    });
};