{{>adminHeader}}
<title>Update Album</title>

<style>
    .tab-pane {
        padding-top: 2px;
        /* Adjust as needed */
    }

    #imagePreviewAdd img {
        height: 60px !important;
    }

    #imagePreviewUpdate img {
        height: 60px !important;
    }

    #imagePreviewAdd img {
        height: 60px !important;
    }

    .nav-pills .nav-link.active,
    .nav-pills .show>.nav-link {
        color: #CBA255;
        background-color: white;
    }

    .custom-btn-danger {
        font-size: 18px;
        /* Increase font size */
        padding: 24px 24px;
    }
</style>
<link rel="stylesheet" href="/admin/css/summernote-bs4.min.css">


<body>
    <section class="content">
        <div class="container-fluid">
            <div class="row">
                <div class="col-md-12">
                    <div class="card card-primary card-outline mt-3" style="border-left: 2px solid black;">
                        <div class="card-header" style="color:white;">
                            <h4><b style="color: black;">Album</b></h4>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <div class="card">
                        <div class="card-header p-2">
                            <ul class="nav nav-pills">
                                <li class="nav-item"><a class="nav-link active" href="#Achievement"
                                        data-toggle="tab">Album
                                        Information</a></li>
                                <li class="nav-item"><a class="nav-link" href="#faculties" data-toggle="tab">Songs</a>
                                </li>
                                <li class="nav-item"><a class="nav-link" href="#Youtube" data-toggle="tab">YouTube
                                        Videos</a></li>
                            </ul>
                        </div>
                        <div class="card-body">
                            <div class="tab-content">
                                {{!-- album details --}}
                                <div class="tab-pane active" id="Achievement">
                                    <div class="row">
                                        <div class="col-md-12">
                                            <form method="POST" action="/admin/updatealbumdetails/{{allData._id}}"
                                                enctype="multipart/form-data">
                                                <div class="card">
                                                    <div class="card-body">
                                                        <div class="form-group">
                                                            <label for="summernote7" class="col-form-label">
                                                                <h5><b>Album Information</b></h5>
                                                            </label>
                                                            <textarea name="albumInfo" id="summernote7" rows="2"
                                                                class="form-control">{{allData.albumInfo}}</textarea>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="form-group d-flex justify-content-center">
                                                    <button class="btn btn-lg btn-primary" type="submit"
                                                        style="background-color: #121212; color: white; margin-right: 19px;">
                                                        Update
                                                    </button>
                                                </div>
                                            </form>
                                        </div>
                                    </div>
                                </div>

                                {{!-- songs --}}
                                <div class="tab-pane" id="faculties">
                                    <div class="card-body p-2">
                                        <div id="example1_wrapper">
                                            <div class="row">
                                                <div class="col-sm-12">
                                                    <ol class="float-sm-right">
                                                        <button href="" id="" data-bs-toggle="modal"
                                                            data-bs-target="#addFacultiesModal"
                                                            style="background-color: #121212; color: #CBA255; border:none; border-radius:5px; height: 40px; "><i
                                                                class="fa-solid fa-plus"></i> Add
                                                            Song</button>
                                                    </ol>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    {{!-- //table --}}
                                    <div class="col-sm-12 table-responsive">
                                        <table id="example2" class="table table-striped table-bordered"
                                            aria-describedby="example1_info">
                                            <thead>
                                                <tr>
                                                    <th class="sorting" tabindex="0" aria-controls="example1">S.No</th>
                                                    {{!-- <th class="sorting" tabindex="0" aria-controls="example1">
                                                        songId
                                                    </th> --}}
                                                    <th class="sorting" tabindex="0" aria-controls="example1">Song Name
                                                    </th>
                                                    <th class="sorting" tabindex="0" aria-controls="example1">Artists
                                                    </th>
                                                    <th class="sorting" tabindex="0" aria-controls="example1">Action
                                                    </th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                {{#each allData.songs}}
                                                <tr>
                                                    <td>{{inc @index}}</td>
                                                    {{!-- <td>{{this._id}}</td> --}}
                                                    <td>{{this.songName}}</td>
                                                    <td>{{this.songArtists}}</td>
                                                    <td>
                                                        <div class="d-flex align-items-center">
                                                            <a href="/admin/icon/{{this._id}}"
                                                                class="btn btn-md btn-secondary">
                                                                <i class="fas fa-eye"></i>
                                                            </a>
                                                            <a href="javascript:void(0);" data-bs-toggle="modal"
                                                                data-bs-target="#updateFacultyModal"
                                                                class="btn btn-md btn-info m-1" data-id="{{this._id}}"
                                                                data-song-artists="{{this.songArtists}}"
                                                                data-song-name="{{this.songName}}">
                                                                <i class="fa-solid fa-edit"></i>
                                                            </a>
                                                            <a href="javascript:void(0);" data-bs-toggle="modal"
                                                                data-id="{{this._id}}" data-posterid="{{allData._id}}"
                                                                data-bs-target="#deleteModal"
                                                                class="btn btn-md btn-danger m-1">
                                                                <i class="fa-solid fa-trash fa-md"></i>
                                                            </a>
                                                        </div>
                                                    </td>
                                                </tr>
                                                {{/each}}
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                                {{!-- youtube Videos --}}
                                <div class="tab-pane" id="Youtube">
                                    <div class="card-body p-2">
                                        <div id="example1_wrapper">
                                            <div class="row">
                                                <div class="col-sm-12">
                                                    <ol class="float-sm-right">
                                                        <button href="" id="addYoutubeButton" data-bs-toggle="modal"
                                                            data-bs-target="#addYoutubeModal"
                                                            style="background-color: #121212; color: #CBA255; border:none; border-radius:5px; height: 40px;">
                                                            <i class="fa-solid fa-plus"></i> Add YouTube URL
                                                        </button>
                                                    </ol>
                                                </div>
                                                <!-- Table Section -->
                                                <div class="col-sm-12 table-responsive">
                                                    <table id="example2" class="table table-striped table-bordered"
                                                        aria-describedby="example1_info">
                                                        <thead>
                                                            <tr>
                                                                <th>S.No</th>
                                                                <th>YouTube URL</th>
                                                                <th>Action</th>
                                                            </tr>
                                                        </thead>
                                                        <tbody>
                                                            {{#each allData.videoSongs}}
                                                            <tr>
                                                                <td>{{inc @index}}</td>
                                                                <td>
                                                                    <iframe src="https://www.youtube.com/embed/{{this}}"
                                                                        width="100%" height="auto" frameborder="0"
                                                                        allowfullscreen></iframe>
                                                                </td>
                                                                <td
                                                                    style="display: flex; justify-content: center; flex-direction: row; align-items: center; padding-top: 60px;">
                                                                    <button class="btn btn-md btn-danger"
                                                                        data-bs-toggle="modal"
                                                                        data-bs-target="#deleteYoutubeModel"
                                                                        data-posterid="{{posterId}}"
                                                                        data-songindex="{{@index}}">
                                                                        <i class="fa-solid fa-trash"></i>
                                                                    </button>
                                                                </td>
                                                            </tr>
                                                            {{/each}}
                                                        </tbody>
                                                    </table>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
</body>


{{!-- Add faculty modal --}}
<div class="modal fade" id="addFacultiesModal" tabindex="-1" aria-labelledby="addModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h3><b>Add Song</b></h3>
            </div>
            <form id="addFacultyForm" action="/admin/addsongs/{{allData._id}}" method="post"
                enctype="multipart/form-data">
                <div class="modal-body">
                    <label for="songName">Song Name</label>
                    <input type="text" class="form-control" name="songName" placeholder="Song Name" required>
                </div>
                <div class="modal-body">
                    <label for="songArtists">Song Artists</label>
                    <input class="form-control" name="songArtists" placeholder="Song Artists" required>
                </div>
                <div class="modal-footer">
                    <button type="submit" class="btn btn-success" id="submitBtn"
                        style="background-color: rgb(0, 0, 0); color: white">
                        Add Song
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>

<script>
    document.getElementById("addFacultyForm").addEventListener("submit", function (event) {
        const submitButton = document.getElementById("submitBtn");

        // Disable the button and change its text to "Adding..."
        submitButton.disabled = true;
        submitButton.textContent = "Adding...";
    });
</script>

{{!-- update songs modal --}}
<div class="modal fade" id="updateFacultyModal" tabindex="-1" aria-labelledby="updateFacultyLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 style="color: black; font-weight: bold;">Update Song</h5>
            </div>
            <form id="updateFacultyForm" method="post" enctype="multipart/form-data"
                action="/admin/udpatesongs/{{allData._id}}">
                <div class="modal-body">
                    <label for="songName">Song Name</label>
                    <input type="text" class="form-control" name="songName" required>
                </div>
                <div class="modal-body">
                    <label for="songArtists">Song Artists</label>
                    <input type="text" class="form-control" name="songArtists" required>
                </div>
                <input type="hidden" name="songId" id="songId">
                <div class="modal-footer">
                    <button type="submit" class="btn btn-success" id="updateSubmitBtn">Update</button>
                </div>
            </form>
        </div>
    </div>
</div>

{{!-- delete songs --}}
{{!-- <div class="modal fade" id="deleteSongModal" tabindex="-1" aria-labelledby="deleteSongModalLabel"
    aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body">
                Are you sure you want to delete this song?
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
                <a href="" id="confirmDeleteSongBtn" class="btn btn-danger">Delete</a>
            </div>
        </div>
    </div>
</div> --}}

<div class="modal fade" id="deleteModal" tabindex="-1" aria-labelledby="deleteModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 style="color: black; font-weight: 500;">Are you sure you want to delete this Song?</h4>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close">X</button>
            </div>
            <div class="modal-footer">
                <form action="/admin/deletesong" method="post">
                    <!-- Hidden input for the songId -->
                    {{!-- <input type="hidden" name="posterId" id="posterId" value="{{allSongs._id}}"> --}}
                    <!-- Hidden input for the iconId -->
                    <input type="hidden" name="posterId" value="{{allData._id}}">
                    <input type="hidden" name="songId" id="songId" value="">

                    <!-- Submit button for confirming the deletion -->
                    <button type="submit" class="btn btn-danger">Yes</button>
                </form>
                <!-- Cancel button -->
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">No</button>
            </div>
        </div>
    </div>
</div>

<!-- Add YouTube URL Modal -->
<div class="modal fade" id="addYoutubeModal" tabindex="-1" aria-labelledby="addYoutubeModalLabel" aria-hidden="true">
    <div class="modal-dialog custom-width"> <!-- Apply custom width class here -->
        <div class="modal-content">
            <div class="modal-header">
                <h5 style="color: black; font-weight: bold; font-size: 20px;">Add YouTube URL</h5>
                {{!-- <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close">X</button> --}}
            </div>
            <form action="/admin/addyoutube/{{allData._id}}" method="post" enctype="multipart/form-data"
                id="youtubeForm">
                <div class="modal-body">
                    <label for="videoSongs">YouTube URL</label><br>
                    <input type="url" class="form-control" name="videoSongs" placeholder="Enter YouTube URL" required>
                </div>
                <div class="modal-footer">
                    <button type="submit" class="btn btn-success" style="background-color: #121212; color: #CBA255">Add
                        YouTube URL</button>
                </div>
            </form>
        </div>
    </div>
</div>
<!-- Delete YouTube URL Modal -->
<div class="modal fade" id="deleteYoutubeModel" tabindex="-1" aria-labelledby="deleteYoutubeModelLabel"
    aria-hidden="true">
    <div class="modal-dialog custom-width">
        <div class="modal-content">
            <form id="deleteYoutubeForm" method="post" action="/admin/poster/{{allData._id}}/delete-youtube">
                <div class="modal-body">
                    <input type="hidden" id="posterIdInput" name="posterId">
                    <input type="hidden" id="songIndexInput" name="songIndex">
                    <h4 style="color: black; font-weight: 170px;">Are you sure you want to delete this URL?</h4>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" style="background-color: #121212; color: #CBA255;"
                        data-bs-dismiss="modal">Cancel</button>
                    <button type="submit" class="btn btn-danger">Delete</button>
                </div>
            </form>
        </div>
    </div>
</div>

<script>
    $(document).ready(function () {
        // Initialize DataTables
        if (!$.fn.DataTable.isDataTable('#example2')) {
            $('#example2').DataTable({ "paging": true });
        }
    });
</script>


{{!-- Update Faculties --}}
<script>
    $(document).ready(function () {
        $('#updateFacultyModal').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget); // Button that triggered the modal
            var modal = $(this);

            // Extract info from data-* attributes
            var songId = button.data('id');
            var songName = button.data('song-name'); // Match the data attribute: data-song-name
            var songArtists = button.data('song-artists'); // Match the data attribute: data-song-artists

            // Populate modal fields
            modal.find('input[name="songName"]').val(songName);
            modal.find('input[name="songArtists"]').val(songArtists);
            modal.find('input[name="songId"]').val(songId);
        });
    });

</script>
{{!-- Delete songs --}}

<script>
    $(document).ready(function () {
        $('#deleteModal').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget); // Button that triggered the modal
            var songId = button.data('id'); // Extract songId from 'data-id' attribute
            var posterId = button.data('posterid'); // Extract posterId from 'data-posterid' attribute

            var modal = $(this);
            // Populate hidden inputs in the form
            modal.find('#songId').val(songId);
            modal.find('#posterId').val(posterId);
        });
    });
</script>

{{!-- script uout --}}
<script>
    document.addEventListener('DOMContentLoaded', function () {
        // Get the delete modal
        const deleteModal = document.getElementById('deleteYoutubeModel');
        const deleteForm = document.getElementById('deleteYoutubeForm');

        deleteModal.addEventListener('show.bs.modal', function (event) {
            // Button that triggered the modal
            const button = event.relatedTarget;

            // Extract info from data-* attributes
            const posterId = button.getAttribute('data-posterid');
            const songIndex = button.getAttribute('data-songindex');

            // Update hidden inputs with these values
            document.getElementById('posterIdInput').value = posterId;
            document.getElementById('songIndexInput').value = songIndex;

            // Set the form's action dynamically based on posterId and songIndex
            deleteForm.action = `admin/poster/${allData._id}`;
        });
    });

</script>
{{!-- script youtube delete --}}
<script>
    $('#deleteYoutubeModel').on('show.bs.modal', function (event) {
        var button = $(event.relatedTarget); // Button that triggered the modal
        var posterId = button.data('posterid'); // Extract posterId from data-* attributes
        var songIndex = button.data('songindex'); // Extract songIndex from data-* attributes

        // Update the modal's hidden input fields
        var modal = $(this);
        modal.find('#posterIdInput').val(posterId);
        modal.find('#songIndexInput').val(songIndex);
    });

</script>



{{>adminFooter}}


<!-- Include Summernote JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.18/summernote-bs4.min.js"></script>

<!-- JavaScript dependencies -->
<script src="/admin/js/bootstrap.bundle.min.js"></script>
<script src="/admin/js/summernote-bs4.min.js"></script>




{{!-- summernotes css --}}
<script>
    $(document).ready(function () {
        $('#summernote7').summernote({
            height: 120,  // Set editor height
            callbacks: {
                onInit: function () {
                    $('#summernote3').summernote('format', 'foreColor', 'black');
                }
            }
        });
    });
</script>



<style>
    #summernote1,
    #summernote2,
    #summernote3,
    #summernote4,
    #summernote5,
    #summernote6,
    #summernote7,
    #summernote8,
    #summernote9 {
        color: black !important;
    }
</style>

</html>