import { _ as _extends } from './_rollupPluginBabelHelpers-736b301a.js';
import React__default, { useMemo, useCallback } from 'react';
import { Button } from 'antd';
import IconFont from './IconFont/index.js';
import AuthComponent from './AuthComponent/index.js';
import { uuid, LM_DB } from '@zenview/micro-utils';
import { Shared } from '@zenview/micro-basic-library';
import { useHistory } from 'react-router-dom';

function LinkItem({
  typeKey,
  linkConfig,
  history,
  ...data
}) {
  const config = useMemo(() => linkConfig[typeKey] || {}, [typeKey, linkConfig]);
  const isVisisble = useMemo(() => {
    let flag = true;
    if (Array.isArray(config.deps) && config.deps.length > 0) {
      const flagArr = config.deps.map(itemArr => {
        let vData = data;
        const vArr = itemArr.map(v => vData[v]);
        return vArr.findIndex(v => !v) === -1;
      });
      if (config.condition === 'and') {
        flag = flagArr.findIndex(v => !v) === -1;
      } else {
        flag = flagArr.find(v => !!v) > -1;
      }
    } else {
      flag = false;
    }
    return flag;
  }, [config.condition, config.deps, data]);
  return !isVisisble ? /*#__PURE__*/React__default.createElement(React__default.Fragment, null) : /*#__PURE__*/React__default.createElement(config.ItemComponent, _extends({
    history: history
  }, data));
}

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,
      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(`/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(Button, {
    onClick: onClick
  }, /*#__PURE__*/React__default.createElement(IconFont, {
    type: "icon-S_Bar_Face"
  }), title));
}
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(Button, {
    onClick: onClick
  }, /*#__PURE__*/React__default.createElement(IconFont, {
    type: "icon-L_AID_Body1"
  }), title));
}
function FaceSearch({
  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.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(`/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(Button, {
    onClick: onClick
  }, /*#__PURE__*/React__default.createElement(IconFont, {
    type: "icon-S_Bar_Face"
  }), !!data.hasFace ? '关联人脸检索' : '人脸检索'));
}
function BodySearch({
  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/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(Button, {
    onClick: onClick
  }, /*#__PURE__*/React__default.createElement(IconFont, {
    type: "icon-S_Bar_Body"
  }), !!data.hasBody ? '关联人体检索' : '人体检索'));
}
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;
    id = data.captureVehicleId;
  }
  const onClick = useCallback(e => {
    e.stopPropagation();
    const pageInfo = Shared.resourcePageInfo['vehicleSearch'];
    const fnName = pageInfo.fnName;
    Shared[fnName]({
      history,
      defaultUrl,
      frameUrl: data.sceneUrl,
      id,
      imgId: data.imgId
    });
  }, [history, defaultUrl, data.sceneUrl, data.imgId, id]);
  return /*#__PURE__*/React__default.createElement(AuthComponent, {
    actionName: "vehicleSearch",
    key: 'vehicleSearch'
  }, /*#__PURE__*/React__default.createElement(Button, {
    onClick: onClick
  }, /*#__PURE__*/React__default.createElement(IconFont, {
    type: "icon-S_Bar_Motor"
  }), title));
}
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;
    id = data.captureVehicleId;
  }
  const onClick = useCallback(e => {
    e.stopPropagation();
    const pageInfo = Shared.resourcePageInfo['nonVehicleSearch'];
    const fnName = pageInfo.fnName;
    Shared[fnName]({
      history,
      defaultUrl,
      frameUrl: data.sceneUrl,
      id,
      imgId: data.imgId
    });
  }, [history, defaultUrl, data.sceneUrl, data.imgId, id]);
  return /*#__PURE__*/React__default.createElement(AuthComponent, {
    actionName: "nonVehicleSearch",
    key: 'nonVehicleSearch'
  }, /*#__PURE__*/React__default.createElement(Button, {
    onClick: onClick
  }, /*#__PURE__*/React__default.createElement(IconFont, {
    type: "icon-M_AID_NonMotor"
  }), title));
}
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(Button, {
    onClick: onClick
  }, /*#__PURE__*/React__default.createElement(IconFont, {
    type: "icon-S_View_FilePerson"
  }), title));
}
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(Button, {
    onClick: onClick
  }, /*#__PURE__*/React__default.createElement(IconFont, {
    type: "icon-S_View_FilePerson"
  }), title));
}
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(Button, {
    onClick: onClick
  }, /*#__PURE__*/React__default.createElement(IconFont, {
    type: "icon-S_Photo_Relationship"
  }), title));
}
function VehiclePlateSearch({
  title = '车牌检索',
  history,
  ...data
}) {
  const onClick = useCallback(e => {
    e.stopPropagation();
    let {
      plateNo,
      tags
    } = data;
    const imagePath = data && (data.vehicleUrl || data.sceneUrl || data.url || data.pictureUrl || data.scenePath || data.imageUrl);
    const dbId = uuid();
    const dataDb = {
      id: dbId,
      defaultUrl: imagePath,
      frameUrl: imagePath,
      plateNo,
      tags
    };
    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(Button, {
    onClick: onClick
  }, /*#__PURE__*/React__default.createElement(IconFont, {
    type: "icon-LicensePlateNumber"
  }), title));
}
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
  },
  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', 'vehiclePlateSearch', 'vehicleSearch', 'nonVehicleSearch', 'vehicleFile'];
}
function CaptureTools({
  leftExtContent,
  rightExtContent,
  onlyTools,
  filterTools,
  ...data
}) {
  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: "capture-tools-layout"
  }, leftExtContent, toools.map(item => /*#__PURE__*/React__default.createElement(LinkItem, _extends({}, data, {
    history: history,
    typeKey: item,
    key: item,
    linkConfig: ItemConfig
  }))), rightExtContent);
}

export { CaptureTools as C, LinkItem as L };
//# sourceMappingURL=index-19c4ec5b.js.map
