import { Entry } from 'har-format'

export interface SortableEntry extends Entry {
  timestamp: number
  id: string
}

/**
 * @returns The copy of the entires array with a shallow copy of each entry.
 */
export function sortEntires(entries: Entry[]): SortableEntry[] {
  const cp = entries.map((entry) => {
    const d = new Date(entry.startedDateTime)
    return {
      ...entry,
      timestamp: d.getTime(),
    } as SortableEntry
  })
  cp.sort((a, b) => a.timestamp - b.timestamp)
  return cp
}
