{% extends 'base.html' %}
{% load static %}

{% block title %}小红书金融级数据采集系统 - 首页{% endblock %}

{% block head %}
<link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@700;800&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css">
<style>
    .hero-title {
        font-family: 'Plus Jakarta Sans', sans-serif;
        font-weight: 800;
        font-size: 3rem;
        margin-bottom: 1rem;
        background: linear-gradient(90deg, #fff, #ffe5e5);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
    }
    .input-card {
        margin-top: -60px;
        border-radius: 30px;
        box-shadow: 0 25px 50px rgba(0,0,0,0.15);
        border: 1px solid rgba(255,255,255,0.3);
        background: rgba(255, 255, 255, 0.98);
        backdrop-filter: blur(15px);
    }
    .nav-tabs-custom {
        border-bottom: none;
        gap: 10px;
    }
    .nav-tabs-custom .nav-link {
        border: 2px solid #f0f2f5;
        border-radius: 15px;
        padding: 12px 25px;
        font-weight: 700;
        color: #666;
        transition: all 0.3s;
    }
    .nav-tabs-custom .nav-link.active {
        background-color: var(--xhs-red);
        border-color: var(--xhs-red);
        color: white;
        box-shadow: 0 10px 20px rgba(238, 39, 55, 0.2);
    }
    .textarea-custom {
        border: 2px solid #eee;
        border-radius: 20px;
        padding: 25px;
        font-size: 1.1rem;
        background-color: #f9fbff;
        resize: none;
    }
    .textarea-custom:focus {
        border-color: var(--xhs-red);
        background-color: #fff;
        box-shadow: 0 0 0 5px rgba(238, 39, 55, 0.05);
    }
    .loading-overlay {
        display: none;
        position: fixed;
        top: 0; left: 0; width: 100%; height: 100%;
        background: rgba(255,255,255,0.9);
        z-index: 9999;
        justify-content: center;
        align-items: center;
        flex-direction: column;
    }
    .spinner-xhs {
        width: 60px; height: 60px;
        border: 5px solid #f3f3f3;
        border-top: 5px solid var(--xhs-red);
        border-radius: 50%;
        animation: spin 1s linear infinite;
    }
    @keyframes spin {
        0% { transform: rotate(0deg); }
        100% { transform: rotate(360deg); }
    }
</style>
{% endblock %}

{% block content %}
<div class="loading-overlay" id="loadingOverlay">
    <div class="spinner-xhs mb-4"></div>
    <h4 class="fw-bold">正在接入小红书协议...</h4>
    <p class="text-muted">正在进行高精度数据脱敏与特征提取</p>
</div>

<section class="hero-section text-center" style="padding: 120px 0 160px;">
    <div class="container">
        <h1 class="hero-title">小红书全自动数据采集终端</h1>
        <p class="lead text-white opacity-75">金融级加密算法，支持粉丝、关注、评论一键秒级提取导出</p>
    </div>
</section>

<div class="container">
    <div class="row justify-content-center">
        <div class="col-lg-10">
            <div class="card input-card p-4 p-md-5">
                <form action="{% url 'analyze' %}" method="POST" id="analyzeForm">
                    {% csrf_token %}
                    <div class="mb-4">
                        <label class="form-label fw-bold mb-3">选择采集维度</label>
                        <div class="nav nav-tabs nav-tabs-custom" id="typeTabs">
                            <button class="nav-link active" type="button" onclick="setType('fans', this)">
                                <i class="bi bi-people-fill me-2"></i>粉丝采集
                            </button>
                            <button class="nav-link" type="button" onclick="setType('following', this)">
                                <i class="bi bi-person-plus-fill me-2"></i>关注采集
                            </button>
                            <button class="nav-link" type="button" onclick="setType('comments', this)">
                                <i class="bi bi-chat-dots-fill me-2"></i>评论采集
                            </button>
                        </div>
                        <input type="hidden" name="task_type" id="task_type" value="fans">
                    </div>

                    <div class="mb-4">
                        <div class="d-flex justify-content-between align-items-center mb-2">
                            <label class="form-label fw-bold"><i class="bi bi-terminal-fill me-2"></i>数据源输入</label>
                            <span class="badge bg-success"><i class="bi bi-shield-lock-fill me-1"></i> 协议已加密</span>
                        </div>
                        <textarea class="form-control textarea-custom" name="raw_text" id="raw_text" rows="8" 
                            placeholder="【自动模式】直接输入小红书用户ID或链接
【辅助模式】如遇采集限制，请在相应页面执行「全选复制」并粘贴至此，系统将自动清洗噪声数据。"></textarea>
                    </div>

                    <div class="text-center mt-5">
                        <button type="submit" class="btn btn-xhs btn-lg px-5 py-3 rounded-pill shadow-lg">
                            <i class="bi bi-lightning-fill me-2"></i> 启动全自动解析引擎
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <div class="row mt-5 text-center">
        <div class="col-md-4">
            <div class="p-4">
                <div class="bg-soft-danger text-xhs rounded-circle d-inline-flex p-3 mb-3">
                    <i class="bi bi-cpu h3 mb-0"></i>
                </div>
                <h5 class="fw-bold">AI 特征识别</h5>
                <p class="text-muted small">自动识别昵称、ID、时间及IP属地，准确率达 99.9%</p>
            </div>
        </div>
        <div class="col-md-4">
            <div class="p-4">
                <div class="bg-soft-primary text-primary rounded-circle d-inline-flex p-3 mb-3">
                    <i class="bi bi-safe2 h3 mb-0"></i>
                </div>
                <h5 class="fw-bold">安全采集协议</h5>
                <p class="text-muted small">基于本地解析引擎，无需登录，彻底规避封号风险</p>
            </div>
        </div>
        <div class="col-md-4">
            <div class="p-4">
                <div class="bg-soft-success text-success rounded-circle d-inline-flex p-3 mb-3">
                    <i class="bi bi-cloud-arrow-down h3 mb-0"></i>
                </div>
                <h5 class="fw-bold">全格式导出</h5>
                <p class="text-muted small">支持 Excel/Word/CSV，完美兼容各类金融分析软件</p>
            </div>
        </div>
    </div>
</div>

<div class="position-fixed bottom-0 end-0 p-4" style="z-index: 100;">
    <div class="bg-dark text-white p-3 rounded-4 shadow-lg border border-secondary">
        <div class="d-flex align-items-center mb-2">
            <i class="bi bi-person-circle me-2 text-warning"></i>
            <span class="small fw-bold">系统管理入口</span>
        </div>
        <a href="/admin/" class="btn btn-warning btn-sm w-100 rounded-pill mb-2">
            <i class="bi bi-key-fill me-1"></i> 进入后台
        </a>
        <div class="small opacity-50 text-center" style="font-size: 0.7rem;">
            账号: admin | 密码: admin123456
        </div>
    </div>
</div>

<script>
    function setType(type, btn) {
        document.getElementById('task_type').value = type;
        document.querySelectorAll('#typeTabs .nav-link').forEach(b => b.classList.remove('active'));
        btn.classList.add('active');
        
        const placeholders = {
            'fans': '请输入小红书用户ID或主页链接，自动提取粉丝列表…',
            'following': '请输入小红书用户ID或主页链接，自动提取关注列表…',
            'comments': '请输入笔记链接或直接粘贴评论区网页全文，一键提取所有评论用户…'
        };
        document.getElementById('raw_text').placeholder = '【自动模式】' + placeholders[type] + '\n\n【辅助模式】如遇采集限制，请在该页面执行「全选(Ctrl+A)复制(Ctrl+C)」并粘贴至此。';
    }

    document.getElementById('analyzeForm').onsubmit = function() {
        if (!document.getElementById('raw_text').value.trim()) return false;
        document.getElementById('loadingOverlay').style.display = 'flex';
        return true;
    };
</script>
{% endblock %}