// The order shots appear in on the project page's Shots tab. Shared with the // shot detail page so its previous/next navigation walks the same list. type OrderableShot = { episode?: string | null; scene: string; shotNumber: number; shotGroup?: { name: string } | null; }; export function sortShotsForList(shots: T[], projectType: string): T[] { // Episodic: episode → scene → shotNumber if (projectType === "EPISODIC") { return [...shots].sort((a, b) => { const ea = a.episode ?? ""; const eb = b.episode ?? ""; if (ea !== eb) return ea.localeCompare(eb, undefined, { numeric: true }); if (a.scene !== b.scene) return a.scene.localeCompare(b.scene, undefined, { numeric: true }); return a.shotNumber - b.shotNumber; }); } // Standard with custom groups: group → scene → shotNumber, ungrouped last if (projectType === "STANDARD" && shots.some((s) => s.shotGroup)) { return [...shots].sort((a, b) => { const ga = a.shotGroup?.name ?? "￿"; const gb = b.shotGroup?.name ?? "￿"; if (ga !== gb) return ga.localeCompare(gb, undefined, { numeric: true }); if (a.scene !== b.scene) return a.scene.localeCompare(b.scene, undefined, { numeric: true }); return a.shotNumber - b.shotNumber; }); } // Otherwise the list keeps the query's createdAt order return shots; }