<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Eversync</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
    {% load static %}
    <link rel="icon" href="{% static 'favicon.ico' %}">
    <link rel="stylesheet" href="{% static 'index-style.css' %}" ">

    <style>
.container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: calc(100vh - 100px); /* adjust for header height */
  padding: 20px;
}

.welcome-box {
  padding: 20px;
  border-radius: 8px;
  color: white;
  text-align: center;
  max-width: 90vw;
}

.welcome-box {
  flex: 0 0 250px;
  padding: 20px;
  border-radius: 8px;
  max-width: 250px; 
}

/* On mobile */
@media (max-width: 700px) {
  .container {
    flex-direction: column;
    align-items: center; 
  }
  .welcome-box {
    flex: none;
    width: auto;
    max-width: 90vw; 
    margin: 0 0 20px 0; 
    padding: 15px;
  }
  .content-box {
    width: 100%;
  }
}

    </style>
</head>
    
</head>
<body>
    <div class="header">
        <div class="header-content">
            <a href="/"><img src="{% static 'eversync2.png' %}" alt="Eversync Logo" style="height: 80px; margin-right: 10px; display: flex; align-items: center; gap: 5px;"></a>
            <a href="/" class="logo" >eversync</a>
            <div class="nav-links" style="position: relative;">
                <div class="dropdown">
                    <button class="dropdown-toggle" style="background: none; border: none; color: white; font-size: 16px; cursor: pointer;">
                        Welcome, {{ user.username }} <i class="fas fa-caret-down"></i>
                    </button>
                    <div class="dropdown-menu" style="display: none; position: absolute; right: 0; background-color: #333; border: 1px solid #444; border-radius: 4px; padding: 10px; width: 184px;">
                        
                        <form action="{% url 'manage' %}" method="post" style="margin: 0;">
                            {% csrf_token %}
                            <button type="submit" class="logout-button" style="background-color: transparent; color: white; border: none; cursor: pointer;">Manage Account</button>
                        </form>
                        
                        <form action="{% url 'logoutz' %}" method="post" style="margin: 0;">
                            {% csrf_token %}
                            <button type="submit" class="logout-button" style="background-color: transparent; color: white; border: none; cursor: pointer;">Log Out</button>
                        </form>
                        
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <div class="container">
        <div class="welcome-box">
            <h1>Thought Reframing</h1>
            <p style="color: black;">Type your negative thought below and let’s reframe it 💜</p>
          
            <input type="text" id="negativeThought" placeholder="I'm not good enough..." 
                   style="width: 100%;  margin-top: 10px; border-radius: 6px; border: 1px solid #aaa; font-size: 16px;">
            
            <button onclick="sendThought()" 
                    style="margin-top: 10px; padding: 10px 20px; font-size: 16px; background-color: #6a0dad; color: white; border: none; border-radius: 6px; cursor: pointer;">
              Reframe
            </button>
          
            <div id="positiveThought" style="margin-top: 15px; color: #c04cf4;"></div>
          </div>
<script>
    document.addEventListener('DOMContentLoaded', function () {
        const toggle = document.querySelector('.dropdown-toggle');
        const menu = document.querySelector('.dropdown-menu');
        toggle.addEventListener('click', function () {
            menu.style.display = menu.style.display === 'block' ? 'none' : 'block';
        });
    });
</script>

<script>
    async function sendThought() {
        const input = document.getElementById('negativeThought').value.trim();
        const output = document.getElementById('positiveThought');
    
        if (!input) {
            output.textContent = "Please enter a thought 💭";
            return;
        }
    
        output.textContent = "Thinking... 💭";
    
        try {
            const response = await fetch("https://ai.hackclub.com/chat/completions", {
                method: "POST",
                headers: {
                    "Content-Type": "application/json"
                },
                body: JSON.stringify({
                    messages: [
                        {
                            role: "user",
                            content: `Reframe this negative thought positively: "${input}". Provide only the rephrased thought. Do not include explanation or formatting. Make it warm and self-compassionate.`
                        }
                    ]
                })
            });
    
            const data = await response.json();
            const reply = data.choices?.[0]?.message?.content?.trim();
    
            output.textContent = reply || "Couldn't reframe that. Please try again 💔";
        } catch (error) {
            output.textContent = "Something went wrong. Try again later 🥺";
            console.error("API Error:", error);
        }
    }
    </script>
</body>
</html>