File size: 11,740 Bytes
36d488d
 
 
 
 
 
 
 
d816aa5
 
36d488d
 
d816aa5
 
 
 
36d488d
d816aa5
36d488d
d816aa5
36d488d
 
d816aa5
36d488d
d816aa5
36d488d
d816aa5
 
36d488d
 
d816aa5
 
 
 
36d488d
 
d816aa5
 
36d488d
d816aa5
 
 
 
 
 
36d488d
 
d816aa5
 
 
 
 
 
36d488d
d816aa5
 
 
36d488d
d816aa5
 
36d488d
d816aa5
 
36d488d
d816aa5
 
36d488d
d816aa5
36d488d
d816aa5
 
36d488d
d816aa5
 
 
36d488d
 
 
 
d816aa5
36d488d
 
d816aa5
 
36d488d
d816aa5
 
 
36d488d
 
 
d816aa5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36d488d
d816aa5
 
 
36d488d
 
 
d816aa5
 
 
 
 
 
 
 
 
 
 
 
 
 
36d488d
 
 
 
 
 
d816aa5
36d488d
 
 
 
 
d816aa5
36d488d
 
 
 
d816aa5
 
 
 
36d488d
28f892f
 
 
 
 
36d488d
 
 
 
 
28f892f
 
 
 
 
 
 
 
 
 
 
 
 
36d488d
 
 
 
d816aa5
 
 
 
36d488d
d816aa5
36d488d
 
 
 
 
 
 
 
d816aa5
36d488d
d816aa5
36d488d
 
 
 
 
 
 
 
 
 
