import React, { FC, useEffect } from "react";
import { Table } from "../../../index";
import { useFetch } from "@utils//request";
import { conditionalColumns } from "@components/OrderList/columnConfigs";
import { orderListTotalsSub } from "@components/OrderList";
import { APINameEnum } from "@utils/request/ApiNameEnum";

export interface ConditionalProps {}
export const Conditional: FC<ConditionalProps> = props => {
  const {} = props;
  const { data: openOrderSource, loading: openOrderSourceLoading } = useFetch(APINameEnum.OPEN_ORDERS, {
    tradeType: "linearPerpetual"
  });
  useEffect(() => {
    orderListTotalsSub.next({
      ...orderListTotalsSub.value,
      conditional: openOrderSource?.totalSize
    });
  }, [openOrderSource]);

  return (
    <>
      <Table columns={conditionalColumns} dataSource={openOrderSource?.list} isLoading={openOrderSourceLoading} />
    </>
  );
};
