import React, { useCallback } from "react";
import FormPage from "../jobForm/FormPage";
import { submitJobInfo } from "../data/submitData";
import { useLoaded } from "../util/hooks";
import { getProfileLoc } from "../data/getProfileLoc";
import Loading from "../util/Loading";
import styled from "styled-components";
import { FullScreen } from "../util/Layout";
import { notification } from "antd";

const Backgroud = styled(FullScreen)`
  background: rgba(245, 246, 249, 1);
`;

export default ({ history, user }) => {
  console.log(user);
  const { isLoaded, data: city } = useLoaded(getProfileLoc, [user]);
  const submit = useCallback((v) => {
    const f = async () => {
      await submitJobInfo(v);
      notification.open({
        message: "成功",
        description: "提交职位成功，请耐心等待审核",
      });
      const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
      await wait(1000);
      history.push("/recruitment?tab=1&jobstate=drafted");
    };
    f();
  }, []);
  const data = {
    education: "学历不限",
    work_year: "经验不限",
    city,
  };
  if (!isLoaded) {
    return (
      <Backgroud>
        <Loading />
      </Backgroud>
    );
  }
  return (
    <FormPage
      submit={submit}
      data={data}
      back={() => {
        history.goBack();
      }}
    ></FormPage>
  );
};
