import Link from '@/core/components/elements/Link/Link'
import { useRouter } from 'next/router'

const Menu = () => {
  const router = useRouter()

  const routeStartWith = (route) => router.pathname.startsWith(route)

  return (
    <div className='grid grid-cols-1 bg-white border border-gray_r-6 rounded py-2 px-4'>
      <div className='mt-4 mb-1 font-medium'>Menu</div>
      <LinkItem href='/my/quotations' active={routeStartWith('/my/quotations')}>
        Daftar Quotation
      </LinkItem>
      <LinkItem href='/my/transactions' active={routeStartWith('/my/transactions')}>
        Daftar Transaksi
      </LinkItem>
      <LinkItem href='/my/invoices' active={routeStartWith('/my/invoices')}>
        Invoice & Faktur Pajak
      </LinkItem>
      <LinkItem href='/my/wishlist' active={routeStartWith('/my/wishlist')}>
        Wishlist
      </LinkItem>

      <div className='mt-4 mb-1 font-medium'>Pusat Bantuan</div>
      <LinkItem href='/'>Layanan Pelanggan</LinkItem>

      <div className='mt-4 mb-1 font-medium'>Pengaturan Akun</div>
      <LinkItem href='/my/address' active={routeStartWith('/my/address')}>
        Daftar Alamat
      </LinkItem>
      <LinkItem href='/my/profile' active={routeStartWith('/my/profile')}>
        Profil Saya
      </LinkItem>
      <button type='button' className='text-gray_r-12/80 p-2 text-left'>
        Keluar Akun
      </button>
    </div>
  )
}

const LinkItem = ({ children, ...props }) => (
  <Link
    {...props}
    className={`!text-gray_r-12/80 !font-normal p-2 rounded ${
      props.active == true ? 'bg-gray_r-3' : ''
    }`}
  >
    {children}
  </Link>
)

export default Menu
