/* Thẻ affiliate, Zalo và credit trong profile học viên. */ function ProfileBenefitCards({ data, form, credits, setCredits, go }) { const [affIdx, setAffIdx] = React.useState(0); const [copied, setCopied] = React.useState(false); const [targetCourse, setTargetCourse] = React.useState("N1"); const [exchange, setExchange] = React.useState({ accept: false, quote: null, msg: "" }); const aff = (data && data.affiliate) || {}; const z = (data && data.zalo) || {}; const links = aff.course_links || []; const currentAffLink = () => (links[affIdx] && links[affIdx].link) || aff.link || ""; const copyAffiliate = () => { const done = () => { setCopied(true); setTimeout(() => setCopied(false), 1500); }; try { navigator.clipboard.writeText(currentAffLink()).then(done).catch(done); } catch (e) { done(); } }; const quoteExchange = async () => { const r = await (window.AG && AG.exchangeQuote ? AG.exchangeQuote(targetCourse) : { ok: false }); setExchange(Object.assign({}, exchange, { quote: r, msg: r.ok ? "Đã tính phần cần bù." : (r.msg || "Chưa tính được.") })); }; const redeemExchange = async () => { const r = await (window.AG && AG.exchangeRedeem ? AG.exchangeRedeem({ target_course: targetCourse, accept_no_refund: exchange.accept, idempotency_key: "ui-" + targetCourse + "-" + Date.now() }) : { ok: false }); setExchange(Object.assign({}, exchange, { msg: r.msg || (r.ok ? "Đã gửi yêu cầu đổi." : "Chưa gửi được.") })); if (r.ok && AG.credits) AG.credits().then(setCredits).catch(() => {}); }; return
Tên Zalo: {z.sender_name || form.zalo_name || "Chưa xác nhận"}
Số Zalo: {form.zalo_phone || "Chưa nhập"}
Group: {z.group_name || "Chưa liên kết group"}
Mã xác nhận: {z.code || "Bấm lưu hồ sơ hoặc mở mục Zalo để lấy mã"}
Mã: {aff.code || "Đang tạo"}
Mức: {aff.rate || 20}% · {aff.tier || "Khởi động"}
Doanh số: {scFmtMoney(aff.revenue)} · Hoa hồng: {scFmtMoney(aff.commission)}
{links.length > 0 && }Số dư: {scFmtMoney((credits && credits.balance) || 0)} credit
{exchange.quote && exchange.quote.ok &&Cần bù: {scFmtMoney(exchange.quote.cash_due)} · Dùng: {scFmtMoney(exchange.quote.credits_applied)}
} {exchange.msg &&{exchange.msg}
}