"""
Web Pages Routes
Dashboard, AI Analysis, Portfolio, Alerts, Reports
"""

from flask import render_template, redirect, url_for
from flask_login import login_required, current_user
from app.routes.web import web_routes


# =========================
# Landing Page
# =========================
@web_routes.route('/')
def index():
    """Landing page"""
    if current_user.is_authenticated:
        return redirect(url_for('web.dashboard_home'))
    return render_template('index.html')


# =========================
# Dashboard Redirect
# =========================
@web_routes.route('/dashboard')
def dashboard_redirect():
    """Redirect to dashboard home"""
    return redirect(url_for('web.dashboard_home'))


# =========================
# Dashboard Pages
# =========================

@web_routes.route('/dashboard/home')
@login_required
def dashboard_home():
    return render_template('dashboard_home.html')


@web_routes.route('/dashboard/ai')
@login_required
def dashboard_ai():
    return render_template('ai_analysis.html')


@web_routes.route('/dashboard/portfolio')
@login_required
def dashboard_portfolio():
    return render_template('portfolio.html')


@web_routes.route('/dashboard/alerts')
@login_required
def dashboard_alerts():
    return render_template('alerts.html')


@web_routes.route('/dashboard/whale')
@login_required
def dashboard_whale():
    return render_template('whale_hunter.html')


# =========================
# TradingView Charts
# =========================
@web_routes.route('/dashboard/tradingview')
@login_required
def dashboard_tradingview():
    return render_template('tradingview.html')


# =========================
# Reports & Analytics
# =========================
@web_routes.route('/dashboard/reports')
@login_required
def dashboard_reports():
    return render_template('reports.html')


@web_routes.route('/dashboard/performance')
@login_required
def dashboard_performance():
    return render_template('performance.html')


# =========================
# Iran Market Pages
# =========================
@web_routes.route('/dashboard/iran-stocks')
@login_required
def dashboard_iran_stocks():
    return render_template('iran_stocks.html')


@web_routes.route('/dashboard/iran-csv')
@login_required
def dashboard_iran_csv():
    return render_template('iran_csv_analysis.html')


# =========================
# Crypto Page
# =========================
@web_routes.route('/dashboard/crypto-gainers')
@login_required
def dashboard_crypto_gainers():
    """Top gaining cryptocurrencies"""
    return render_template('crypto_gainers.html')


# =========================
# Admin Section
# =========================
@web_routes.route('/dashboard/admin/subscriptions')
@login_required
def admin_subscriptions():
    """Admin subscription management"""
    if not getattr(current_user, "is_admin", False):
        return redirect(url_for('web.dashboard_home'))

    return render_template('admin_subscriptions.html')