import { Box } from "@mui/system";
import { useEffect, useState } from "react";
import { useDispatch } from "react-redux";
import { Grid } from "../../../../components/grid/Grid";
import { SimpleTable } from "../../../../components/simple-table/SimpleTable";
import { SPACING } from "../../../../data/spacing";
import {
  LOADING_END,
  LOADING_START,
} from "../../../../lib/redux/slices/appSlice";
import { getChainCompanyProfile } from "../../services/get-chain-company-profile";

export const ChainCompanyProfile = () => {
  const dispatch = useDispatch();

  const [data, setData] = useState();

  useEffect(() => {
    dispatch(LOADING_START());
    dispatch(getChainCompanyProfile()).then((r) => {
      setData(r.payload.data);
      dispatch(LOADING_END());
    });
  }, []);

  return (
    <Box>
      <Grid container gap={SPACING.LARGE}>
        <Grid container direction="column" xs={12}>
          <Grid
            container
            direction="column"
            justifyContent="space-between"
            gap={SPACING.SMALL}
          >
            <>
              <Grid>
                <SimpleTable
                  name={`اطلاعات شرکت زنجیره`}
                  columns={[
                    "نام",
                    "نام خانوداگی",
                    "استان",
                    "شهر",
                    "آدرس",
                    "کدپستی",
                  ]}
                  data={[
                    [
                      data?.user?.firstName,
                      data?.user?.lastName,
                      data?.address?.province.name,
                      data?.address?.city.name,
                      data?.address?.address,
                      data?.address?.postalCode,
                    ],
                  ]}
                />
              </Grid>
            </>
          </Grid>
        </Grid>
      </Grid>
    </Box>
  );
};
