/** List of actions sorted chronologically */
export const STATUS = Object.freeze({
  CREATED: 'CREATED',
  SCHEDULED: 'SCHEDULED',
  READY: 'READY',
  APPROVED: 'APPROVED',
  REFUSED: 'REFUSED',
  INPUT: 'INPUT',
  SENT: 'SENT',
  STORES: 'STORES',
  BEAMLINE: 'BEAMLINE',
  BACK_STORES: 'BACK_STORES',
  BACK_USER: 'BACK_USER',
  DESTROYED: 'DESTROYED',
});

export const STATUS_DEFS = {
  [STATUS.CREATED]: {
    desc: 'Parcel has been created',
    label: 'CREATED',
    icon: 'new-window',
    editable: true,
    inactiveParcel: false,
    sendable: false,
    action: { desc: 'Create parcel' },
    allowedActions: () => [STATUS.SCHEDULED],
  },
  [STATUS.SCHEDULED]: {
    desc: 'Parcel has been associated with an experimental session',
    label: 'SCHEDULED',
    icon: 'calendar',
    editable: true,
    inactiveParcel: false,
    sendable: false,
    action: { desc: 'Associate the parcel with an experimental session' },
    allowedActions: (parcel) => (parcel.items.length > 0 ? [STATUS.READY] : []),
  },
  [STATUS.READY]: {
    desc: 'Samples have been declared and waiting for safety validation',
    label: 'READY FOR SAFETY CHECK',
    icon: 'check',
    editable: false,
    inactiveParcel: false,
    sendable: false,
    action: {
      desc: 'Request safety approval for this parcel',
      requiresInput: true,
    },
    allowedActions: () => [STATUS.APPROVED, STATUS.REFUSED, STATUS.INPUT],
  },
  [STATUS.APPROVED]: {
    desc: 'Approved by safety group',
    label: 'APPROVED',
    icon: 'ok-circle',
    editable: false,
    inactiveParcel: false,
    sendable: true,
    action: { desc: 'Approve the parcel', safety: true, requiresInput: true },
    allowedActions: () => [STATUS.SENT],
  },
  [STATUS.REFUSED]: {
    desc: 'Refused by safety group',
    label: 'REFUSED',
    icon: 'ban-circle',
    editable: true,
    inactiveParcel: false,
    sendable: false,
    action: { desc: 'Refuse the parcel', safety: true, requiresInput: true },
    allowedActions: (parcel) => (parcel.items.length > 0 ? [STATUS.READY] : []),
  },
  [STATUS.INPUT]: {
    desc: 'Safety group needs more information',
    label: 'NEEDS MORE INFO',
    icon: 'comment',
    editable: true,
    inactiveParcel: false,
    sendable: false,
    action: {
      desc: 'Ask user for more information',
      safety: true,
      requiresInput: true,
    },
    allowedActions: (parcel) => (parcel.items.length > 0 ? [STATUS.READY] : []),
  },
  [STATUS.SENT]: {
    desc: 'Sent to facility',
    label: 'SENT',
    icon: 'envelope',
    editable: false,
    inactiveParcel: false,
    sendable: true,
    action: { desc: 'Notify that the parcel has been shipped to the facility' },
    allowedActions: () => [STATUS.STORES],
  },
  [STATUS.STORES]: {
    desc: 'Arrived at facility stores',
    label: 'STORES',
    icon: 'home',
    editable: false,
    inactiveParcel: false,
    sendable: true,
    action: {
      desc: 'Notify that the parcel has arrived at the stores',
      safety: true,
    },
    allowedActions: () => [STATUS.BEAMLINE],
  },
  [STATUS.BEAMLINE]: {
    desc: 'Parcel has arrived to the beamline',
    label: 'BEAMLINE',
    icon: 'thumbs-up',
    editable: false,
    inactiveParcel: false,
    sendable: true,
    action: { desc: 'Notify that the parcel has arrived at the beamline' },
    allowedActions: () => [STATUS.BACK_STORES],
  },
  [STATUS.BACK_STORES]: {
    desc: 'Back to facility stores',
    label: 'BACK IN STORES',
    icon: 'home',
    editable: false,
    inactiveParcel: true,
    sendable: true,
    action: {
      desc: 'Notify that the parcel has been returned to the stores',
      safety: true,
    },
    allowedActions: (parcel) => [
      parcel.returnAddress ? STATUS.BACK_USER : STATUS.DESTROYED,
    ],
  },
  [STATUS.BACK_USER]: {
    desc: 'Sent back to return address',
    label: 'SENT BACK TO USER',
    icon: 'user',
    editable: false,
    inactiveParcel: true,
    sendable: true,
    action: {
      desc: 'Notify that the parcel has been shipped back to the user',
    },
    allowedActions: () => [],
  },
  [STATUS.DESTROYED]: {
    desc: 'Parcel destroyed',
    label: 'DESTROYED',
    icon: 'remove-circle',
    editable: false,
    inactiveParcel: true,
    sendable: true,
    action: { desc: 'Notify that the parcel has been destroyed', safety: true },
    allowedActions: () => [],
  },
};
