import { DEFAULT_COLORS } from '../composables/useAutoGroup' import type { SampleGroup } from '../types' export type ColorEdit = | { kind: 'single'; name: string } | { kind: 'family'; names: string[] } export const DEFAULT_COLOR_PICKER_SEED = '#3B82F6' export const SAMPLE_GROUP_COLOR_OPTIONS = DEFAULT_COLORS.slice(0, 5) export function applySampleGroupColorEdit( groups: SampleGroup[], edit: ColorEdit, color: string, ): SampleGroup[] { const targets = edit.kind === 'family' ? new Set(edit.names) : new Set([edit.name]) return groups.map(group => targets.has(group.name) ? { ...group, color } : group, ) } export function getSampleGroupColorEditSeed( edit: ColorEdit | null, getGroupColor: (groupName: string) => string, ): string { if (!edit) return DEFAULT_COLOR_PICKER_SEED return getGroupColor(edit.kind === 'family' ? edit.names[0] : edit.name) } export function pickUnusedSampleGroupColor(groups: SampleGroup[]): string { const usedColors = new Set(groups.map(group => group.color)) return DEFAULT_COLORS.find(color => !usedColors.has(color)) || DEFAULT_COLORS[0] } export function createSampleGroup( name: string, existingGroups: SampleGroup[], color?: string, ): SampleGroup | null { const trimmedName = name.trim() if (!trimmedName) return null return { name: trimmedName, color: color || pickUnusedSampleGroupColor(existingGroups), samples: [], } }