{% extends "base.html" %}

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

{% block content %}
<div class="container">
    <h1 style="color: #f44336;" data-i18n="delete_page.title">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 data-i18n="delete_page.sub_warning_title">⚠️ 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 data-i18n="delete_page.sub_item_cancel">Cancel your subscription immediately</li>
            <li data-i18n="delete_page.sub_item_access">You will lose access to all premium features</li>
            <li data-i18n="delete_page.sub_item_refund">No refunds will be issued for remaining subscription time</li>
        </ul>
        <p style="margin-top: 0.5rem;" data-i18n="delete_page.sub_consider">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 data-i18n="delete_page.will_delete">⚠️ This will permanently delete:</h3>
            <ul>
                <li data-i18n="delete_page.item_account">Your account and profile information</li>
                <li data-i18n="delete_page.item_providers">All your API providers and configurations</li>
                <li data-i18n="delete_page.item_rotations">All your rotation and autoselect settings</li>
                <li data-i18n="delete_page.item_history">All your usage history and analytics</li>
                <li data-i18n="delete_page.item_tokens">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" data-i18n="delete_page.cancel">Cancel</a>
            </div>
        </form>
    </div>
</div>

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

.card {
    background: var(--bg-panel);
    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: var(--bg-page);
    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: var(--color-text);
}

.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: var(--color-text);
}

.form-group input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    background: var(--bg-page);
    color: var(--color-text);
    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: var(--bg-accent);
    color: var(--color-text);
}

.btn-secondary:hover {
    background: var(--bg-panel);
}
</style>

<script>
async function confirmDeletion() {
    const confirmation = document.getElementById('confirmation').value;
    if (confirmation !== 'DELETE') {
        showAlert(window.i18n.t('delete_page.type_delete_confirm'), 'Validation Error', '⚠️', 'warn');
        return false;
    }
    return await showDangerConfirm(window.i18n.t('delete_page.final_confirm'), window.i18n.t('delete_page.title'));
}
</script>
{% endblock %}
