<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Execute MySQL Query</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f8f9fa;
        }

        .container {
            background-color: #ffffff;
            margin: 50px auto;
            padding: 20px;
            max-width: 800px;
            border-radius: 8px;
            box-shadow: 5px 8px 14px rgba(0, 0, 0, 0.1);
            overflow: auto;
        }

        h1 {
            font-size: 24px;
            color: #333;
        }

        textarea {
            width: 100%;
            border-radius: 4px;
            border: 1px solid #ccc;
            padding: 10px;
            font-size: 14px;
        }

        button {
            background-color: #007bff;
            color: #fff;
            border: none;
            padding: 10px 20px;
            font-size: 16px;
            border-radius: 4px;
            cursor: pointer;
        }

        button:hover {
            background-color: #0056b3;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }

        th, td {
            border: 1px solid #ddd;
            padding: 8px;
            text-align: left;
        }

        th {
            background-color: #f2f2f2;
        }

        p {
            font-size: 14px;
        }
    </style>
</head>
<body>
    <div class="container-lg text-center mt-5 p-4">
        <h1>Execute MySQL Query</h1>
        <p>{{ csv_file_path }}</p>

        <form method="post">
            {% csrf_token %}
            <textarea name="query" rows="5" cols="60" placeholder="Enter your SQL query here"></textarea><br>
            <button type="submit">Execute</button>
        </form>

        <h2>Output:</h2>
        {% if out_put.error %}
            <p style="color: red;">Error: {{ out_put.error }}</p>
        {% elif out_put.message %}
            <p style="color: green;">{{ out_put.message }}</p>
        {% elif out_put.data %}
            <table>
                <thead>
                    <tr>
                        {% for column in out_put.data.0 %}
                            <th>Column {{ forloop.counter }}</th>
                        {% endfor %}
                    </tr>
                </thead>
                <tbody>
                    {% for row in out_put.data %}
                        <tr>
                            {% for item in row %}
                                <td>{{ item }}</td>
                            {% endfor %}
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        {% else %}
            <p>No output.</p>
        {% endif %}
    </div>
</body>
</html>
