import { STATUS_PENDING, STATUS_IN_PROGRESS, STATUS_STAGED, STATUS_COMPLETE, STATUS_ERROR, STATUS_CANCELED } from '../../../constants';
import { getFileId } from '../../../utils/uploads';
const STATUS_MAP = {
  [STATUS_PENDING]: 'pending',
  [STATUS_IN_PROGRESS]: 'uploading',
  [STATUS_STAGED]: 'staged',
  [STATUS_COMPLETE]: 'complete',
  [STATUS_ERROR]: 'error',
  [STATUS_CANCELED]: 'canceled'
};
export function getUploadItemKey(item, rootFolderId) {
  const fileItem = item;
  if (fileItem.file) {
    const fileWithOptions = fileItem.options ? {
      file: fileItem.file,
      options: fileItem.options
    } : fileItem.file;
    return getFileId(fileWithOptions, rootFolderId);
  }
  const folderId = item.options?.folderId ?? rootFolderId;
  const {
    uploadInitTimestamp
  } = item.options ?? {};
  if (uploadInitTimestamp === undefined) {
    return `${item.name}_${folderId}`;
  }
  return `${item.name}_${folderId}_${uploadInitTimestamp}`;
}
export function mapToModernizedUploadItem(item, rootFolderId) {
  const errorMessage = item.error ? item.error.message : undefined;
  return {
    id: getUploadItemKey(item, rootFolderId),
    name: item.name,
    extension: item.extension ?? '',
    progress: item.progress ?? 0,
    status: STATUS_MAP[item.status] ?? 'pending',
    isFolder: item.isFolder,
    errorMessage
  };
}
export function mapToModernizedUploadItems(items, rootFolderId) {
  return items.map(item => mapToModernizedUploadItem(item, rootFolderId));
}
//# sourceMappingURL=mapToModernizedUploadItem.js.map