import { useQuery } from "@apollo/client";
import React from "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 { loading, error, data, refetch } = useQuery(GET_LINE_TICKET_BY_PK, {
    variables: { id: jobId },
    skip: !!!jobId,
    fetchPolicy: "network-only",
    nextFetchPolicy: "network-only",
  });

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

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