import { Typography } from "antd";
import parsePhoneNumber from "libphonenumber-js";

const { Text } = Typography;

export default function PhoneNumberFormatter({ children, type }) {
  const p = parsePhoneNumber(children || "", "CA");
  if (!p) return null;

  const phone = p.formatNational();

  return (
    <span>
      <span>{phone}</span>
      {type ? <Text type="secondary"> ({type})</Text> : null}
    </span>
  );
}
