import mock from '../mock'

const orders = [
  {
    id: '12345',
    customerName: 'Lemmy Kilmister',
    customerEmail: 'lemmyk@email.com',
    paymentMethod: 'Cash',
    branch: 'New York',
    total: 20.98,
    dateTime: '10/03/2024, 15:16',
    status: 'On Road',
  },
  {
    id: '678910',
    customerName: 'Ozzy Osbourne',
    customerEmail: 'ozzyO@email.com',
    paymentMethod: 'Credit Card',
    branch: 'Washington',
    total: 60.98,
    dateTime: '10/03/2024, 15:16',
    status: 'Preparing',
  },
  {
    id: '111213',
    customerName: 'James Hetfield',
    customerEmail: 'jamesH@email.com',
    paymentMethod: 'Debit Card',
    branch: 'Texas',
    total: 12.99,
    dateTime: '10/03/2024, 15:16',
    status: 'Cancelled',
  },
  {
    id: '141516',
    customerName: 'Dave Mustaine',
    customerEmail: 'daved@email.com',
    paymentMethod: 'Cash',
    branch: 'Florida',
    total: 14.99,
    dateTime: '10/03/2024, 15:16',
    status: 'Delivered',
  },
  {
    id: '171819',
    customerName: 'Jason Newstead',
    customerEmail: 'jsonn@email.com',
    paymentMethod: 'Cash',
    branch: 'Florida',
    total: 14.99,
    dateTime: '10/03/2024, 15:16',
    status: 'On Road',
  },
  {
    id: '232425',
    customerName: 'John Doe',
    customerEmail: 'john.doe@example.com',
    paymentMethod: 'Credit Card',
    branch: 'California',
    total: 45.75,
    dateTime: '11/03/2024, 10:45',
    status: 'On Road',
  },
  {
    id: '262728',
    customerName: 'Jane Smith',
    customerEmail: 'jane.smith@example.com',
    paymentMethod: 'Cash',
    branch: 'Texas',
    total: 33.25,
    dateTime: '11/03/2024, 11:15',
    status: 'Preparing',
  },
  {
    id: '293031',
    customerName: 'Alex Johnson',
    customerEmail: 'alex.johnson@example.com',
    paymentMethod: 'Credit Card',
    branch: 'Florida',
    total: 22.50,
    dateTime: '11/03/2024, 12:30',
    status: 'Cancelled',
  },
  {
    id: '323334',
    customerName: 'Emily Brown',
    customerEmail: 'emily.brown@example.com',
    paymentMethod: 'Cash',
    branch: 'New York',
    total: 18.99,
    dateTime: '11/03/2024, 13:00',
    status: 'Delivered',
  },
  {
    id: '353637',
    customerName: 'Chris Miller',
    customerEmail: 'chris.miller@example.com',
    paymentMethod: 'Credit Card',
    branch: 'Washington',
    total: 40.00,
    dateTime: '11/03/2024, 14:15',
    status: 'On Road',
  },
  {
    id: '383940',
    customerName: 'Amanda White',
    customerEmail: 'amanda.white@example.com',
    paymentMethod: 'Cash',
    branch: 'California',
    total: 27.75,
    dateTime: '11/03/2024, 15:30',
    status: 'Preparing',
  },
  {
    id: '414243',
    customerName: 'Tom Johnson',
    customerEmail: 'tom.johnson@example.com',
    paymentMethod: 'Credit Card',
    branch: 'Florida',
    total: 32.99,
    dateTime: '11/03/2024, 16:00',
    status: 'Cancelled',
  },
  {
    id: '444546',
    customerName: 'Alice Anderson',
    customerEmail: 'alice.anderson@example.com',
    paymentMethod: 'Cash',
    branch: 'Texas',
    total: 15.49,
    dateTime: '11/03/2024, 17:15',
    status: 'Delivered',
  },
  {
    id: '474849',
    customerName: 'Bob Smith',
    customerEmail: 'bob.smith@example.com',
    paymentMethod: 'Credit Card',
    branch: 'Washington',
    total: 28.00,
    dateTime: '11/03/2024, 18:30',
    status: 'On Road',
  },
  {
    id: '505152',
    customerName: 'Eva Brown',
    customerEmail: 'eva.brown@example.com',
    paymentMethod: 'Cash',
    branch: 'New York',
    total: 19.99,
    dateTime: '11/03/2024, 19:00',
    status: 'Preparing',
  },
  {
    id: '535455',
    customerName: 'Mike White',
    customerEmail: 'mike.white@example.com',
    paymentMethod: 'Credit Card',
    branch: 'California',
    total: 33.50,
    dateTime: '11/03/2024, 20:15',
    status: 'Cancelled',
  },
  {
    id: '565758',
    customerName: 'Sophie Johnson',
    customerEmail: 'sophie.johnson@example.com',
    paymentMethod: 'Cash',
    branch: 'Texas',
    total: 25.99,
    dateTime: '11/03/2024, 21:30',
    status: 'Delivered',
  },
  {
    id: '596061',
    customerName: 'David Anderson',
    customerEmail: 'david.anderson@example.com',
    paymentMethod: 'Credit Card',
    branch: 'Washington',
    total: 38.75,
    dateTime: '11/03/2024, 22:00',
    status: 'On Road',
  },
  {
    id: '626364',
    customerName: 'Linda Smith',
    customerEmail: 'linda.smith@example.com',
    paymentMethod: 'Cash',
    branch: 'Florida',
    total: 20.49,
    dateTime: '11/03/2024, 23:15',
    status: 'Preparing',
  },
  {
    id: '656667',
    customerName: 'Mark Brown',
    customerEmail: 'mark.brown@example.com',
    paymentMethod: 'Credit Card',
    branch: 'New York',
    total: 29.00,
    dateTime: '11/04/2024, 00:30',
    status: 'Cancelled',
  },
  {
    id: '686970',
    customerName: 'Emma White',
    customerEmail: 'emma.white@example.com',
    paymentMethod: 'Cash',
    branch: 'California',
    total: 22.99,
    dateTime: '11/04/2024, 01:00',
    status: 'Delivered',
  },
  {
    id: '717273',
    customerName: 'Chris Johnson',
    customerEmail: 'chris.johnson@example.com',
    paymentMethod: 'Credit Card',
    branch: 'Texas',
    total: 36.50,
    dateTime: '11/04/2024, 02:15',
    status: 'On Road',
  },
  {
    id: '747576',
    customerName: 'Olivia Smith',
    customerEmail: 'olivia.smith@example.com',
    paymentMethod: 'Cash',
    branch: 'Florida',
    total: 24.75,
    dateTime: '11/04/2024, 03:30',
    status: 'Preparing',
  },
]

mock.onGet('/restaurant/orders').reply(request => {
  const { q = '', status = '', payMethod = '' } = request.params || { q: '', status: '', payMethod: '' }
  const queryLower = q.toLowerCase()

  let filterDb = orders

  filterDb = filterDb.filter(order => {
    return order.customerName.toLowerCase().includes(queryLower)
      || order.customerEmail.toLowerCase().includes(queryLower)
      || order.id.toLowerCase().includes(queryLower)
  })

  if (status) {
    filterDb = filterDb.filter(order => {
      return order.status.toLowerCase() === status.toLowerCase() // Add parentheses to toLowerCase
    })
  }

  if (payMethod) {
    filterDb = filterDb.filter(order => {
      return order.paymentMethod.toLowerCase() === payMethod.toLowerCase()
    })
  }

  return [200, { orders: filterDb }]
})
