import React from 'react'
import { NormalTypes } from '../utils/prop-types'
import DotIcon from './icon'

interface Props {
  type?: NormalTypes
  className?: string
}

const defaultProps = {
  type: 'default' as NormalTypes,
  className: ''
}

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

const Dot: React.FC<React.PropsWithChildren<DotProps>> = ({
  type,
  children,
  className,
  ...props
}) => {
  return (
    <span className={`dot ${className}`} {...props}>
      <DotIcon type={type} />
      <span className="label">{children}</span>

      <style jsx>{`
        .dot {
          display: inline-flex;
          align-items: center;
        }

        .label {
          margin-left: 8px;
          font-size: 1rem;
          text-transform: capitalize;
        }
      `}</style>
    </span>
  )
}

type MemoDot<P> = React.NamedExoticComponent<P> & {
  Icon: typeof DotIcon
}

type ComponentProps = Partial<typeof defaultProps> &
  Omit<Props, keyof typeof defaultProps> &
  NativeAttrs

Dot.defaultProps = defaultProps

export default React.memo(Dot) as MemoDot<ComponentProps>
