import React from 'react'
import config from '../router.config'
import { Link } from 'react-router-dom'
import style from './style.module.css'
import { RouteProps } from '../@types'

function Slide(props: RouteProps) {
  let router = config.filter(item => item.navigation)
  let query = (item: any, currItem: any) : boolean => {
    if (!currItem) return false
    if (currItem === item) return true
    if (currItem.parent) {
      return query(item, currItem.parent)
    } else {
      return false
    }
  }
  const currItem = props.match && config.find(item => item.path === props.match.path)

          // <Redirect from="/" to="/gis" />

  return (
    <div className={style.slidelayer + ' ' + props.className}>
      {router.map(item => (
        <Link to={item.path} key={item.path} className={query(item, currItem) ? style.active : ''} >
          <img src={item.icon} />
          {item.title}
        </Link>
      ))}
    </div>
  )
}

export default Slide