d816aa5
36d488d
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Admin Control Center — ViralFlow AI</title>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Outfit:wght@400;600;800;900&family=Plus+Jakarta+Sans:wght@300;400;600;700&display=swap" rel="stylesheet">
    <script src="https://unpkg.com/lucide@latest"></script>
    <style>
        :root {
            --bg: #020617;
            --surface: rgba(15, 23, 42, 0.6);
            --accent: #6366f1;
            --success: #10b981;
            --danger: #ef4444;
            --text: #f8fafc;
            --text-dim: #94a3b8;
            --glass-border: rgba(255, 255, 255, 0.08);
        }

        * { box-sizing: border-box; transition: all 0.3s ease; }
        body {
            background: radial-gradient(circle at 50% -20%, #1e1b4b 0%, var(--bg) 80%);
            color: var(--text);
            font-family: 'Plus Jakarta Sans', sans-serif;
            margin: 0; padding: 40px;
        }

        .glass-panel {
            background: var(--surface); backdrop-filter: blur(20px);
            border-radius: 32px; border: 1px solid var(--glass-border);
            padding: 40px; margin-bottom: 30px;
        }

        .header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 40px; }
        h1 { font-family: 'Outfit', sans-serif; font-size: 2.2rem; font-weight: 900; margin: 0; }

        .pricing-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 20px; }
        .input-group { margin-bottom: 20px; }
        label { display: block; margin-bottom: 10px; font-size: 0.8rem; font-weight: 800; color: var(--text-dim); text-transform: uppercase; }
        input {
            width: 100%; background: rgba(0,0,0,0.3); border: 1px solid var(--glass-border);
            padding: 15px 20px; border-radius: 15px; color: #fff; outline: none;
        }

        /* --- Toggle Switch --- */
        .switch { position: relative; display: inline-block; width: 60px; height: 34px; }
        .switch input { opacity: 0; width: 0; height: 0; }
        .slider {
            position: absolute; cursor: pointer; inset: 0; background-color: #334155;
            transition: .4s; border-radius: 34px;
        }
        .slider:before {
            position: absolute; content: ""; height: 26px; width: 26px; left: 4px; bottom: 4px;
            background-color: white; transition: .4s; border-radius: 50%;
        }
        input:checked + .slider { background-color: var(--accent); }
        input:checked + .slider:before { transform: translateX(26px); }

        .admin-table {
            width: 100%; border-collapse: collapse; margin-top: 30px;
        }
        th { text-align: left; padding: 20px; color: var(--text-dim); font-size: 0.8rem; text-transform: uppercase; border-bottom: 1px solid var(--glass-border); }
        td { padding: 20px; border-bottom: 1px solid var(--glass-border); }

        .badge { padding: 6px 14px; border-radius: 20px; font-size: 0.75rem; font-weight: 900; }
        .badge-free { background: rgba(148, 163, 184, 0.1); color: #94a3b8; }
        .badge-premium { background: rgba(129, 140, 248, 0.1); color: #818cf8; }
        .badge-ultra { background: rgba(245, 158, 11, 0.1); color: #f59e0b; }

        .btn-primary {
            cursor: pointer; border: none; padding: 14px 28px; border-radius: 18px;
            background: var(--accent); color: #fff; font-weight: 800;
        }
    </style>
</head>
<body>

    <div class="header">
        <div>
            <a href="index.html" style="color: var(--text-dim); text-decoration: none; font-size: 0.9rem; font-weight: 700;">← Exit Admin</a>
            <h1>Revenue Control Center 💰</h1>
        </div>
        <div style="display: flex; gap: 40px;">
            <div style="text-align: center;"><div style="font-size: 0.7rem; color: var(--text-dim);">USERS</div><div id="stat-users" style="font-size: 1.8rem; font-weight: 900;">0</div></div>
            <div style="text-align: center;"><div style="font-size: 0.7rem; color: var(--text-dim);">CHANNELS</div><div id="stat-active" style="font-size: 1.8rem; font-weight: 900; color: var(--success);">0</div></div>
        </div>
    </div>

    <div class="glass-panel">
        <h3 style="margin-top: 0; font-family: 'Outfit', sans-serif;">Advanced Pricing Engine</h3>
        
        <div class="pricing-grid">
            <div class="input-group"><label>Monthly Sale Price (₹)</label><input type="number" id="price-monthly"></div>
            <div class="input-group"><label>Monthly Old Price (₹)</label><input type="number" id="old-price-monthly"></div>
            <div class="input-group"><label>Yearly Sale Price (₹)</label><input type="number" id="price-yearly"></div>
            <div class="input-group"><label>Yearly Old Price (₹)</label><input type="number" id="old-price-yearly"></div>
        </div>

        <div class="pricing-grid" style="margin-top: 20px;">
            <div class="input-group"><label>Discount Percent (%)</label><input type="number" id="discount-pct"></div>
            <div class="input-group"><label>Sale Badge Text</label><input type="text" id="sale-text"></div>
            <div class="input-group">
                <label>Monthly Sale Active</label>
                <label class="switch"><input type="checkbox" id="m-sale-active"><span class="slider"></span></label>
            </div>
            <div class="input-group">
                <label>Yearly Sale Active</label>
                <label class="switch"><input type="checkbox" id="y-sale-active"><span class="slider"></span></label>
            </div>
        </div>

        <div style="text-align: right; margin-top: 20px;">
            <button class="btn-primary" onclick="savePricing()">Apply Global Price Changes 🚀</button>
        </div>
    </div>

    <div class="glass-panel" style="padding: 0; overflow: hidden;">
        <table class="admin-table">
            <thead>
                <tr>
                    <th>Agency Owner</th>
                    <th>YouTube Channel</th>
                    <th>Current Tier</th>
                    <th>Automation Status</th>
                    <th>Actions</th>
                </tr>
            </thead>
            <tbody id="user-list"></tbody>
        </table>
    </div>

    <script>
        const authToken = localStorage.getItem('saas_token');

        async function loadAdminData() {
            if (!authToken) { window.location.href = 'index.html'; return; }
            
            const statsRes = await fetch('/api/admin/global-stats', { headers: { 'Authorization': `Bearer ${authToken}` } });
            const stats = await statsRes.json();
            document.getElementById('stat-users').innerText = stats.totalUsers || 0;
            document.getElementById('stat-active').innerText = stats.activeChannels || 0;

            const res = await fetch('/api/admin/users', { headers: { 'Authorization': `Bearer ${authToken}` } });
            const users = await res.json();
            const list = document.getElementById('user-list');
            list.innerHTML = users.map(u => `
                <tr>
                    <td style="font-weight: 800;">${u.email}</td>
                    <td><div style="font-weight: 700;">${u.channels?.[0]?.channel_name || '❌ Unlinked'}</div></td>
                    <td><span class="badge ${u.plan === 'ultra' ? 'badge-ultra' : (u.plan === 'premium' ? 'badge-premium' : 'badge-free')}">${u.plan?.toUpperCase() || 'FREE'}</span></td>
                    <td><div style="display: flex; align-items: center; gap: 8px;"><div style="width: 10px; height: 10px; border-radius: 50%; background: ${u.channels?.[0]?.is_active ? 'var(--success)' : '#475569'};"></div>${u.channels?.[0]?.is_active ? 'Active' : 'Offline'}</div></td>
                    <td>
                        <div style="display:flex; gap:8px;">
                            <button onclick="adminAction('${u.id}', 'ultra')" style="background: rgba(245, 158, 11, 0.1); color: #f59e0b; border: 1px solid #f59e0b; padding: 6px 12px; border-radius: 10px; cursor: pointer; font-weight: 800; font-size: 0.7rem;">ULTRA</button>
                            <button onclick="adminAction('${u.id}', 'pro')" style="background: rgba(99, 102, 241, 0.1); color: var(--accent); border: 1px solid var(--accent); padding: 6px 12px; border-radius: 10px; cursor: pointer; font-weight: 800; font-size: 0.7rem;">PRO</button>
                            <button onclick="adminAction('${u.id}', 'free')" style="background: rgba(255, 255, 255, 0.05); color: #fff; border: 1px solid var(--glass-border); padding: 6px 12px; border-radius: 10px; cursor: pointer; font-weight: 800; font-size: 0.7rem;">FREE</button>
                        </div>
                    </td>
                </tr>
            `).join('');
        }

        async function adminAction(userId, plan) {
            if (!confirm(`Change user to ${plan.toUpperCase()}?`)) return;
            const res = await fetch('/api/admin/update-plan', {
                method: 'POST',
                headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${authToken}` },
                body: JSON.stringify({ userId, plan })
            });
            if (res.ok) {
                alert("User Plan Updated! 🚀");
                loadAdminData();
            }
        }

        async function loadAdminPricing() {
            const res = await fetch('/api/platform/pricing');
            const p = await res.json();
            if (p) {
                document.getElementById('price-monthly').value = p.pro_monthly || 0;
                document.getElementById('old-price-monthly').value = p.old_pro_monthly || 0;
                document.getElementById('price-yearly').value = p.pro_yearly || 0;
                document.getElementById('old-price-yearly').value = p.old_pro_yearly || 0;
                document.getElementById('discount-pct').value = p.discount_percent || 0;
                document.getElementById('sale-text').value = p.discount_text || "";
                document.getElementById('m-sale-active').checked = p.m_discount_active || false;
                document.getElementById('y-sale-active').checked = p.y_discount_active || false;
            }
        }

        async function savePricing() {
            const pricing = {
                pro_monthly: parseInt(document.getElementById('price-monthly').value),
                old_pro_monthly: parseInt(document.getElementById('old-price-monthly').value),
                pro_yearly: parseInt(document.getElementById('price-yearly').value),
                old_pro_yearly: parseInt(document.getElementById('old-price-yearly').value),
                discount_percent: parseInt(document.getElementById('discount-pct').value),
                discount_text: document.getElementById('sale-text').value,
                m_discount_active: document.getElementById('m-sale-active').checked,
                y_discount_active: document.getElementById('y-sale-active').checked
            };
            const res = await fetch('/api/admin/pricing', {
                method: 'POST',
                headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${authToken}` },
                body: JSON.stringify({ pricing })
            });
            if (res.ok) alert("Global Pricing Engine Updated! ⚡");
        }

        loadAdminPricing();
        loadAdminData();
    </script>
</body>
</html>