import React from 'react'
import useTheme from '../use-theme'
import withDefaults from '../utils/with-defaults'

interface Props {
  className?: string
  title: string
}

const defaultProps = {
  className: ''
}

type NativeAttrs = Omit<React.HTMLAttributes<any>, keyof Props>
export type FlyoutMenuGroupProps = Props & typeof defaultProps & NativeAttrs

const FooterGroup: React.FC<React.PropsWithChildren<FlyoutMenuGroupProps>> = ({
  title,
  children,
  ...props
}) => {
  const theme = useTheme()
  return (
    <div {...props}>
      {title && <span className="group-title">{title}</span>}
      <ul className="group-list">
        {React.Children.map(
          children as [React.ReactElement<any>],
          (child: React.ReactElement<any>) => {
            return <li>{React.cloneElement(child)}</li>
          }
        )}
      </ul>
      <style jsx>{`
        div {
          width: 50%;
          margin-bottom: 24px;
        }
        .group-title {
          display: block;
          text-transform: uppercase;
          font-size: 0.75rem;
          line-height: ${theme.font.lineHeights.title};
          font-weight: ${theme.font.fontWeights.bold};
          letter-spacing: ${theme.font.letterSpacings.tracked};
          color: ${theme.palette.secondary};
        }
        ul {
          list-style: none;
          margin: 0;
          padding: 0;
        }
        li {
          margin-top: 8px;
        }
        li:before {
          display: none;
        }

        @media screen and (min-width: ${theme.layout.breakpointMobile}) {
          div {
            width: auto;
          }
        }
      `}</style>
    </div>
  )
}

export default withDefaults(FooterGroup, defaultProps)
