import React from 'react'
import { useLocation } from 'react-router-dom'
import DashboardSidebar from '../common/DashboardSidebar'
import { DashboardOutlined } from '@ant-design/icons'
import FilamentStockIcon from '../../Icons/FilamentStockIcon'
import PartStockIcon from '../../Icons/PartStockIcon'
import ProductStockIcon from '../../Icons/ProductStockIcon'
import StockEventIcon from '../../Icons/StockEventIcon'
import StockAuditIcon from '../../Icons/StockAuditIcon'

const items = [
  {
    key: 'overview',
    label: 'Overview',
    icon: <DashboardOutlined />,
    path: '/dashboard/inventory/overview'
  },
  { type: 'divider' },
  {
    key: 'filamentstocks',
    label: 'Filament Stocks',
    icon: <FilamentStockIcon />,
    path: '/dashboard/inventory/filamentstocks'
  },
  {
    key: 'partstocks',
    label: 'Part Stocks',
    icon: <PartStockIcon />,
    path: '/dashboard/inventory/partstocks'
  },
  {
    key: 'productstocks',
    label: 'Product Stocks',
    icon: <ProductStockIcon />,
    path: '/dashboard/inventory/productstocks'
  },
  { type: 'divider' },
  {
    key: 'stockevents',
    label: 'Stock Events',
    icon: <StockEventIcon />,
    path: '/dashboard/inventory/stockevents'
  },
  {
    key: 'stockaudits',
    label: 'Stock Audits',
    icon: <StockAuditIcon />,
    path: '/dashboard/inventory/stockaudits'
  }
]

const routeKeyMap = {
  '/dashboard/inventory/overview': 'overview',
  '/dashboard/inventory/filamentstocks': 'filamentstocks',
  '/dashboard/inventory/partstocks': 'partstocks',
  '/dashboard/inventory/productstocks': 'productstocks',
  '/dashboard/inventory/stockevents': 'stockevents',
  '/dashboard/inventory/stockaudits': 'stockaudits'
}

const InventorySidebar = (props) => {
  const location = useLocation()
  const selectedKey = (() => {
    const match = Object.keys(routeKeyMap).find((path) =>
      location.pathname.startsWith(path)
    )
    return match ? routeKeyMap[match] : 'filaments'
  })()

  return <DashboardSidebar items={items} selectedKey={selectedKey} {...props} />
}

export default InventorySidebar
