import React from "react"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
import PropTypes from "prop-types"

import { icons } from "./icons"
import "./library"

export const lookupSocialIcon = icon => icons.find(i => i.iconName === icon)

const Icon = ({ icon, ...props }) => {
  if (icon && typeof icon == "string") {
    icon = lookupSocialIcon(icon)
  }

  return <FontAwesomeIcon icon={icon} {...props} />
}

Icon.propTypes = {
  icon: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
}
export default Icon
