<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Odoo Setup</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }

        .form-container {
            background: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            width: 100%;
            max-width: 400px;
        }

        h2 {
            text-align: center;
            margin-bottom: 20px;
            color: #333;
        }

        label {
            display: block;
            font-weight: bold;
            margin-top: 10px;
        }

        input {
            width: 100%;
            padding: 8px;
            margin-top: 5px;
            border: 1px solid #ccc;
            border-radius: 5px;
        }

        .password-wrapper {
            position: relative;
        }

        .password-wrapper input {
            padding-right: 40px;
        }

        .toggle-password {
            position: absolute;
            right: 10px;
            top: 50%;
            transform: translateY(-50%);
            cursor: pointer;
            font-size: 18px;
            color: #555;
        }

        .toggle-password:hover {
            color: #000;
        }

        .error {
            color: red;
            font-size: 14px;
            margin-top: 5px;
        }

        .non-field-errors {
            background: #ffebee;
            color: #d32f2f;
            padding: 10px;
            border-radius: 5px;
            margin-bottom: 10px;
            text-align: center;
        }

        button {
            width: 100%;
            background-color: #007BFF;
            color: white;
            padding: 10px;
            border: none;
            border-radius: 5px;
            font-size: 16px;
            cursor: pointer;
            margin-top: 15px;
        }

        button:hover {
            background-color: #0056b3;
        }
    </style>
    <script>
        function togglePassword() {
            var passwordField = document.getElementById("api_token");
            var toggleIcon = document.getElementById("toggleIcon");

            if (passwordField.type === "password") {
                passwordField.type = "text";
                toggleIcon.textContent = "🙈";
            } else {
                passwordField.type = "password";
                toggleIcon.textContent = "👁️";
            }
        }
    </script>
</head>
<body>

    <div class="form-container">
        <h2>Odoo Setup</h2>

        {% if form.non_field_errors %}
            <div class="non-field-errors">
                {% for error in form.non_field_errors %}
                    <p>{{ error }}</p>
                {% endfor %}
            </div>
        {% endif %}

        <form method="post">
            {% csrf_token %}

            <label for="id_url">Odoo URL</label>
            {{ form.url }}
            {% if form.url.errors %}
                <div class="error">
                    {% for error in form.url.errors %}
                        <p>{{ error }}</p>
                    {% endfor %}
                </div>
            {% endif %}

            <label for="id_database_name">Database Name</label>
            {{ form.database_name }}
            {% if form.database_name.errors %}
                <div class="error">
                    {% for error in form.database_name.errors %}
                        <p>{{ error }}</p>
                    {% endfor %}
                </div>
            {% endif %}

            <label for="id_username">Username</label>
            {{ form.username }}
            {% if form.username.errors %}
                <div class="error">
                    {% for error in form.username.errors %}
                        <p>{{ error }}</p>
                    {% endfor %}
                </div>
            {% endif %}

            <label for="id_api_token">API token</label>
            <div class="password-wrapper">
                {{ form.api_token }}
                <span id="toggleIcon" class="toggle-password" onclick="togglePassword()">👁️</span>
            </div>
            {% if form.api_token.errors %}
                <div class="error">
                    {% for error in form.api_token.errors %}
                        <p>{{ error }}</p>
                    {% endfor %}
                </div>
            {% endif %}

            <button type="submit">Save</button>
        </form>
    </div>

</body>
</html>
