import React from "react";
import { Link } from "react-router-dom";

import { useFormValidation } from "@hooks/useFormValidation";
import { useNotification } from "@hooks/useNotification";

import AuthHeader from "@components/Common/AuthHeader/AuthHeader";
import { Footer } from "@components/Common/Footer/Footer";
import SideBar from "@components/SideBar/SideBar";
import StepsForCandidate from "@components/StepsForCandidate/StepsForCandidate";

import arrowBtn from "assets/icons/arrows/arrowRight.svg";
import BackEndImg from "assets/images/partnerProfile/personalBackEnd.svg";

import "./registationForCandidate.scss";

export const RegistrationForCandidate = () => {
  const apiEndpoint = "/register/sign-up";

  const fields = {
    username: "",
    summary: "",
    email: "",
    tg: "",
    password: "",
    secondPassword: ""
  };

  const { showNotification } = useNotification();
  const showNotificationError = () => {
    showNotification({
      show: true,
      text: "Аккаунт с таким логином или email уже существует",
      type: "error"
    });
  };
  const showNotificationTrue = () => {
    showNotification({
      show: true,
      text: "Аккаунт успешно создан",
      type: "success"
    });
  };

  const { formData, validationErrors, handleChange, handleSubmit } =
    useFormValidation(
      apiEndpoint,
      fields,
      showNotificationError,
      showNotificationTrue
    );

  return (
    <div className="registrationCandidate">
      <AuthHeader />
      <div className="container">
        <div className="registrationCandidate__start">
          <h2 className="auth-candidate__start__title">
            Хочу в команду <span>IT-специалистов</span>
          </h2>
          <div className="change-mode__arrow">
            <img src={arrowBtn}></img>
          </div>
          <p className="auth-candidate__start__description">
            Для нас не имеет значения Ваша локация.
          </p>
          <StepsForCandidate step="шаг 2 - заполните данные" />
          <div className="registrationCandidate__formWrapper">
            <div className="registrationCandidate__info">
              <div className="registrationCandidate__info__category">
                <img src={BackEndImg} alt="img" />
                <p>Backend разработчики</p>
              </div>
              <p className="registrationCandidate__info__skills">
                Java PHP Python C# React Vue.js NodeJs Golang Ruby JavaScript
              </p>
              <Link
                to="/auth-candidate"
                className="registrationCandidate__info__arrow"
              >
                <img src={arrowBtn} alt="img" />
              </Link>
            </div>
            {/* форма регистрации */}
            <form
              className="registrationCandidate__form"
              onSubmit={handleSubmit}
            >
              <div className="registrationCandidate__form__input">
                <label htmlFor="name">Ваше имя</label>
                <input
                  className={validationErrors.username ? "error" : ""}
                  value={formData.username}
                  onChange={handleChange}
                  id="username"
                  type="text"
                  placeholder="Имя"
                />
                <span>{validationErrors.username}</span>
              </div>
              <div className="registrationCandidate__form__input">
                <label htmlFor="summary">Если есть ссылка на резюме</label>
                <input
                  className={validationErrors.summary ? "error" : ""}
                  value={formData.summary}
                  onChange={handleChange}
                  id="summary"
                  type="url"
                  placeholder="Резюме"
                />
                <span>{validationErrors.summary}</span>
              </div>
              <div className="registrationCandidate__form__input">
                <label htmlFor="email">Ваш e-mail</label>
                <input
                  className={validationErrors.email ? "error" : ""}
                  value={formData.email}
                  onChange={handleChange}
                  id="email"
                  type="email"
                  placeholder="E-mail"
                />
                <span>{validationErrors.email}</span>
              </div>
              <div className="registrationCandidate__form__input">
                <label htmlFor="tg">Ваш telegram</label>
                <input
                  className={validationErrors.tg ? "error" : ""}
                  value={formData.tg}
                  onChange={handleChange}
                  id="tg"
                  type="text"
                  placeholder="Telegram"
                />
                <span>{validationErrors.tg}</span>
              </div>
              <div className="registrationCandidate__form__input">
                <label htmlFor="password">Придумайте пароль</label>
                <input
                  className={validationErrors.password ? "error" : ""}
                  value={formData.password}
                  onChange={handleChange}
                  id="password"
                  type="password"
                  placeholder="Пароль"
                />
                <span>{validationErrors.password}</span>
              </div>
              <div className="registrationCandidate__form__input">
                <label htmlFor="secondPassword">Повторите пароль</label>
                <input
                  className={validationErrors.secondPassword ? "error" : ""}
                  value={formData.secondPassword}
                  onChange={handleChange}
                  id="secondPassword"
                  type="password"
                  placeholder="Пароль"
                />
                <span>{validationErrors.secondPassword}</span>
              </div>
              <div className="registrationCandidate__form__submit">
                <button type="submit">Отправить</button>
              </div>
            </form>
          </div>
        </div>
      </div>
      <SideBar />
      <Footer />
    </div>
  );
};
