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 SocialIcon = ({ name, ...props }) => {
  let iconName
  if (name && typeof name == "string") {
    iconName = lookupSocialIcon(name)
  }

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

SocialIcon.propTypes = {
  name: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
}

export default SocialIcon
