import React, { useMemo, useState } from "react";
import JobLinesComponent from "./job-lines.component";

function JobLinesContainer({ job, joblines, refetch, form, ...rest }) {
  const [searchText, setSearchText] = useState("");

  const jobLines = useMemo(() => {
    return joblines
      ? searchText
        ? joblines.filter(
            (jl) =>
              (jl.unq_seq || "").toString().toLowerCase().includes(searchText.toLowerCase()) ||
              (jl.line_desc || "").toLowerCase().includes(searchText.toLowerCase()) ||
              (jl.part_type || "").toLowerCase().includes(searchText.toLowerCase()) ||
              (jl.oem_partno || "").toLowerCase().includes(searchText.toLowerCase()) ||
              (jl.op_code_desc || "").toLowerCase().includes(searchText.toLowerCase()) ||
              (jl.db_price || "").toString().includes(searchText.toLowerCase()) ||
              (jl.act_price || "").toString().includes(searchText.toLowerCase())
          )
        : joblines
      : [];
  }, [joblines, searchText]);

  return (
    <JobLinesComponent refetch={refetch} jobLines={jobLines} setSearchText={setSearchText} job={job} form={form} />
  );
}

export default JobLinesContainer;
