import { useState, useContext, useEffect } from "react";
import { useLocation } from "react-router-dom";

import JobContext from "../../ctx/JobContext.jsx";
import JobBox from "./JobBox.jsx";
import JobTestSelector from "./JobTestSelector.jsx";
import JobView from "./JobView.jsx";
import JobBuilder from "./builder/JobBuilder.jsx";

export default function Jobs() {
  const {
    state: jobState,
    dispatch: jobDispatch,
    jobBuilder,
  } = useContext(JobContext);
  const location = useLocation();

  return (
    <div className="jobs">
      <JobBuilder />
      {location.hash === "" &&
        jobState.jobs.map((v, i) => (
          <a
            key={i}
            href={`/qualiteer/jobs#${v.name}`}
            style={{ textDecoration: "none" }}
          >
            <JobBox job={v} />
          </a>
        ))}
      {jobState.jobs.find((job) => job.name === location.hash.slice(1)) && (
        <JobView
          job={jobState.jobs.find((job) => job.name === location.hash.slice(1))}
        />
      )}
    </div>
  );
}
