admin/features/events/eventCapacity.ts
alisaza e1eaf5eff5 feat: initial ghabilee-admin backoffice app
Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js
app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
2026-09-05 13:12:59 +03:30

26 lines
924 B
TypeScript

export type EventCapacityTone = 'neutral' | 'warning' | 'danger'
export function occupiedSeatCount(bookedCount: number, reservedCapacity: number): number {
return bookedCount + reservedCapacity
}
export function remainingSeatCount(capacity: number, bookedCount: number, reservedCapacity = 0): number {
return Math.max(0, capacity - occupiedSeatCount(bookedCount, reservedCapacity))
}
export function isOccupancyFull(capacity: number, bookedCount: number, reservedCapacity = 0): boolean {
return occupiedSeatCount(bookedCount, reservedCapacity) >= capacity
}
/** Badge tone from remaining / total: red <20%, orange <50%, otherwise gray. */
export function capacityToneFromRemaining(remaining: number, capacity: number): EventCapacityTone {
if (capacity <= 0) return 'danger'
const ratio = remaining / capacity
if (ratio < 0.2) return 'danger'
if (ratio < 0.5) return 'warning'
return 'neutral'
}