import React, { useEffect, useState } from "react";
import { Grid } from "../../../../components/grid/Grid";
import { SimpleTable } from "../../../../components/simple-table/SimpleTable";
import { provinceJahadGetCooperativesPosInfoService } from "../../services/province-jahad-get-cooperatives-pos";
import { useDispatch } from "react-redux";

export const ProvinceJahadCooperativesModal = ({ item }) => {
  const dispatch = useDispatch();
  const [tableData, setTableData] = useState([]);

  useEffect(() => {
    dispatch(provinceJahadGetCooperativesPosInfoService(item.key)).then((r) => {
      const d = r.payload.data?.map((item, i) => {
        return [i + 1, item?.companyName, item?.posId];
      });

      setTableData(d);
    });
  }, []);

  return (
    <Grid container xs={12}>
      <SimpleTable
        columns={["ردیف", "نام شرکت", "شناسه POS"]}
        data={tableData}
      />
    </Grid>
  );
};
