import { _ as _extends } from '../_rollupPluginBabelHelpers-736b301a.js';
import React__default, { useCallback, useMemo } from 'react';
import IconFont from '../IconFont/index.js';
import AuthComponent from '../AuthComponent/index.js';
import { Tooltip } from 'antd';
import { uuid, LM_DB, pageStateHelper } from '@zenview/micro-utils';
import { Shared } from '@zenview/micro-basic-library';
import ___default from 'lodash';
import { L as LinkItem, C as CaptureTools } from '../index-19c4ec5b.js';
import { useHistory } from 'react-router-dom';

const getPageStateData = ({
  history
}) => {
  const {
    location
  } = history;
  const pageState = pageStateHelper.getPageState(`${location.pathname}${location.search}`) || {};
  const options = ___default.cloneDeep(pageState);
  delete options.id;
  delete options.imgId;
  return options;
};
function FaceRecord({
  title = '人脸记录',
  history,
  ...data
}) {
  const onClick = useCallback(e => {
    e.stopPropagation();
    const dbId = uuid();
    const db = new LM_DB('faceLibs');
    db.put({
      id: dbId,
      defaultUrl: data.faceUrl || data.bodyUrl || data.vehicleUrl || data.sceneUrl,
      frameUrl: data.sceneUrl,
      searchData: {
        id: data.id,
        imgId: data.imgId,
        aids: data.aid ? Array.isArray(data.aid) ? data.aid : [data.aid] : []
      }
    }).then(() => {
      history.push(`/faceLibrary/record?dbId=${dbId}`);
    });
  }, [data.faceUrl, data.bodyUrl, data.vehicleUrl, data.sceneUrl, data.id, data.imgId, data.aid, history]);
  return /*#__PURE__*/React__default.createElement(AuthComponent, {
    actionName: "faceRecord",
    key: 'faceRecord'
  }, /*#__PURE__*/React__default.createElement(Tooltip, {
    title: title
  }, /*#__PURE__*/React__default.createElement(IconFont, {
    type: "icon-S_Bar_Face",
    onClick: onClick
  })));
}
function BodyRecord({
  title = '人体记录',
  history,
  ...data
}) {
  const onClick = useCallback(e => {
    e.stopPropagation();
    const dbId = uuid();
    const db = new LM_DB('bodyLibs');
    db.put({
      id: dbId,
      defaultUrl: data.faceUrl ? data.faceUrl : data.bodyUrl,
      frameUrl: data.sceneUrl,
      searchData: {
        id: data.id,
        imgId: data.imgId,
        aids: data.aid ? Array.isArray(data.aid) ? data.aid : [data.aid] : []
      }
    }).then(res => {
      history.push(`/bodyLibrary/record?dbId=${dbId}`);
    });
  }, [data.faceUrl, data.bodyUrl, data.sceneUrl, data.id, data.imgId, data.aid, history]);
  return /*#__PURE__*/React__default.createElement(AuthComponent, {
    actionName: "bodyRecord",
    key: 'bodyRecord'
  }, /*#__PURE__*/React__default.createElement(Tooltip, {
    title: title
  }, /*#__PURE__*/React__default.createElement(IconFont, {
    type: "icon-L_AID_Body1",
    onClick: onClick
  })));
}
function FaceSearch({
  title = '人脸检索',
  history,
  ...data
}) {
  let name = data.faceUrl ? '人脸检索' : '关联人脸检索';
  const onClick = useCallback(e => {
    e.stopPropagation();
    const dbId = uuid();
    const pageStateOptions = getPageStateData({
      history
    });
    const _pageStateOptions = ___default.cloneDeep(pageStateOptions);
    delete _pageStateOptions.feature;
    const db = new LM_DB('faceLibs');
    db.put({
      id: dbId,
      defaultUrl: data.faceUrl ? data.faceUrl : data.bodyUrl,
      frameUrl: data.sceneUrl,
      searchData: {
        id: data.id,
        imgId: data.imgId,
        aids: data.aid ? Array.isArray(data.aid) ? data.aid : [data.aid] : [],
        ..._pageStateOptions
      }
    }).then(res => {
      history.push(`/faceLibrary/search?dbId=${dbId}`);
    });
  }, [data.faceUrl, data.bodyUrl, data.sceneUrl, data.id, data.imgId, data.aid, history]);
  return /*#__PURE__*/React__default.createElement(AuthComponent, {
    actionName: "faceSearch",
    key: 'faceSearch'
  }, /*#__PURE__*/React__default.createElement(Tooltip, {
    title: name || title
  }, /*#__PURE__*/React__default.createElement(IconFont, {
    type: "icon-S_Bar_Face",
    onClick: onClick
  })));
}
function BodySearch({
  title = '人体检索',
  history,
  ...data
}) {
  let name = data.bodyUrl ? '人体检索' : '关联人体检索';
  const onClick = useCallback(e => {
    e.stopPropagation();
    const dbId = uuid();
    const pageStateOptions = getPageStateData({
      history
    });
    const _pageStateOptions = ___default.cloneDeep(pageStateOptions);
    delete _pageStateOptions.feature;
    const db = new LM_DB('bodyLibs');
    db.put({
      id: dbId,
      defaultUrl: data.faceUrl ? data.faceUrl : data.bodyUrl,
      frameUrl: data.sceneUrl,
      searchData: {
        id: data.id,
        imgId: data.imgId,
        aids: data.aid ? Array.isArray(data.aid) ? data.aid : [data.aid] : [],
        ..._pageStateOptions
      }
    }).then(res => {
      history.push(`/bodyLibrary/search?dbId=${dbId}`);
    });
  }, [data.faceUrl, data.bodyUrl, data.sceneUrl, data.id, data.imgId, data.aid, history]);
  return /*#__PURE__*/React__default.createElement(AuthComponent, {
    actionName: "bodySearch",
    key: 'bodySearch'
  }, /*#__PURE__*/React__default.createElement(Tooltip, {
    title: name || title
  }, /*#__PURE__*/React__default.createElement(IconFont, {
    type: "icon-L_AID_Body1",
    onClick: onClick
  })));
}
function VehicleSearch({
  title = '综合检索',
  history,
  ...data
}) {
  let defaultUrl = data.vehicleUrl;
  let id = data.id;
  if ((data.faceUrl || data.bodyUrl) && data.captureVehicleId) {
    defaultUrl = data.faceUrl || data.bodyUrl || data.sceneUrl;
    id = data.captureVehicleId;
  }
  const onClick = useCallback(async e => {
    e.stopPropagation();
    const pageStateOptions = getPageStateData({
      history
    });
    const _pageStateOptions = ___default.cloneDeep(pageStateOptions);
    delete _pageStateOptions.feature;
    const pageInfo = Shared.resourcePageInfo['vehicleSearch'];
    const dbId = uuid();
    const db = new LM_DB(pageInfo.dbName);
    const searchData = {
      id,
      imgId: data.imgId,
      ..._pageStateOptions
    };
    const dbData = {
      id: dbId,
      defaultUrl,
      searchData
    };
    await db.put(dbData);
    const pathname = `/vehicleLibrary/search?dbId=${dbId}`;
    const location = {
      state: {
        pageTitle: '机动车综合检索'
      },
      pathname
    };
    history.push(location);
  }, [history, id, data.imgId, defaultUrl]);
  return /*#__PURE__*/React__default.createElement(AuthComponent, {
    actionName: "vehicleSearch",
    key: 'vehicleSearch'
  }, /*#__PURE__*/React__default.createElement(Tooltip, {
    title: title
  }, /*#__PURE__*/React__default.createElement(IconFont, {
    type: "icon-S_Bar_Motor",
    onClick: onClick
  })));
}
function VehicleTrajectory({
  title = '车辆轨迹',
  history,
  ...data
}) {
  const onClick = useCallback(e => {
    e.stopPropagation();
    const pageInfo = Shared.resourcePageInfo['queryVehicleTrajectoryPictures'];
    const fnName = pageInfo.fnName;
    Shared[fnName]({
      history,
      type: 'queryVehicleTrajectoryPictures',
      data
    });
  }, [history, data]);
  return /*#__PURE__*/React__default.createElement(Tooltip, {
    title: title
  }, /*#__PURE__*/React__default.createElement(IconFont, {
    type: "icon-M_Bar_Trajectory1",
    onClick: onClick
  }));
}
function NonVehicleSearch({
  title = '非机动车检索',
  history,
  ...data
}) {
  let defaultUrl = data.vehicleUrl;
  let id = data.id;
  if ((data.faceUrl || data.bodyUrl) && data.captureVehicleId) {
    defaultUrl = data.faceUrl || data.bodyUrl || data.sceneUrl;
    id = data.captureVehicleId;
  }
  const onClick = useCallback(async e => {
    e.stopPropagation();
    const pageInfo = Shared.resourcePageInfo['nonVehicleSearch'];
    const pageStateOptions = getPageStateData({
      history
    });
    const _pageStateOptions = ___default.cloneDeep(pageStateOptions);
    delete _pageStateOptions.feature;
    const dbId = uuid();
    const db = new LM_DB(pageInfo.dbName);
    const searchData = {
      id,
      imgId: data.imgId,
      ..._pageStateOptions
    };
    const dbData = {
      id: dbId,
      defaultUrl,
      searchData
    };
    await db.put(dbData);
    const pathname = `/nonVehicleLibrary/search?dbId=${dbId}`;
    const location = {
      state: {
        pageTitle: '机动车综合检索'
      },
      pathname
    };
    history.push(location);
    // Shared[fnName]({ history, defaultUrl, frameUrl: data.sceneUrl, id, imgId: data.imgId });
  }, [history, defaultUrl, data.imgId, id]);
  return /*#__PURE__*/React__default.createElement(AuthComponent, {
    actionName: "nonVehicleSearch",
    key: 'nonVehicleSearch'
  }, /*#__PURE__*/React__default.createElement(Tooltip, {
    title: title
  }, /*#__PURE__*/React__default.createElement(IconFont, {
    type: "icon-M_AID_NonMotor",
    onClick: onClick
  })));
}
function VehicleFile({
  title = '车辆档案',
  history,
  ...data
}) {
  const onClick = useCallback(e => {
    e.stopPropagation();
    const plateId = data.motorPlateId;
    history.push(`/vehicleArchives/vehicleDetail?id=${plateId}`);
  }, [data.motorPlateId, history]);
  return /*#__PURE__*/React__default.createElement(AuthComponent, {
    actionName: "vehicleDetail",
    key: 'vehicleDetail'
  }, /*#__PURE__*/React__default.createElement(Tooltip, {
    title: title
  }, /*#__PURE__*/React__default.createElement(IconFont, {
    type: "icon-S_View_FileMotor",
    onClick: onClick
  })));
}
function PersonFile({
  title = '人员档案',
  history,
  ...data
}) {
  const onClick = useCallback(e => {
    e.stopPropagation();
    let {
      aid,
      personId
    } = data;
    history.push(`/personArchives/personnelDetail?${aid ? `aid=${aid}&` : ''}${personId ? `personId=${personId}` : ''}`);
  }, [data, history]);
  return /*#__PURE__*/React__default.createElement(AuthComponent, {
    actionName: "personArchivesDetail",
    key: 'personArchivesDetail'
  }, /*#__PURE__*/React__default.createElement(Tooltip, {
    title: title
  }, /*#__PURE__*/React__default.createElement(IconFont, {
    type: "icon-S_View_FilePerson",
    onClick: onClick
  })));
}
function RelationMap({
  title = '关系图谱',
  history,
  ...data
}) {
  const onClick = useCallback(e => {
    e.stopPropagation();
    let {
      aid,
      personId
    } = data;
    history.push(`/relationShip?${aid ? `aid=${aid}&` : ''}${personId ? `personId=${personId}` : ''}`);
  }, [data, history]);
  return /*#__PURE__*/React__default.createElement(AuthComponent, {
    actionName: "relationShip",
    key: 'relationShip'
  }, /*#__PURE__*/React__default.createElement(Tooltip, {
    title: title
  }, /*#__PURE__*/React__default.createElement(IconFont, {
    type: "icon-S_Photo_Relationship",
    onClick: onClick
  })));
}
function VehiclePlateSearch({
  title = '车牌检索',
  history,
  ...data
}) {
  const onClick = useCallback(e => {
    var _pageStateOptions$dat, _data$plateNo;
    e.stopPropagation();
    let {
      imgUrl,
      tags
    } = data;
    const dbId = uuid();
    const pageStateOptions = getPageStateData({
      history
    });
    const {
      cids,
      dataSelectAll,
      endTime,
      plateColor,
      plateNo,
      score,
      startTime,
      timeRange
    } = pageStateOptions;
    const dataDb = {
      id: dbId,
      defaultDataSelectAll: (_pageStateOptions$dat = pageStateOptions.dataSelectAll) !== null && _pageStateOptions$dat !== void 0 ? _pageStateOptions$dat : data.dataSelectAll,
      defaultUrl: imgUrl,
      frameUrl: imgUrl,
      plateNo: (_data$plateNo = data.plateNo) !== null && _data$plateNo !== void 0 ? _data$plateNo : plateNo,
      tags,
      searchData: {
        cids,
        dataSelectAll,
        endTime,
        plateColor,
        plateNo,
        score,
        startTime,
        timeRange
      }
    };
    const db = new LM_DB('vehicleLibs');
    db.put(dataDb).then(() => {
      history.push({
        state: {
          pageTitle: '机动车车牌检索'
        },
        pathname: '/vehicleLibrary/plateSearch',
        search: `?dbId=${dbId}`
      });
    });
  }, [data, history]);
  return /*#__PURE__*/React__default.createElement(AuthComponent, {
    actionName: "vehiclePlateSearch",
    key: 'vehiclePlateSearch'
  }, /*#__PURE__*/React__default.createElement(Tooltip, {
    title: title
  }, /*#__PURE__*/React__default.createElement(IconFont, {
    type: "icon-LicensePlateNumber",
    onClick: onClick
  })));
}
const ItemConfig = {
  faceRecord: {
    deps: [['hasArchives', 'aid', 'hasFace'],
    //人体卡片跳人脸
    ['hasArchives', 'aid', 'faceUrl'],
    //人脸卡片跳人体
    ['vehicleUrl', 'hasAid'] //车辆跳人脸、人体
    ],
    condition: 'or',
    ItemComponent: FaceRecord
  },
  bodyRecord: {
    deps: [['hasArchives', 'aid', 'hasBody'],
    //人脸卡片跳人体
    ['hasArchives', 'aid', 'bodyUrl'] //人体卡片跳人脸
    // ['vehicleUrl', 'hasAid'] //车辆跳人脸、人体
    ],
    condition: 'or',
    ItemComponent: BodyRecord
  },
  personFile: {
    deps: [['aid', 'hasArchives'], ['personId']],
    condition: 'or',
    ItemComponent: PersonFile
  },
  relationMap: {
    deps: [['aid', 'hasArchives'], ['personId']],
    condition: 'or',
    ItemComponent: RelationMap
  },
  faceSearch: {
    deps: [['faceUrl'],
    //人脸卡片跳人体
    ['hasFace'] //人体卡片跳人脸
    ],
    condition: 'or',
    ItemComponent: FaceSearch
  },
  bodySearch: {
    deps: [['hasBody'],
    //人脸卡片跳人体
    ['bodyUrl'] //人体卡片跳人脸
    ],
    condition: 'or',
    ItemComponent: BodySearch
  },
  vehicleSearch: {
    deps: [['vehicleUrl'],
    //机动车
    ['hasArchives', 'captureVehicleId'],
    // 有档案
    ['faceUrl', 'captureVehicleId'],
    //人脸
    ['bodyUrl', 'captureVehicleId'] //人体
    ],
    condition: 'or',
    ItemComponent: VehicleSearch
  },
  nonVehicleSearch: {
    deps: [['vehicleUrl'],
    //非机动车
    ['hasArchives', 'captureVehicleId'],
    // 有档案
    ['faceUrl', 'captureVehicleId'],
    //人脸
    ['bodyUrl', 'captureVehicleId'] //人体
    ],
    condition: 'or',
    ItemComponent: NonVehicleSearch
  },
  vehicleTrajectory: {
    deps: [['vehicleUrl']],
    condition: 'or',
    ItemComponent: VehicleTrajectory
  },
  vehicleFile: {
    deps: [['motorPlateId', 'plateNo']],
    condition: 'or',
    ItemComponent: VehicleFile
  },
  vehiclePlateSearch: {
    deps: [['plateNo']],
    condition: 'or',
    ItemComponent: VehiclePlateSearch
  }
};

function getToolsConfig() {
  //TODO 记录使用频率，完成推荐排序
  return ['faceRecord', 'bodyRecord', 'personFile', 'relationMap', 'faceSearch', 'bodySearch', 'vehicleTrajectory', 'vehiclePlateSearch', 'vehicleSearch', 'nonVehicleSearch', 'vehicleFile'];
}
function LinkTools({
  onlyTools,
  filterTools,
  ...props
}) {
  const history = useHistory();
  const toools = useMemo(() => {
    const arr = getToolsConfig();
    if (onlyTools && Array.isArray(onlyTools)) {
      return onlyTools.filter(v => arr.includes(v));
    }
    if (filterTools && Array.isArray(filterTools)) {
      return arr.filter(v => !filterTools.includes(v));
    }
    return arr;
  }, [filterTools, onlyTools]);
  return /*#__PURE__*/React__default.createElement("div", {
    className: "link-tools-layout"
  }, toools.map(item => /*#__PURE__*/React__default.createElement(LinkItem, _extends({}, props, {
    history: history,
    typeKey: item,
    key: item,
    linkConfig: ItemConfig
  }))));
}

const ToolsBar = {
  LinkTools,
  CaptureTools
};

export { ToolsBar as default };
//# sourceMappingURL=index.js.map
