import { Button, Input, Space } from "antd";
import React, { useState } from "react";
import { useTranslation } from "react-i18next";

export default function HelpRescue() {
  const { t } = useTranslation();
  const [code, setCode] = useState("");

  const handleClick = async () => {
    var bodyFormData = new FormData();
    bodyFormData.append("Code", code);
    bodyFormData.append("hostederrorhandling", 1);
    await fetch("https://secure.logmeinrescue.com/Customer/Code.aspx", {
      mode: "no-cors",
      method: "POST",
      body: bodyFormData
    });
  };

  return (
    <div style={{ display: "flex", justifyContent: "center" }}>
      <Space direction="vertical" align="center">
        <div>{t("help.labels.rescuedesc")}</div>
        <Input
          size="large"
          style={{ width: "10rem" }}
          onChange={(e) => setCode(e.target.value)}
          value={code}
          placeholder={t("help.labels.codeplacholder")}
        />
        <Button onClick={handleClick}>{t("help.actions.connect")}</Button>

        <form
          name="logmeinsupport"
          action="https://secure.logmeinrescue.com/Customer/Code.aspx"
          method="post"
          id="logmeinsupport"
          onSubmit={(...props) => {
            alert();
          }}
        >
          <span>Enter your 6-digit code: </span>
          <input type="text" name="Code" />
          <br />
          <input type="submit" value="Connect to technician" />
          <input type="hidden" name="tracking0" maxlength="64" />
          <input type="hidden" name="language" maxlength="5" />
          <input type="hidden" name="hostederrorhandling" value="1" />
        </form>
      </Space>
    </div>
  );
}
