diff --git a/src/routes/calculate/[id]/share/+page.svelte b/src/routes/calculate/[id]/share/+page.svelte index 86f4c53..1646310 100644 --- a/src/routes/calculate/[id]/share/+page.svelte +++ b/src/routes/calculate/[id]/share/+page.svelte @@ -11,6 +11,43 @@ const order = { FOH: 0, Bar: 1, Kitchen: 2 } as Record; return (order[a.role] ?? 9) - (order[b.role] ?? 9) || a.name.localeCompare(b.name); })); + + let copyFeedback = $state(''); + + function buildShareText(): string { + const lines: string[] = [ + `TipSplit — ${c.date} · ${c.shift} Shift`, + '', + `Gross Tips: $${formatCents(c.gross_tips_cents)}`, + `CC Fees: −$${formatCents(c.cc_fees_cents)}`, + `Kitchen Pool: $${formatCents(c.kitchen_pool_cents)}`, + ]; + if (c.bar_pool_cents > 0) { + lines.push(`Bar Pool: $${formatCents(c.bar_pool_cents)}`); + } + lines.push(''); + for (const d of sorted) { + lines.push(`${d.name} (${d.role}): $${formatCents(d.total_cents)}`); + } + const total = dists.reduce((s, d) => s + d.total_cents, 0); + lines.push('', `Total Distributed: $${formatCents(total)}`); + return lines.join('\n'); + } + + async function shareViaMessenger() { + const text = buildShareText(); + if (typeof navigator !== 'undefined' && navigator.share) { + try { + await navigator.share({ title: 'TipSplit', text }); + } catch { + // user cancelled or share failed — do nothing + } + } else { + await navigator.clipboard.writeText(text); + copyFeedback = 'Copied!'; + setTimeout(() => { copyFeedback = ''; }, 2000); + } + } @@ -67,6 +104,16 @@ + +
+ +