/* global React, Icon, Eyebrow, Badge, Button, api */
const { useState: useStateEO, useEffect: useEffectEO } = React;
function EarningsOverview({ onSubmit }){
const [clips, setClips] = useStateEO([]);
const [balance, setBalance] = useStateEO(null);
const [payouts, setPayouts] = useStateEO([]);
const [loading, setLoading] = useStateEO(true);
useEffectEO(() => {
let mounted = true;
(async () => {
const [c, b, p] = await Promise.all([api.listMyClips(), api.getMyBalance(), api.listMyPayouts()]);
if (!mounted) return;
setClips(c.error ? [] : c.data);
setBalance(b.error ? null : b.data);
setPayouts(p.error ? [] : p.data);
setLoading(false);
})();
return () => { mounted = false; };
}, []);
const approved = clips.filter(c => c.status === "approved");
const pending = clips.filter(c => c.status === "pending");
const totalViews = clips.reduce((s,c) => s + (c.views || 0), 0);
const earnedThisWeek = approved
.filter(c => c.reviewed_at && (Date.now() - new Date(c.reviewed_at).getTime()) < 7*86400_000)
.reduce((s,c) => s + Number(c.earned||0), 0);
const lifetimeEarned = approved.reduce((s,c) => s + Number(c.earned||0), 0);
const available = balance ? Number(balance.available_balance) : 0;
const profile_method = balance && balance.method;
const lastPaid = payouts.find(p => p.status === "paid");
const nextPayoutLine = available >= 20
? "Withdrawable now — request below"
: `$${(20 - available).toFixed(2)} to your $20 cashout floor`;
if (loading) return
| {h} | ))}|||||
|---|---|---|---|---|---|
|
{shortUrl(c.url)}
{c.platform || "other"} · {timeAgo(c.submitted_at)}
|
{camp.name || "—"} |
{c.rejection_reason}
)}
|
{(c.views||0).toLocaleString()} | 0?"#047857":"#6E6D66"}}>{c.earned>0?`$${Number(c.earned).toFixed(2)}`:"—"} |
|