import { MailFilled } from "@ant-design/icons";
import { Button, Input, Space } from "antd";

function FormItemEmail({ defaultValue, value, ref, ...restProps }) {
  const emailValue = defaultValue || value;

  return (
    <Space.Compact style={{ width: "100%" }}>
      <Input {...restProps} ref={ref} value={value} defaultValue={defaultValue} />
      {emailValue ? (
        <Button icon={<MailFilled />} href={`mailto:${emailValue}`} target="_blank" rel="noopener noreferrer" />
      ) : (
        <Button icon={<MailFilled />} disabled />
      )}
    </Space.Compact>
  );
}

export default FormItemEmail;
