import { useQuery } from "@apollo/client/react";
import { GET_LINE_TICKET_BY_PK } from "../../graphql/jobs-lines.queries";
import AlertComponent from "../alert/alert.component";
import JobsDetailLaborComponent from "./jobs-detail-labor.component";

export default function JobsDetailLaborContainer({ jobId, techConsole, job }) {
  const id = jobId ?? null;

  const { loading, error, data, refetch } = useQuery(GET_LINE_TICKET_BY_PK, {
    variables: { id },
    skip: !id,
    fetchPolicy: "network-only",
    nextFetchPolicy: "network-only"
  });

  if (error) return <AlertComponent title={error.message} type="error" />;

  return (
    <JobsDetailLaborComponent
      loading={loading}
      jobId={id}
      timetickets={data ? data.timetickets : []}
      joblines={data ? data.joblines : []}
      refetch={refetch}
      techConsole={techConsole}
      adjustments={data ? data.jobs_by_pk.lbr_adjustments : []}
      job={job}
    />
  );
}
