{{>adminHeader}}
<title>RECENT RELEASES SONGS</title>

<style>
    table {
        width: 100%;
        border-collapse: collapse;
    }

    th,
    td {
        padding: 8px 12px;
        text-align: left;
        border: 1px solid #ddd;
    }

    th.si-no,
    td.si-no {
        width: 50px;
    }

    th.action,
    td.action {
        width: 100px;
    }

    th.banner,
    td.banner {
        width: 300px;
    }

    th.banner {
        white-space: nowrap;
    }

    @media screen and (max-width: 768px) {

        th,
        td {
            font-size: 14px;
        }
    }

    /* Styling for select fields */
    select {
        background-color: #121212;
        color: #CBA255;
        padding: 0%;
        width: 100%;
        border: none;
        border-radius: 5px;
        cursor: pointer;
    }

    select:hover {
        background-color: #1a1a1a;
        color: #CBA255;
    }

    /* Styling for options inside select */
    option {
        background-color: #121212;
        color: #CBA255;
    }

    /* Styling for hovered options */
    select option:hover {
        background-color: #1a1a1a;
        color: #CBA255;
    }

    /* Adding focus state for better interaction */
    select:focus {
        outline: none;
        box-shadow: 0 0 5px rgba(203, 162, 85, 0.8);
    }

    .switch {
        position: relative;
        display: inline-block;
        width: 60px;
        height: 34px;
    }

    /* Hide default HTML checkbox */
    .switch input {
        opacity: 0;
        width: 0;
        height: 0;
    }

    /* The slider */
    .slider {
        position: absolute;
        cursor: pointer;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: red;
        /* Red for off state */
        transition: .4s;
    }

    .slider:before {
        position: absolute;
        content: "";
        height: 26px;
        width: 26px;
        left: 4px;
        bottom: 4px;
        background-color: white;
        transition: .4s;
    }

    input:checked+.slider {
        background-color: green;
        /* Green for on state */
    }

    input:focus+.slider {
        box-shadow: 0 0 1px #2196F3;
    }

    input:checked+.slider:before {
        transform: translateX(26px);
    }

    /* Rounded sliders */
    .slider.round {
        border-radius: 34px;
    }

    .slider.round:before {
        border-radius: 50%;
    }
</style>

