{% load static %}

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Osina</title>

    <link rel="stylesheet" type="text/css" href='{% static "dist/output.css" %}'>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
</head>

<body class="font-poppinsLight">
    <form id="addPointModal"  method="POST" action="{% url 'addpointmodal' task.task_id %}">
        {% csrf_token %}
        <h1 class="text-secondosiblue text-2xl font-semibold text-center">Add Point</h1>
        <div class="w-full flex justify-center items-center">
            <input name="text" type="text" placeholder="Type your point here..."
                class="w-full p-3 border border-gray-300 rounded-md bg-transparent outline-none mt-4" required id="pointInput">
        </div>

        <div class="w-full flex justify-end items-center mt-4 gap-2">
            <button
                class="w-fit bg-osiblue border border-osiblue rounded-md text-white px-5 py-1 hover:bg-white hover:text-osiblue duration-300"
                id="savePointButton">Save</button>
            <button type="submit"
                class="w-fit bg-osiblue border border-osiblue rounded-md text-white px-5 py-1 hover:bg-white hover:text-osiblue duration-300">Save and Continue</button>
        </div>


    </form>

    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function() {
            $('#savePointButton').on('click', function(e) {
                e.preventDefault();
                var form = $('#addPointModal');
                $.ajax({
                    type: form.attr('method'),
                    url: form.attr('action'),
                    data: form.serialize(),
                    success: function(response) {
                        window.parent.location.reload();
                    },
                    error: function(xhr, status, error) {
                        alert('An error occurred while saving the point.');
                    }
                });
            });
        });
    </script>
</body>

</html>