import { request } from "@cqsjjb/jjb-common-lib/http.js";
import { useEffect, useState } from "react";
import BasicSelectTree from "../../Basic";

/**
 * 隐患部位下拉树组件（港务局版本）
 */
function HiddenPartSelectTree(props) {
  const {
    params = {},
    isNeedCorpInfoId = false,
    ...restProps
  } = props;

  const [treeData, setTreeData] = useState([]);

  const getData = async () => {
    setTreeData([]);

    // 根据参数决定是否发送请求
    if (isNeedCorpInfoId && !params.eqCorpinfoId)
      return;

    const { data } = await request("/hidden/hiddenRegion/listByTree", "post", params);
    setTreeData(data);
  };

  useEffect(() => {
    getData();
  }, [JSON.stringify(params), isNeedCorpInfoId]);

  return (
    <BasicSelectTree treeData={treeData} placeholder="隐患部位" nameKey="hiddenregion" idKey="hiddenregionId" {...restProps} />
  );
}

HiddenPartSelectTree.displayName = "HiddenPartSelectTree";

export default HiddenPartSelectTree;
