{% extends 'FirstApp/template.html' %}
<!DOCTYPE html>
<html lang="en">
<body id="page-top">
<!-- Page Wrapper -->

{% block javascript %}
        {% load static %}

        <!-- Bootstrap core JavaScript-->
      <script src="{% static 'FirstApp/vendor/jquery/jquery.min.js' %}"></script>
      <script src="{% static 'FirstApp/vendor/bootstrap/js/bootstrap.bundle.min.js' %}"></script>

      <!-- Core plugin JavaScript-->
      <script src="{% static 'FirstApp/vendor/jquery-easing/jquery.easing.min.js' %}"></script>


    <script type="text/javascript">
        const cur_date = new Date().toDateString();
        let video_name = '';
        $(document).ready(function () {
            $('.video_row').click(function () {
                video_name = $(this).attr('id');
                let video_duration = $(this).attr('data-duration');
                let src = "{% static '' %}FirstApp/videos/" + video_name;

                //assigning the src
                $("video").attr('src', src);

                //setting the video details
                $('#video_name').text(video_name);
                $('#video_duration').text(video_duration);
                $('#video_date').text(cur_date);

            });

            //to handle video extraction button

            $('#extractBtn').click(function () {
                //run the api
                fetch('http://127.0.0.1:8000/videoExtract', {
                   method: 'POST',
                   headers: {
                       "Content-type": "application/json"
                   },
                   body: JSON.stringify({
                       "video_name": video_name
                   })
                })
                .then((res) => res.json())
                .then((out) => alert(out.response))
                .catch((error) => alert('this is an error'));
            });
        });
    </script>


{% endblock %}

<div id="wrapper">
    <!-- Sidebar -->

    <!-- Content Wrapper -->
    <div id="content-wrapper" class="d-flex flex-column">

        <!-- Main Content -->
        <div id="content">

            <!-- Begin Page Content -->
            {% block 'container-fluid' %}
                <div class="container-fluid">
                    {% load static %}

                    <!-- Page Heading -->
                    <div class="d-sm-flex align-items-center justify-content-between mb-4">
                        <h1 class="h3 mb-0 text-gray-800">Video Extractor</h1>
                    </div>

                    <!--1st row -->
                    <div class="row p-2">

                        <!--first column -->
                        <div class="col-lg-6">

                            <!-- Main Video Context -->
                            <div class="card shadow mb-4">
                                <div class="card-header py-3">
                                    <h6 class="m-0 font-weight-bold text-primary">Main Video</h6>
                                </div>
                                <div class="card-body">
                                    <video width="500" height="300" id="first_video" controls>
                                        <source src="{% static '' %}FirstApp/videos/{{ firstVideo.name }}"
                                                type="video/mp4">
                                        Your browser does not support the video tag.
                                    </video>

                                    <table class="table table-borderless table-striped m-1">
                                        <tbody>
                                            <tr>
                                                <td class="font-weight-bold">Name</td>
                                                <td id="video_name">{{ firstVideo.name }}</td>
                                            </tr>
                                            <tr>
                                                <td class="font-weight-bold">Duration</td>
                                                <td id="video_duration">{{ firstVideo.duration }}</td>
                                            </tr>
                                            <tr>
                                                <td class="font-weight-bold">Date</td>
                                                <td id="video_date"></td>
                                            </tr>
                                        </tbody>
                                    </table>

                                    <div class="col-lg-3 p-3">
                                        <button type="button" class="btn btn-outline-primary" id="extractBtn">Extract</button>
                                    </div>

                                </div>
                            </div>
                        </div>


                        <!--second column -->
                        <div class="col-lg-6">

                            <!-- Main Video Context -->
                            <div class="card shadow mb-4">
                                <div class="card-header py-3">
                                    <h6 class="m-0 font-weight-bold text-primary">List of Lectures</h6>
                                </div>
                                <div class="card-body">
                                    <table class="table table-bordered">
                                        <thead>
                                        <tr>
                                            <th>Video Name</th>
                                            <th>Length</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        {% for video in Videos %}
                                            <tr class="video_row" id="{{ video.name }}" data-duration="{{ video.duration }}">
                                                <td>
                                                    {{ video.name }}
                                                </td>
                                                <td>{{ video.duration }}</td>
                                            </tr>
                                        {% endfor %}
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>




                </div>
            {% endblock %}
            <!-- End of container-fluid -->

        </div>
        <!-- End of Main Content -->

    </div>
    <!-- End of Content Wrapper -->

</div>

{% block 'modal' %}
    <div class="modal fade" id="gif-body" role="dialog" aria-labelledby="gif-body">
        <div class="modal-dialog modal-lg" style="max-width: 1600px; max-height: 800px">
            <div class="modal-content">
                <div class="modal-header">
                    <h2 class="modal-title">Processing....</h2>
                    <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">×</span>
                    </button>
                </div>

                <div class="modal-body text-center">
                    <img src="{% static 'FirstApp/images/ajax-loader.gif' %}" width="200" height="500"
                         alt="This is a GIF">
                    <h5>This might take few seconds...</h5>
                </div>
            </div>
        </div>
    </div>
{% endblock %}

</body>
</html>