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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>GTA V Mod Converter</title>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600&display=swap" rel="stylesheet">
    <style>
        :root {
            --primary: #c084fc;
            --primary-glow: #a855f7;
            --glass-bg: rgba(255, 255, 255, 0.05);
            --glass-border: rgba(255, 255, 255, 0.1);
            --text: #ffffff;
            --text-secondary: #a1a1aa;
        }

        body {
            font-family: 'Outfit', sans-serif;
            background-color: #0f172a;
            background-image: url('{{ url_for("static", filename="background.png") }}');
            background-size: cover;
            background-position: center;
            background-repeat: no-repeat;
            color: var(--text);
            margin: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            overflow: hidden;
        }

        .container {
            background: var(--glass-bg);
            backdrop-filter: blur(16px);
            -webkit-backdrop-filter: blur(16px);
            padding: 3rem;
            border-radius: 24px;
            border: 1px solid var(--glass-border);
            box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
            width: 90%;
            max-width: 550px;
            text-align: center;
            transition: transform 0.3s ease;
        }

        .container:hover {
            transform: translateY(-5px);
            border-color: rgba(255, 255, 255, 0.2);
        }

        h1 {
            margin-bottom: 0.5rem;
            font-weight: 600;
            font-size: 2.5rem;
            background: linear-gradient(135deg, #fff 0%, #c084fc 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            letter-spacing: -1px;
        }

        p {
            color: var(--text-secondary);
            margin-bottom: 2.5rem;
            font-weight: 300;
        }

        .input-group {
            margin-bottom: 2rem;
            text-align: left;
            position: relative;
        }

        label {
            display: block;
            margin-bottom: 0.75rem;
            color: var(--text);
            font-size: 0.9rem;
            font-weight: 500;
            margin-left: 5px;
        }

        input[type="text"] {
            width: 100%;
            padding: 16px;
            border-radius: 12px;
            border: 1px solid var(--glass-border);
            background: rgba(0, 0, 0, 0.2);
            color: white;
            font-family: 'Outfit', sans-serif;
            font-size: 1rem;
            box-sizing: border-box;
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        }

        input[type="text"]:focus {
            outline: none;
            border-color: var(--primary);
            box-shadow: 0 0 0 4px rgba(192, 132, 252, 0.1);
            background: rgba(0, 0, 0, 0.4);
        }

        input[type="text"]::placeholder {
            color: rgba(255, 255, 255, 0.3);
        }

        button {
            background: linear-gradient(135deg, var(--primary) 0%, var(--primary-glow) 100%);
            color: white;
            border: none;
            padding: 1.2rem;
            font-size: 1.1rem;
            font-weight: 600;
            border-radius: 12px;
            cursor: pointer;
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            width: 100%;
            font-family: 'Outfit', sans-serif;
            box-shadow: 0 10px 15px -3px rgba(168, 85, 247, 0.3);
        }

        button:hover {
            transform: translateY(-2px);
            box-shadow: 0 20px 25px -5px rgba(168, 85, 247, 0.4);
            filter: brightness(1.1);
        }

        button:active {
            transform: translateY(0);
        }

        button:disabled {
            background: #4b5563;
            transform: none;
            cursor: not-allowed;
            box-shadow: none;
        }

        .progress-container {
            margin-top: 2rem;
            display: none;
        }

        .spinner {
            border: 4px solid rgba(255, 255, 255, 0.1);
            width: 40px;
            height: 40px;
            border-radius: 50%;
            border-left-color: var(--primary);
            animation: spin 1s cubic-bezier(0.4, 0, 0.2, 1) infinite;
            margin: 0 auto 15px auto;
        }

        @keyframes spin {
            0% {
                transform: rotate(0deg);
            }

            100% {
                transform: rotate(360deg);
            }
        }

        .status-text {
            font-size: 0.95rem;
            color: var(--text-secondary);
            margin: 0;
            font-weight: 400;
        }

        .result-area {
            margin-top: 2.5rem;
            display: none;
            animation: fadeIn 0.5s ease;
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translateY(10px);
            }

            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .download-btn {
            background: linear-gradient(135deg, #10b981 0%, #059669 100%);
            box-shadow: 0 10px 15px -3px rgba(16, 185, 129, 0.3);
            text-decoration: none;
            display: inline-block;
            margin-top: 1rem;
            color: white;
            padding: 1rem 2rem;
            border-radius: 12px;
            font-weight: 600;
            transition: all 0.3s ease;
        }

        .download-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 20px 25px -5px rgba(16, 185, 129, 0.4);
        }

        .secondary-btn {
            background: transparent;
            border: 1px solid var(--glass-border);
            width: auto;
            margin-top: 1.5rem;
            padding: 0.8rem 1.5rem;
            font-size: 0.9rem;
            box-shadow: none;
        }

        .secondary-btn:hover {
            background: rgba(255, 255, 255, 0.1);
            box-shadow: none;
        }
    </style>
</head>

<body>
    <div class="container">
        <h1>Mod to Resource</h1>
        <p>Premium GTA V Vehicle Converter</p>

        <div class="input-group">
            <label for="url-input">GTA5-Mods Link</label>
            <input type="text" id="url-input" placeholder="Paste link here..." autocomplete="off">
        </div>

        <button id="convert-btn">Convert Vehicle</button>

        <div class="progress-container" id="progress-container">
            <div class="spinner"></div>
            <p class="status-text" id="status-text">Creating magic...</p>
        </div>

        <div class="result-area" id="result-area">
            <h3 style="margin-top: 0; font-weight: 500;">Ready to Deploy</h3>
            <a href="#" id="download-link" class="download-btn">Download Resource</a>
            <br>
            <button onclick="location.reload()" class="secondary-btn">Convert Another</button>
        </div>
    </div>

    <script>
        const urlInput = document.getElementById('url-input');
        const convertBtn = document.getElementById('convert-btn');
        const progressContainer = document.getElementById('progress-container');
        const statusText = document.getElementById('status-text');
        const resultArea = document.getElementById('result-area');
        const downloadLink = document.getElementById('download-link');

        convertBtn.addEventListener('click', () => {
            const url = urlInput.value.trim();
            if (!url) {
                // Shake effect on error if desired, for now just alert/focus
                urlInput.focus();
                return;
            }

            convertBtn.disabled = true;
            urlInput.disabled = true;
            progressContainer.style.display = 'block';
            resultArea.style.display = 'none';
            statusText.textContent = 'Initializing engine...';

            fetch('/process', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify({ url: url }),
            })
                .then(response => response.json())
                .then(data => {
                    if (data.success) {
                        statusText.textContent = 'Vehicle converted successfully!';
                        downloadLink.href = data.download_url;
                        resultArea.style.display = 'block';
                        progressContainer.style.display = 'none';
                    } else {
                        statusText.textContent = 'Error: ' + (data.error || 'Something went wrong');
                        convertBtn.disabled = false;
                        urlInput.disabled = false;
                    }
                })
                .catch(error => {
                    console.error('Error:', error);
                    statusText.textContent = 'Connection failed.';
                    convertBtn.disabled = false;
                    urlInput.disabled = false;
                });
        });
    </script>
</body>

</html>