<div class="row p-2" style="margin: 0px !important;">
    <div class="col-md-12">
        <div class="card mt-2" style="border-left: 2px solid black;">
            <div class="card-header">
                <h4><b>RECENT RELEASES SONGS</b></h4>
            </div>
            <div class="card-body p-2">
                <div class="d-flex justify-content-end mb-3">
                    <button id="addSongBtn" data-bs-toggle="modal" data-bs-target="#addSongModal"
                        style="background-color: #121212; color: #CBA255; border:none; border-radius:5px; width: 180px; height: 40px;">
                        <i class="fa-solid fa-plus"></i> Add Recent Song
                    </button>
                </div>
                <div class="table-responsive">
                    <table id="example2" class="table table-striped table-bordered">
                        <thead>
                            <tr>
                                <th class="si-no">S.No</th>
                                <th>Name</th>
                                <th>Thumbnail</th>
                                <th>Recommendation</th>
                                <th>YouTube Link</th>
                                <th class="action">Action</th>
                            </tr>
                        </thead>
                        <tbody>
                            {{#each allRecentReleases}}
                            <tr>
                                <td>{{inc @index}}</td>
                                <td>{{this.recentTitle}}</td>
                                <td>
                                    {{#if this.recentThumbNail}}
                                    <img src="/{{this.recentThumbNail}}" alt="Recent Song Thumbnail"
                                        style="height: 60px;">
                                    {{/if}}
                                </td>
                                <td>{{this.status}}</td>
                                <td>
                                    {{#if this.recentYouTubeLink}}
                                    <a href="{{this.recentYouTubeLink}}" target="_blank">Watch</a>
                                    {{/if}}
                                </td>
                                <td>
                                    <div class="d-flex justify-content-center">
                                        <a href="javascript:void(0);" data-bs-toggle="modal"
                                            data-bs-target="#updateSongModals" class="btn btn-md btn-info m-1"
                                            data-id="{{this._id}}" data-title="{{this.recentTitle}}"
                                            data-thumbnail="{{this.recentThumbNail}}"
                                            data-link="{{this.recentYouTubeLink}}" data-status="{{this.status}}">
                                            <i class="fa-solid fa-edit"
                                                style="background-color: #121212; color: #CBA255;"></i>
                                        </a>
                                        <a href="javascript:void(0);" data-bs-toggle="modal" data-id="{{this._id}}"
                                            data-bs-target="#deleteModal" class="btn btn-md btn-danger m-1">
                                            <i class="fa-solid fa-trash"></i>
                                        </a>
                                    </div>
                                </td>
                            </tr>
                            {{/each}}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- Add recent Modal -->
<div class="modal fade" id="addSongModal" tabindex="-1" aria-labelledby="addSongModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 style="color: black; font-weight: bold; font-size: 20px;" id="addSongModalLabel">Add Recent Song
                </h5>
            </div>
            <form id="addSongForm" action="/admin/addrecentrelease" method="post" enctype="multipart/form-data">
                <div class="modal-body">
                    <div class="form-group">
                        <label for="songTitle">Song Title</label>
                        <input type="text" class="form-control" id="songTitle" name="recentTitle" required>
                    </div>
                    <div class="form-group">
                        <label for="thumbNail">Thumbnail</label>
                        <input type="file" class="form-control" id="thumbNail" name="recentThumbNail"
                            accept=".jpg, .jpeg, .png" required>
                    </div>
                    <div class="mb-3">
                        <label for="recentYouTubeLink" class="form-label">YouTube Link</label>
                        <input type="url" class="form-control" id="recentYouTubeLink" name="recentYouTubeLink" required>
                    </div>
                </div>
                <div class="form-group">
                    <label>Preference</label>
                    <div class="form-check form-switch">
                        <label class="switch">
                            <input type="checkbox" name="status" id="statusToggle">
                            <span class="slider round"></span>
                        </label>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="submit" class="btn btn-success" style="background-color: #121212; color: #CBA255;">Add
                        Song</button>
                </div>
            </form>
        </div>
    </div>
</div>
<!-- Update recent Modal -->
<div class="modal fade" id="updateSongModals" tabindex="-1" aria-labelledby="updateSongModalsLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <form id="updateSongForm" method="post" enctype="multipart/form-data">
                <div class="modal-body">
                    <div class="mb-3">
                        <label for="recentTitle" class="form-label">Song Title</label>
                        <input type="text" class="form-control" id="recentTitle" name="recentTitle" required>
                    </div>
                    <div class="mb-3">
                        <label for="recentThumbNail">New Poster Picture</label>
                        <input type="file" id="recentThumbNail" class="modal-file" name="recentThumbNail"
                            accept=".jpg, .img, .jpeg, .png">
                    </div>
                    <div class="mb-3">
                        <label for="recentYouTubeLink" class="form-label">YouTube Link</label>
                        <input type="url" class="form-control" id="recentYouTubeLink" name="recentYouTubeLink" required>
                    </div>
                    <div class="mb-3">
                        <img id="currentRecentPicture" src="" alt="Current Thumbnail" width="60px" height="60px"
                            class="img-fluid">
                    </div>
                    <div class="mb-3">
                        <label for="recentTitle" class="form-label">Preference</label>
                        <input type="checkbox" class="status" name="status" data-on-text="On" data-off-text="Off"
                            data-on-color="success" data-off-color="danger" data-bootstrap-switch>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="submit" class="btn btn-success"
                        style="background-color: #121212; color: #CBA255;">Update Song</button>
                </div>
            </form>
        </div>
    </div>
</div>
<!-- Delete Confirmation Modal -->
<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 class="modal-title" style="color: black; font-weight: 480;">Are you sure you want to delete this
                    Recent release?</h4>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info" style="background-color: #c82333; color: white;"
                    data-bs-dismiss="modal">No</button>
                <a href="#" id="deleteConfirmButton" type="button" style="background-color: black; color: #CBA255;"
                    class="btn btn-danger">Yes</a>
            </div>
        </div>
    </div>
</div>
{{!-- script for update --}}
<script>
    $(document).ready(function () {
        $('#updateSongModals').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget);
            const recentId = button.data('id');
            const title = button.data('title');
            const thumbnail = button.data('thumbnail');
            const link = button.data('link');
            const status = button.data('status') === true || button.data('status') === 'true';

            var modal = $(this);
            modal.find('#recentId').val(recentId);
            modal.find('#recentTitle').val(title);
            modal.find('#recentYouTubeLink').val(link);
            modal.find('form#updateSongForm').attr('action', '/admin/updaterecentreleases/' + recentId);
            modal.find('img#currentRecentPicture').attr('src', '/' + thumbnail);
            modal.find('.status').prop('checked', status);
        });
    });
</script>
{{!-- toggle button true or false --}}
<script>
    $(document).ready(function () {
        $('#updateSongModals').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget);
            var modal = $(this);
            const status = button.data('status') === true || button.data('status') === 'true';
            modal.find('.status').prop('checked', status).bootstrapSwitch('state', status);
        });
        $("input[data-bootstrap-switch]").each(function () {
            $(this).bootstrapSwitch();
        });
    });
</script>
{{!-- delete modal --}}
<script>
    // When the delete button is clicked, dynamically update the delete URL
    document.addEventListener('DOMContentLoaded', function () {
        var deleteButtons = document.querySelectorAll('[data-bs-toggle="modal"]');

        deleteButtons.forEach(function (button) {
            button.addEventListener('click', function () {
                var id = this.getAttribute('data-id');
                var deleteUrl = '/admin/deleterecentreleases/' + id;
                var deleteConfirmButton = document.getElementById('deleteConfirmButton');
                deleteConfirmButton.setAttribute('href', deleteUrl);
            });
        });
    });
</script>

{{!-- button bootstrap --}}

<script>
    $(document).ready(function () {
        $("input[data-bootstrap-switch]").each(function () {
            $(this).bootstrapSwitch('state', $(this).prop('checked'));
        });
        $('.status').bootstrapSwitch('state');
    });
</script>



{{>adminFooter}}