{% extends "base.html" %}

{% block title %}Delete Account - AISBF{% endblock %}

{% block content %}
<div class="container">
    <h1 style="color: #f44336;">Delete Account</h1>
    <p data-i18n="delete_page.warning">This action cannot be undone. All your data will be permanently deleted.</p>

    {% if error %}
    <div class="alert alert-error">{{ error }}</div>
    {% endif %}

    {% if has_subscription %}
    <div class="alert alert-warning">
        <strong>⚠️ Warning: Active Subscription Detected</strong>
        <p style="margin-top: 0.5rem;">You have an active paid subscription ({{ subscription_tier }}). Deleting your account will:</p>
        <ul style="margin-left: 1.5rem; margin-top: 0.5rem;">
            <li>Cancel your subscription immediately</li>
            <li>You will lose access to all premium features</li>
            <li>No refunds will be issued for remaining subscription time</li>
        </ul>
        <p style="margin-top: 0.5rem;">Consider canceling your subscription first if you want to use it until the end of the billing period.</p>
    </div>
    {% endif %}

    <div class="card danger-card">
        <h2 data-i18n="delete_page.confirm_title">Confirm Account Deletion</h2>
        
        <div class="warning-box">
            <h3>⚠️ This will permanently delete:</h3>
            <ul>
                <li>Your account and profile information</li>
                <li>All your API providers and configurations</li>
                <li>All your rotation and autoselect settings</li>
                <li>All your usage history and analytics</li>
                <li>All your API tokens</li>
                {% if has_subscription %}
                <li><strong>Your active subscription ({{ subscription_tier }})</strong></li>
                {% endif %}
            </ul>
        </div>
        
        <form method="POST" action="{{ url_for(request, '/dashboard/delete-account') }}" onsubmit="return confirmDeletion()">
            <div class="form-group">
                <label for="password" data-i18n="delete_page.password">Enter Your Password to Confirm</label>
                <input type="password" id="password" name="password" required>
            </div>

            <div class="form-group">
                <label for="confirmation" data-i18n="delete_page.type_delete">Type "DELETE" to confirm</label>
                <input type="text" id="confirmation" name="confirmation" required placeholder="DELETE">
            </div>

            <div style="margin-top: 1.5rem; display: flex; gap: 1rem;">
                <button type="submit" class="btn btn-danger" data-i18n="delete_page.submit">Delete My Account Permanently</button>
                <a href="{{ url_for(request, '/dashboard/profile') }}" class="btn btn-secondary">Cancel</a>
            </div>
        </form>
    </div>
</div>

<style>
.container {
    margin: 0 auto;
    padding: 2rem;
}

.card {
    background: #16213e;
    padding: 2rem;
    border-radius: 8px;
    margin-top: 1.5rem;
}

.danger-card {
    border: 2px solid #d32f2f;
}

.card h2 {
    margin-bottom: 1.5rem;
    color: #f44336;
}

.warning-box {
    background: #1a1a2e;
    border-left: 4px solid #f44336;
    padding: 1rem;
    margin-bottom: 1.5rem;
    border-radius: 4px;
}

.warning-box h3 {
    color: #f44336;
    margin-bottom: 0.75rem;
    font-size: 1.1rem;
}

.warning-box ul {
    margin-left: 1.5rem;
    color: #e0e0e0;
}

.warning-box li {
    margin-bottom: 0.5rem;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #e0e0e0;
}

.form-group input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #0f3460;
    border-radius: 4px;
    background: #1a1a2e;
    color: #e0e0e0;
    font-size: 1rem;
}

.form-group input:focus {
    outline: none;
    border-color: #f44336;
}

.alert {
    padding: 1rem;
    border-radius: 4px;
    margin-bottom: 1rem;
}

.alert-error {
    background: #b71c1c;
    color: #ef9a9a;
    border: 1px solid #c62828;
}

.alert-warning {
    background: #e65100;
    color: #ffcc80;
    border: 1px solid #ef6c00;
}

.alert-warning strong {
    display: block;
    margin-bottom: 0.5rem;
}

.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    text-decoration: none;
    display: inline-block;
}

.btn-danger {
    background: #d32f2f;
    color: white;
    font-weight: 600;
}

.btn-danger:hover {
    background: #b71c1c;
}

.btn-secondary {
    background: #0f3460;
    color: #e0e0e0;
}

.btn-secondary:hover {
    background: #16213e;
}
</style>

<script>
async function confirmDeletion() {
    const confirmation = document.getElementById('confirmation').value;
    if (confirmation !== 'DELETE') {
        showAlert('Please type "DELETE" exactly to confirm account deletion.', 'Validation Error', '⚠️', 'warn');
        return false;
    }
    return await showDangerConfirm('Are you absolutely sure? This action cannot be undone and all your data will be permanently deleted.', 'Delete Account');
}
</script>
{% endblock %}
