{% extends 'userapp/master.html' %}
{% load static %}
{% block content %}

<style>
    body {
        font-family: Arial, sans-serif;
        background: url("{% static 'images/background.jpg' %}") no-repeat center center fixed;
        background-size: cover;
        margin: 0;
        padding: 20px;
    }

    .container {
        max-width: 400px;
        background: rgba(255, 255, 255, 0.9); /* Transparent white */
        padding: 20px;
        border-radius: 10px;
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    }

    .header {
        text-align: center;
        font-size: 22px;
        font-weight: bold;
    }

    .ride-info {
        background: #e8f5e9;
        padding: 15px;
        border-radius: 8px;
        margin-top: 10px;
    }

    .ride-info div {
        margin: 5px 0;
    }

    .btn {
        display: block;
        width: 100%;
        padding: 10px;
        text-align: center;
        border: none;
        border-radius: 5px;
        cursor: pointer;
        font-size: 16px;
        margin-top: 10px;
    }

    .replace {
        background: #ffc107;
        color: black;
    }

    .return {
        background: #4caf50;
        color: white;
    }

    .toggle-section {
        margin-top: 15px;
        padding: 10px;
        background: #eeeeee;
        border-radius: 8px;
    }

    .footer {
        margin-top: 20px;
        text-align: center;
    }

    /* Modal styles */
    .modal {
        display: none;
        position: fixed;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.5);
        align-items: center;
        justify-content: center;
    }

    .modal-content {
        background: white;
        padding: 20px;
        text-align: center;
        width: 50%;
    }

    .buttons {
        margin-top: 20px;
    }

    .btn.confirm {
        background-color: red;
        color: white;
    }

    .btn.cancel {
        background-color: gray;
        color: white;
    }
</style>

<div class="container my-5">
    <h2 class="text-center text-primary">Ongoing Ride</h2>
    <div class="container border-0 shadow-none mt-2">
        <div class="text-dark"><strong class="text-primary">Bike Code Number:</strong>{{bike_rent.bike.code}}</div>
        <div class="text-dark"><strong class="text-primary">Upto 15 mins:</strong> 30/- rs (30/- rs for next every 15 mins)</div>
        <div class="text-dark"><strong class="text-primary">Pick-Up Station:</strong>{{bike_rent.bike.station.name}}, {{bike_rent.bike.station.location}}</div>
        <div class="text-dark"><strong class="text-primary">Category:</strong>{{bike_rent.bike.category.name}} </div>
        <div class="text-dark"><strong class="text-primary">Start Time:</strong> <span id="ride-timer">{{bike_rent.start_time|date:'H:i A'}}</span></div>

        <div class="text-dark"><strong class="text-primary">
            <h6>Ride Time:</strong> <span id="ride-time">00:00:00</span></h6>
        </div>
    </div>
    <div class="container-fluid pt-5">
        <button class="btn btn-primary w-20 h-10" type="button" onclick="openModal()">End Ride</button>
    </div>
</div>

<div id="confirmModal" class="modal">
    <div class="modal-content">
        <h4>Confirm End Ride</h4>
        <p>Are you sure you want to end the ride?</p>
        <div class="buttons">
            <form method="post">
                {% csrf_token %}
                <button type="submit" class="btn confirm">Yes, End Ride</button>
            </form>
            <button class="btn cancel" onclick="closeModal()">Cancel</button>
        </div>
    </div>
</div>

<script>
    function updateRideTime() {
        let startTime = new Date("{{ bike_rent.start_time|date:'Y-m-d H:i:s' }}").getTime();
        setInterval(function () {
            let currentTime = new Date().getTime();
            let elapsedTime = new Date(currentTime - startTime);

            let hours = String(elapsedTime.getUTCHours()).padStart(2, '0');
            let minutes = String(elapsedTime.getUTCMinutes()).padStart(2, '0');
            let seconds = String(elapsedTime.getUTCSeconds()).padStart(2, '0');

            document.getElementById("ride-time").innerText = `${hours}:${minutes}:${seconds}`;
        }, 1000);
    }

    updateRideTime();

    function openModal() {
        document.getElementById("confirmModal").style.display = "flex";
    }

    function closeModal() {
        document.getElementById("confirmModal").style.display = "none";
    }
</script>

{% endblock %}
