import { _ as _extends } from '../_rollupPluginBabelHelpers-736b301a.js';
import React__default, { Component } from 'react';
import moment from 'moment';
import { message, Radio, Tooltip, Button, Select } from 'antd';
import { cache, formatTimeStamp, SocketEmitter, imageMethods, fullScreenHelper } from '@zenview/micro-utils';
import { Service, Dict, Shared, BaseStore, LMConfig } from '@zenview/micro-basic-library';
import CaptureImgView from '../CaptureImgView/index.js';
import IconFont from '../IconFont/index.js';
import ContentBox from '../ContentBox/index.js';
import LMap from '../LMap/index.js';
import Player from '../Player/index.js';
import ___default, { compact } from 'lodash';
import '../Picture/index.js';
import '../MoveContent/index.js';
import 'add-dom-event-listener';
import '../FullScreen/index.js';
import '../index-19c4ec5b.js';
import '../AuthComponent/index.js';
import 'react-router-dom';
import '../index-4c050215.js';
import '../BetweenBox/index.js';
import 'leaflet';
import '../index-33416316.js';
import '../SearchInput/index.js';
import '../LabelValue/index.js';
import 'geometric';
import 'turf';
import '@src/libs/echarts-leaflet';
import 'leaflet/dist/leaflet.css';
import 'mapbox-gl-leaflet';
import 'react-dom';
import '../DeviceList/index.js';
import '../index-6ef7005c.js';
import '../index-f41abfce.js';
import 'react-virtualized';
import '../CBox/index.js';
import '../TreeTitle/index.js';
import '../HightLevel/index.js';
import '../ImageView/index.js';
import 'leaflet.zv.markercluster';
import 'leaflet.zv.markercluster/dist/MarkerCluster.Default.css';
import 'leaflet.zv.markercluster/dist/MarkerCluster.css';
import '../PlaceTree/index.js';
import '../Tree/index.js';
import '../index-71189681.js';
import '../_commonjsHelpers-e7b0df42.js';
import 'react-is';
import 'mobx-react';
import '../DeviceAndPlace/index.js';
import '../index-fcf1ad06.js';
import '../IconSpan/index.js';
import '@cloud-app-dev/mpegts.js';
import 'hls.js';
import 'ahooks';
import 'lamejs';
import '../RangePicker/index.js';
import '../Title/index.js';
import 'rc-queue-anim';
import '../Modal/index.js';
import '../waterMakeDom-7959ac3b.js';
import '../mobx.esm-dee4cf9f.js';
import 'js-audio-recorder';

const getHeaders = () => {
  return {
    Authorization: cache.getCache('token', 'session')
  };
};
class ServiceHttp {
  constructor() {
    /**
     * @desc 上传 (运营中心和用户用)
     */
    this.uploadImg = data => {
      return Service.$httpMultiPartInstance({
        requestId: 'uploadImg',
        headers: getHeaders(),
        method: 'post',
        url: `/api/user/v1/img/uploadImg`,
        data
      });
    };
  }
  /**
   * @desc 查询设备详细信息 cid
   * @param {*} cid
   */
  queryDeviceInfoByCid(cid, cancelHttp) {
    return Service.$http({
      requestId: 'getDeviceByCId',
      headers: getHeaders(),
      url: `/api/device/v1/getDeviceByCId/${cid}`,
      method: 'post',
      data: {
        cid
      },
      cancelHttp
    });
  }
  /**
   * 获取收藏图片的列表-简版
   */
  querySimplePictureFavorites(options) {
    return Service.$http({
      requestId: 'querySimplePictureFavorites',
      headers: getHeaders(),
      method: 'post',
      url: `/api/user/favorite/v1/querySimplePictureFavorites`,
      data: options
    });
  }
  /**
   * 删除图片
   * @param {*} options
   */
  deleteFavorite(id) {
    return Service.$http({
      requestId: 'deleteFavorite',
      headers: getHeaders(),
      method: 'post',
      url: `/api/user/favorite/v1/deleteFavorite`,
      data: {
        id,
        favoriteType: 3
      }
    });
  }
  /**
   * 新增图片收藏
   * @param {*} options
   */
  addPictureFavorite(options) {
    return Service.$http({
      requestId: 'addPictureFavorite',
      headers: getHeaders(),
      method: 'post',
      url: `/api/user/favorite/v1/addPictureFavorite`,
      data: options
    });
  }
  queryCaptureAllTargetByImgId(data) {
    return Service.$http({
      url: `/api/disa/v1/allTarget/queryCaptureAllTargetByImgId`,
      method: 'post',
      data,
      headers: getHeaders(),
      requestId: 'queryCaptureAllTargetByImgId'
    });
  }
}
var ServiceHttp$1 = new ServiceHttp();

function formartRects(data, type, dicts, typeCodes = []) {
  let rects = [];
  let rect = {
    default: true,
    needExpand: true,
    isDefault: true,
    smId: data.id,
    feature: data.feature || data.faceFeature || data.bodyFeature
  };
  const tags = getDictForTagInfo$1(dicts, data.personTags || [], typeCodes);
  // 以下为图库、布控中心、订阅中心字段兼容
  if (data.faceRect) {
    rects.push({
      type: 'face',
      rect: data.faceRect.split(','),
      value: data.faceRect,
      url: data.faceUrl,
      tags,
      ...rect
    });
  }
  if (data.bodyRect) {
    rects.push({
      type: 'body',
      rect: data.bodyRect.split(','),
      value: data.bodyRect,
      url: data.bodyUrl,
      tags,
      ...rect
    });
  }
  if (data.vehicleRect) {
    if (data.vehicleType === '0') {
      rects.push({
        type: 'vehicle',
        rect: data.vehicleRect.split(','),
        value: data.vehicleRect,
        url: data.vehicleUrl,
        ...rect
      });
    }
    if (data.vehicleType === '1') {
      rects.push({
        type: 'nonVehicle',
        rect: data.vehicleRect.split(','),
        value: data.vehicleRect,
        url: data.vehicleUrl,
        ...rect
      });
    }
  }
  // 以下为防控任务 -- 无帽进入后厨字段兼容
  try {
    let extraInfo = JSON.parse(data.extraInfo);
    if (extraInfo.face_rect) {
      rects.push({
        type: 'face',
        value: extraInfo.face_rect.replaceAll('.0', '').split(','),
        rect: extraInfo.face_rect.replaceAll('.0', '').split(','),
        url: data.sceneUrl,
        ...rect,
        feature: extraInfo.face_feature
      });
    }
    if (extraInfo.body_rect) {
      rects.push({
        type: 'body',
        value: extraInfo.body_rect.replaceAll('.0', '').split(','),
        rect: extraInfo.body_rect.replaceAll('.0', '').split(','),
        url: data.sceneUrl,
        ...rect,
        feature: extraInfo.body_feature
      });
    }
  } catch (error) {}
  // 以下为防控任务 -- 除人员入侵、无帽进入后厨字段兼容
  if (type === 'thing' && data.rects && data.rects.length) {
    data.rects.forEach(rect => {
      rects.push({
        type: 'thing',
        value: rect,
        url: data.imageUrl,
        default: true
      });
    });
  }
  return rects;
}
function getDictForTagInfo$1(dicts, tags, typeCodes = []) {
  let tagInfos = [];
  for (let i = 0, l = dicts.length; i < l; i++) {
    const item = dicts[i];
    for (let i = 0, l = tags.length; i < l; i++) {
      const tag = tags[i];
      const tagInfo = item.find(v => +v.code === +tag);
      if (tagInfo) {
        let icon = tagInfo.icon;
        if (!icon) {
          const findIcon = typeCodes.find(type => type.icon && type.code === tagInfo.typeCode);
          icon = findIcon ? findIcon.icon : '';
        }
        tagInfos.push({
          ...tagInfo,
          icon
        });
        break;
      }
    }
  }
  return tagInfos;
}

/**
 * 走下载审批流程
 * @param {*} param
 */
function downloadImg({
  data,
  imagePath
}) {
  data.uploadImgUrl = imagePath;
  const modelInfoOfApply = {
    applyPicsItem: [data],
    dataArray: {
      downloadContent: [{
        label: '下载类型',
        value: '图片'
      }, {
        label: '设备名称',
        value: data.deviceName || data.cameraName
      }, {
        label: '抓拍时间',
        value: formatTimeStamp(data.captureTime)
      }],
      imageDetails: [{
        url: data.uploadImgUrl
      }]
    },
    isApply: true,
    title: '下载申请'
  };
  SocketEmitter.emit('applyUploadModal', modelInfoOfApply);
}

//收藏类型
function getPictureType(data, type) {
  let pictureType = '1';
  switch (type) {
    case 'face':
      pictureType = '2';
      break;
    case 'personAlarm':
      pictureType = '2';
      break;
    case 'body':
      pictureType = '3';
      break;
    case 'eventAlarm':
      pictureType = '3';
      break;
    case 'vehicle':
      pictureType = '4';
      break;
    case 'nonVehicle':
      pictureType = '4';
      break;
  }
  // 无帽进入特殊处理
  if (data.taskType === '101509') {
    pictureType = '3';
  }
  // 防控中心非机动车收藏特殊处理
  if (type === 'thing' && data.type === '101510') {
    pictureType = '4';
  }
  // 布控中心车辆布控告警收藏特殊处理
  if (data.taskType === '101501' || data.taskType === '101502') {
    pictureType = '4';
  }
  return pictureType;
}

// 添加图片收藏
async function addPictureFavorite(options) {
  if (options.scenceImageUrl.indexOf('data:image') >= 0) {
    // 图片地址为base64则先上传至羚羊再添加到mediaList
    const oldFile = imageMethods.base64ToBlob(options.scenceImageUrl);
    const formData = new FormData();
    formData.append('file', oldFile);
    await ServiceHttp$1.uploadImg(formData).then(res => {
      if (res.code !== 0) {
        return false;
      }
      options.scenceImageUrl = options.smallImageUrl = res.data.url;
    });
  }
  return ServiceHttp$1.addPictureFavorite(options);
}

const faceTypeName = [{
  code: '100000',
  label: '性别',
  name: 'sex'
}, {
  code: '100800',
  label: '年龄段',
  name: 'generation'
}, {
  code: '119000',
  label: '是否戴帽子或头盔',
  name: 'hat'
}, {
  code: '112000',
  label: '头部特征',
  name: 'head'
}, {
  code: '112800',
  label: '是否戴眼镜',
  name: 'eyeGlass'
}, {
  code: '100250',
  label: '是否戴口罩',
  name: 'faceMask'
}, {
  code: '112400',
  label: '上身颜色',
  name: 'upperColor'
}, {
  code: '112100',
  label: '上身纹理',
  name: 'upperTexture'
}, {
  code: '119010',
  label: '是否戴墨镜',
  name: 'sunglasses'
}, {
  code: '121150',
  label: '肤色',
  name: 'skinColorTags'
}, {
  code: '121170',
  label: '面部情绪',
  name: 'faceMoodTags'
}, {
  code: '120970',
  label: '上衣类型',
  name: 'upperClothesTags'
}, {
  code: '119100',
  label: '所在区域',
  name: 'cameraTags'
}];
const bodyTypeName = [{
  code: '100000',
  label: '性别',
  name: 'sex'
}, {
  code: '100800',
  label: '年龄段',
  name: 'generation'
}, {
  code: '119000',
  label: '是否戴帽子或头盔',
  name: 'hat'
}, {
  code: '112000',
  label: '头部特征',
  name: 'head'
}, {
  code: '112800',
  label: '是否戴眼镜',
  name: 'eyeGlass'
}, {
  code: '100250',
  label: '是否戴口罩',
  name: 'faceMask'
}, {
  code: '112400',
  label: '上身颜色',
  name: 'upperColor'
}, {
  code: '112100',
  label: '上身纹理',
  name: 'upperTexture'
}, {
  code: '119010',
  label: '是否戴墨镜',
  name: 'sunglasses'
}, {
  code: '112300',
  label: '随身物品',
  name: 'personalEffectsTags'
}, {
  code: '120970',
  label: '上衣类型',
  name: 'upperClothesTags'
}, {
  code: '112200',
  label: '下身类别',
  name: 'lowerTexture'
}, {
  code: '102600',
  label: '下身服饰',
  name: 'lowerBodyClothing'
}, {
  code: '112500',
  label: '下身颜色',
  name: 'lowerColor'
}, {
  code: '120980',
  label: '鞋子类型',
  name: 'shoesTypeTags'
}, {
  code: '131730',
  label: '鞋子颜色',
  name: 'shoesColorTags'
}, {
  code: '120960',
  label: '发型',
  name: 'hairstyleTags'
}, {
  code: '119100',
  label: '所在区域',
  name: 'cameraTags'
}];
const vehicleTypeName = [{
  code: '117100',
  label: '机动车品牌',
  name: 'vehicleBrands'
}, {
  code: '117500',
  label: '机动车类型',
  name: 'vehicleType'
}, {
  code: '118800',
  label: '车牌类型',
  name: 'plateTypeTags'
}, {
  code: '117750',
  label: '车牌颜色',
  name: 'plateColor'
}, {
  code: '119380',
  label: '汽车车身',
  name: 'vehicleBodyTags'
}, {
  code: '119320',
  label: '车身颜色',
  name: 'vehicleColor'
}, {
  code: '119200',
  label: '汽车配饰',
  name: 'accessoryTags'
}, {
  code: '119370',
  label: '乘车人状态',
  name: 'abnormalTags'
}, {
  code: '121050',
  label: '车牌遮挡',
  name: 'plateOcclusionTags'
}, {
  code: '121070',
  label: '面部遮挡',
  name: 'faceOcclusionTags'
}, {
  code: '119390',
  label: '副驾是否有人',
  name: 'copilotCode'
}, {
  code: '116350',
  label: '车辆抓拍方向',
  name: 'directionCode'
}, {
  code: '119100',
  label: '所在区域',
  name: 'cameraTags'
}];
const nonVehicleTypeName = [{
  code: '100000',
  label: '性别',
  name: 'sex'
}, {
  code: '100800',
  label: '年龄段',
  name: 'generation'
}, {
  code: '112000',
  label: '头部特征',
  name: 'head'
}, {
  code: '119280',
  label: '非机动车车型',
  name: 'nonMotorVehicleModel'
}, {
  code: '119320',
  label: '车身颜色',
  name: 'vehicleColor'
}, {
  code: '119300',
  label: '上身纹理',
  name: 'upperColorType'
}, {
  code: '112400',
  label: '上身颜色',
  name: 'upperColor'
}, {
  code: '119240',
  label: '非机动车车辆角度',
  name: 'directionTags'
}, {
  code: '119350',
  label: '违法载人',
  name: 'illegalMannedTags'
}, {
  code: '120960',
  label: '发型',
  name: 'hairstyleTags'
}, {
  code: '120970',
  label: '上衣类型',
  name: 'upperClothesTags'
}, {
  code: '119260',
  label: '非机动车包款式',
  name: 'nonMotorVehicleType'
}, {
  code: '119100',
  label: '所在区域',
  name: 'cameraTags'
}];
function formatRectInfo(structuredInfo, id, typeCodes, defaultRect = []) {
  const {
    persons,
    vehicles,
    boundaries
  } = structuredInfo || {};
  let targetRect = '';
  try {
    targetRect = defaultRect[0].rect.join(',') || '';
  } catch (error) {}
  const rects = [];
  if (persons) {
    persons.forEach(item => {
      let personTags = item.personTags && item.personTags.filter(tag => tag.length === 6) || [];
      let faceDicts = [],
        bodyDicts = [];
      getTargetTag(faceTypeName, faceDicts);
      getTargetTag(bodyTypeName, bodyDicts);
      let faceTags = getDictForTagInfo(faceDicts, personTags || [], typeCodes);
      let bodyTags = getDictForTagInfo(bodyDicts, personTags || [], typeCodes);
      if (item.faceRect) {
        rects.push({
          imgId: item.imgId,
          smId: item.id,
          imgUrl: item.faceUrl,
          type: 'face',
          rect: item.faceRect.split(',').map(v => +v) || [],
          needExpand: true,
          tags: ___default.orderBy(faceTags, ['typeCode'], ['asc']),
          // isDefault: id === item.id,
          isDefault: targetRect == item.faceRect,
          feature: item.faceFeature,
          lowQuality: item === null || item === void 0 ? void 0 : item.faceLowQuality,
          dupId: item === null || item === void 0 ? void 0 : item.dupId
        });
      }
      if (item.bodyRect) {
        rects.push({
          imgId: item.imgId,
          smId: item.id,
          imgUrl: item.bodyUrl,
          type: 'body',
          rect: item.bodyRect.split(',').map(v => +v) || [],
          needExpand: true,
          tags: ___default.orderBy(bodyTags, ['typeCode'], ['asc']),
          // isDefault: id === item.id,
          isDefault: targetRect == item.bodyRect,
          feature: item.bodyFeature,
          lowQuality: item === null || item === void 0 ? void 0 : item.bodyLowQuality,
          dupId: item === null || item === void 0 ? void 0 : item.dupId
        });
      }
    });
  }
  if (vehicles) {
    vehicles.forEach(item => {
      const type = item.vehicleType === 0 ? 'vehicle' : 'nonVehicle';
      let tags = item.vehicleTags && item.vehicleTags.filter(tag => tag.length === 6) || [];
      let vehicleDicts = [],
        nonVehicleDicts = [];
      getTargetTag(vehicleTypeName, vehicleDicts);
      getTargetTag(nonVehicleTypeName, nonVehicleDicts);
      let vehicleTags = getDictForTagInfo(vehicleDicts, tags || [], typeCodes);
      let nonVehicleTags = getDictForTagInfo(nonVehicleDicts, tags || [], typeCodes);
      rects.push({
        imgId: item.imgId,
        smId: id,
        type,
        imgUrl: item.vehicleUrl,
        feature: item.feature,
        tags: item.vehicleType === 0 ? ___default.orderBy(vehicleTags, ['typeCode'], ['asc']) : ___default.orderBy(nonVehicleTags, ['typeCode'], ['asc']),
        rect: item.vehicleRect ? item.vehicleRect.split(',').map(v => +v) : [],
        // isDefault: id === item.id,
        isDefault: targetRect == item.vehicleRect,
        lowQuality: item.vehicleLowQuality,
        dupId: item.dupId
      });
    });
  }
  if (boundaries && boundaries.length) {
    boundaries.forEach(item => {
      item.map(polygonAreaItem => {
        if (polygonAreaItem.polygonArea) {
          try {
            polygonAreaItem.polygonArea = polygonAreaItem.polygonArea.map(v => JSON.parse(v));
          } catch (error) {
            console.error(error);
          }
        }
        return polygonAreaItem;
      });
      rects.push({
        type: 'roi',
        boundaries: item
      });
    });
  }
  return rects;
}

/**
 * 过滤要显示的tag
 */
function getTargetTag(filterTag, result = []) {
  let allDict = {};
  try {
    allDict = Dict.cacheMap.data;
  } catch (error) {}
  filterTag.forEach(v => {
    let tag = allDict[v.code];
    tag && result.push(tag);
  });
}

/**
 * 获取显示tag的icon信息
 */
function getDictForTagInfo(dicts = [], tags, typeCodes = []) {
  let tagInfos = [];
  for (let i = 0, l = dicts.length; i < l; i++) {
    const item = dicts[i];
    for (let i = 0, l = tags.length; i < l; i++) {
      const tag = tags[i];
      const tagInfo = item.find(v => +v.code === +tag);
      if (tagInfo) {
        let icon = tagInfo.icon;
        if (!icon) {
          const findIcon = typeCodes.find(type => type.icon && type.code === tagInfo.typeCode);
          icon = findIcon ? findIcon.icon : '';
        }
        tagInfos.push({
          ...tagInfo,
          icon
        });
        break;
      }
    }
  }
  return tagInfos;
}

var _dec, _class;
const radioArray = [{
  label: '看图片',
  value: 'image',
  iconType: 'icon-S_Photo_ContentsImage'
}, {
  label: '看视频',
  value: 'video',
  iconType: 'icon-S_Photo_ContentsVideo1'
}, {
  label: '看地图',
  value: 'map',
  iconType: 'icon-S_Photo_ContentsMap'
}];
let DetailPictureMap = (_dec = Dict.withTypeCodes, _dec(_class = class DetailPictureMap extends Component {
  constructor(props) {
    super(props);
    this.getDefaultRects = () => {
      let {
        data,
        type,
        dicts
      } = this.props;
      let typeCodes = [];
      try {
        typeCodes = dicts.typeCodes || this.props.typeCodes;
      } catch (error) {}
      let rects = formartRects(data, type, dicts, typeCodes);
      this.setState({
        rects
      }, () => {
        data.imgId && this.queryCaptureAllTargetByImgId(data.imgId);
      });
    };
    this.queryCaptureAllTargetByImgId = imgId => {
      let {
        data,
        defaultId,
        dicts
      } = this.props;
      let {
        rects
      } = this.state;
      let typeCodes = [];
      try {
        typeCodes = dicts.typeCodes || this.props.typeCodes;
      } catch (error) {}
      ServiceHttp$1.queryCaptureAllTargetByImgId({
        imgId
      }).then(res => {
        let structuredInfo = res.data;
        let allRects = formatRectInfo(structuredInfo, defaultId || data.id, typeCodes, rects);
        this.setState({
          rects: [...rects, ...allRects]
        });
      });
    };
    this.changeRadioType = e => {
      const radioType = e.target.value;
      if (radioType === 'video') {
        const {
          overdue,
          videoReady
        } = this.state.videoOptions;
        if (overdue) {
          return message.warn('视频已过期');
        }
        if (!videoReady && !overdue) {
          return;
        }
        this.queryHistoryAddress();
      }
      this.setState({
        radioType
      });
    };
    this.frameSelectJumpPage = params => {
      let {
        history
      } = this.props;
      const {
        defaultUrl,
        frameUrl,
        searchData = {},
        defaultRect: defaultItem,
        rects
      } = params;
      const pageInfo = Shared.resourcePageInfo[params.moduleName];
      const fnName = pageInfo.fnName;
      const {
        startTime,
        endTime,
        imgId,
        id
      } = searchData;
      Shared[fnName]({
        history,
        id,
        imgId,
        frameUrl,
        defaultUrl,
        startTime,
        endTime,
        rects,
        defaultItem
      });
    };
    // 看视频相关方法：
    // 设置视频参数
    this.setVideoOptions = (options = {}) => {
      this.setState({
        videoOptions: {
          ...this.state.videoOptions,
          ...options
        }
      });
    };
    // 初始化视频相关参数
    this.initVideoOptions = async () => {
      let {
        data,
        isAccessControl
      } = this.props;
      if (isAccessControl) {
        // 是否是门禁
        return data.videoUrl && this.setVideoOptions({
          videoReady: true,
          overdue: false
        });
      }
      const storageLimit = await this.queryStorageLimit(data);
      const {
        systemTime
      } = BaseStore.app;
      // 视频是否已过期
      if (systemTime - data.captureTime > storageLimit * 24 * 60 * 60 * 1000) {
        return this.setVideoOptions({
          overdue: true
        });
      }
      // 视频是否生成中
      if (systemTime - data.captureTime > 60000) {
        return this.setVideoOptions({
          videoReady: true
        });
      }
      this.videoTimer = setTimeout(() => {
        this.setVideoOptions({
          videoReady: true
        });
      }, systemTime - data.captureTime);
    };
    // 获取历史视频
    this.queryHistoryAddress = async () => {
      const {
        associationCids
      } = this.state;
      const {
        data
      } = this.props;
      let arr = [];
      if (associationCids && associationCids.length) {
        arr = associationCids;
      } else {
        arr = [data.cid];
      }
      this.setState({
        fileDatas: arr.map(v => ({
          cid: v
        }))
      }, () => {
        arr.forEach((item, k) => {
          this.setFileDatas(item, k);
        });
      });

      // let fileData = await this.setFileDatas(cid)
      // let options = { fileData }
      // if (cid2) {
      //   let fileData2 = await this.setFileDatas(cid2)
      //   options.fileData2 = fileData2
      // }
      // this.setState(options)
    };
    this.setFileDatas = (cid, k) => {
      const {
        switchTime,
        nextTimes,
        fileDatas
      } = this.state;
      const {
        data,
        afterTime = switchTime,
        beforeTime = switchTime
      } = this.props;
      const deviceData = BaseStore.device.getDeviceByCId(cid) || {};
      const option = {
        cid: cid,
        deviceName: deviceData.deviceName || deviceData.cameraName,
        // 接口返回有的还用cameraName
        startTime: parseInt(data.captureTime / 1000) - beforeTime + nextTimes,
        endTime: parseInt(data.captureTime / 1000) + afterTime + nextTimes
      };
      const paramsObj = {
        startTime: option.startTime,
        endTime: option.endTime,
        deviceInfo: {
          cid: option.cid,
          deviceName: option.deviceName,
          isFrontEnd: !deviceData.hasStorage
        }
      };
      Shared.getVideoRecord(paramsObj).then(videoRes => {
        let res = BaseStore.device.getDeviceByCId(option.cid);
        let fileData = this.getVideoFileDatas(res, videoRes, option);
        if (fileDatas[k]) {
          fileDatas[k].fileData = fileData;
        } else {
          fileDatas[k] = {
            fileData,
            cid: option.cid
          };
        }
        this.setState({
          fileDatas
        });
      });

      // return this.getVideoFileDatas(res, videoRes, option);
    };
    // 组合视频数据
    this.getVideoFileDatas = (res, item, option) => {
      return Object.assign({}, res, {
        historyList: item,
        isLiving: false,
        startTime: option.startTime,
        endTime: option.endTime,
        videoGroupType: option.videoGroupType
      });
    };
    // 查询过期时间
    this.queryStorageLimit = async data => {
      let storageLimit;
      try {
        const result = await ServiceHttp$1.queryDeviceInfoByCid(data.cid);
        storageLimit = +result.data.extJson.cameraInfo.storage.video || 7;
      } catch (_unused) {
        storageLimit = 7;
      }
      return storageLimit;
    };
    // 获取视频 Tab 提示信息
    this.getVideoRadioTitle = () => {
      const {
        overdue,
        videoReady
      } = this.state.videoOptions;
      if (!overdue && !videoReady) {
        return {
          disabeld: true,
          label: '看视频'
        };
      }
      if (overdue) {
        return {
          disabeld: true,
          label: '视频已过期'
        };
      }
      if (!videoReady) {
        return {
          disabeld: true,
          label: '视频生成中，请稍后再试'
        };
      }
      return {
        disabeld: false,
        label: '看视频'
      };
    };
    //下载图片
    this.imgDownload = () => {
      fullScreenHelper.exitFullscreen();
      const {
        funcConfig: {
          imageDownloadApprove = true
        }
      } = LMConfig.BSConfig;
      // 是否经过审批流
      const {
        data = {}
      } = this.props;
      const imagePath = data && (data.sceneUrl || data.url || data.pictureUrl || data.scenePath || data.imageUrl);
      const downloadName = this.props.downloadName || `${data.deviceName}_${moment(+data.captureTime).format('YYYYMMDDTHHmmss')}`;
      Service.logger.save({
        description: `下载【${data.deviceName || data.cameraName}】【${formatTimeStamp(data.captureTime)}】的抓拍图片`,
        module: 104100,
        function: 104108
      });
      if (imageDownloadApprove) {
        downloadImg({
          data,
          imagePath
        });
      } else {
        imageMethods.downloadLocalImage(imagePath, downloadName);
      }
    };
    // 获取所有收藏图片
    this.querySimplePictureFavorites = imgId => {
      const options = {
        pictureTypes: [1, 2, 3, 4]
      };
      ServiceHttp$1.querySimplePictureFavorites(options).then(res => {
        const data = res.data || [];
        const mediaImageListIds = data.map(v => v.pictureId);
        const obj = {
          mediaImageListIds,
          mediaImageListLevel: data // 完整数据
        };
        this.pictureCollection = obj;
        cache.setCache('pictureCollection', JSON.stringify(obj), 'session');
        if (imgId) this.initCollectStatus(imgId);
      });
    };
    /**
     * @desc 判断图片收藏状态
     */
    this.initCollectStatus = (imgId = this.props.data.imgId) => {
      if (imgId) {
        var _this$pictureCollecti;
        const collectStatus = (_this$pictureCollecti = this.pictureCollection) === null || _this$pictureCollecti === void 0 ? void 0 : _this$pictureCollecti.mediaImageListIds.includes(imgId);
        if (collectStatus) {
          this.setState({
            collectStatus
          });
        }
      }
    };
    this.handleCollectiton = event => {
      const {
        collectStatus
      } = this.state;
      if (collectStatus) {
        this.cancelCollection();
      } else {
        this.addCollection(event);
      }
    };
    /**
     * @desc 取消收藏
     */
    this.cancelCollection = () => {
      const {
        data
      } = this.props;
      // 根据pictureId反查id
      const collectItem = this.pictureCollection.mediaImageListLevel.find(v => v.pictureId === data.imgId || v.pictureId === data.captureId);
      if (collectItem !== null && collectItem !== void 0 && collectItem.id) {
        ServiceHttp$1.deleteFavorite(collectItem.id).then(res => {
          if (res.code === 0) {
            Service.logger.save({
              description: `取消收藏【${collectItem.deviceName}】【${formatTimeStamp(collectItem.captureTime)}】的抓拍图`,
              module: 107300,
              function: 107303
            });
            this.querySimplePictureFavorites();
            this.setState({
              collectStatus: false
            });
          }
        });
      }
    };
    /**
     * @desc 添加收藏
     */
    this.addCollection = () => {
      const {
        data,
        type
      } = this.props;
      const pictureType = getPictureType(data, type);
      let cameraInfo = BaseStore.device.getDeviceByCId(data.cid) || BaseStore.device.getDeviceById(data.deviceId) || BaseStore.device.getDeviceById(data.cameraId) || {};
      const mediaOption = {
        pictureId: data.imgId || data.captureId,
        deviceId: cameraInfo.id || data.deviceId || data.cameraId || data.cid,
        deviceName: data.deviceName || cameraInfo.deviceName,
        captureTime: +data.captureTime,
        scenceImageUrl: data.sceneUrl || data.url || data.pictureUrl || data.scenePath || data.imageUrl,
        smallImageUrl: data.sceneUrl || data.url || data.pictureUrl || data.scenePath || data.imageUrl,
        pictureType,
        source: 2
      };
      if (!mediaOption.scenceImageUrl) return message.warn('图片资源获取失败');
      addPictureFavorite(mediaOption).then(res => {
        if (res.code === 0) {
          Service.logger.save({
            description: `收藏【${mediaOption.deviceName}】【${formatTimeStamp(mediaOption.captureTime)}】的抓拍图`,
            module: 107300,
            function: 107301
          });
          this.querySimplePictureFavorites();
          this.setState({
            collectStatus: true
          });
        }
      }).catch(err => {
        message.error('收藏失败');
      });
    };
    this.downloadVideo = (options, fileData) => {
      const {
        data
      } = this.props;
      Service.logger.save({
        description: `下载【${data.deviceName || data.cameraName}】【${formatTimeStamp(data.captureTime)}】的历史视频`,
        module: 104100,
        function: 104107
      });
      this.props.downloadVideo && this.props.downloadVideo({
        fileData,
        ...options
      });
    };
    // 快进/后退 s
    this.videoSwitch = times => {
      const {
        nextTimes
      } = this.state;
      this.setState({
        nextTimes: nextTimes + times
      }, () => {
        this.queryHistoryAddress();
      });
    };
    //时间段
    this.timeRangeChange = value => {
      this.setState({
        switchTime: value
      }, () => {
        this.queryHistoryAddress();
      });
    };
    this.videoTimer = null;
    this.state = {
      associationCids: [],
      radioType: 'image',
      // 当前选中的查看类型
      fileData: {},
      fileDatas: [],
      collectStatus: false,
      videoOptions: {
        overdue: false,
        // 视频已过期
        videoReady: false // 视频可以播放
      },
      rects: [],
      switchTime: 5,
      nextTimes: 0
    };
  }
  async componentDidMount() {
    var _BaseStore$device$get;
    const {
      resourceLibrary: {
        detailVideoSwitchTimes
      }
    } = LMConfig.BSConfig;
    this.setState({
      switchTime: detailVideoSwitchTimes || this.state.switchTime
    });
    const {
      data,
      setAssociationCids
    } = this.props;
    const imgId = data.imgId || data.captureId;
    const pictureCollection = cache.getCache('pictureCollection', 'session');
    if (pictureCollection) {
      this.pictureCollection = JSON.parse(pictureCollection);
      this.initCollectStatus(imgId);
    } else this.querySimplePictureFavorites(imgId);
    // 进入详情时会走两次didMount，第二次data才有数据
    data.cid && this.initVideoOptions();
    const id = (_BaseStore$device$get = BaseStore.device.getDeviceByCId(data.cid)) === null || _BaseStore$device$get === void 0 ? void 0 : _BaseStore$device$get.id;
    if (id) {
      let deviceRes = await ServiceHttp$1.queryDeviceInfoByCid(data.cid);
      const {
        associationCids
      } = deviceRes.data || {};
      this.setState({
        associationCids: associationCids && compact(associationCids).filter(v => +v !== 0)
      }); //:['563020370','563019785']
      // this.setState({ associationCids }) //:['563020370','563019785']
      setAssociationCids && setAssociationCids(associationCids);
    }
    this.getDefaultRects();
    Service.logger.save({
      description: `查看【${data.deviceName || data.cameraName}】【${formatTimeStamp(data.captureTime)}】的抓拍图`,
      module: 104100,
      function: 104105
    });
  }
  componentWillUnmount() {
    clearTimeout(this.videoTimer);
  }
  render() {
    const {
      radioType,
      collectStatus,
      rects,
      switchTime,
      // fileData, fileData2,
      associationCids,
      fileDatas
    } = this.state;
    const {
      data = {},
      type = 'face'
    } = this.props;
    // const { historyList, startTime, endTime, cid, deviceName } = fileData;
    const videoInfo = this.getVideoRadioTitle();
    const mutPlayerFlag = associationCids && associationCids.length >= 2;
    return /*#__PURE__*/React__default.createElement(ContentBox.InfoBox, {
      className: "lm-c-detail-picture-map",
      contentStyle: {
        display: 'flex',
        flexDirection: 'column'
      }
    }, /*#__PURE__*/React__default.createElement("div", {
      className: "detail-header"
    }, /*#__PURE__*/React__default.createElement(Radio.Group, {
      buttonStyle: "solid",
      value: radioType,
      onChange: this.changeRadioType
    }, radioArray.map(v => /*#__PURE__*/React__default.createElement(Radio.Button, {
      value: v.value,
      key: v.value,
      disabled: v.value === 'video' ? videoInfo.disabeld : false
    }, /*#__PURE__*/React__default.createElement(IconFont, {
      type: v.iconType
    }), /*#__PURE__*/React__default.createElement("span", null, v.value === 'video' ? videoInfo.label : v.label))))), radioType === 'image' && type !== 'accessControl' && /*#__PURE__*/React__default.createElement(Tooltip, {
      title: `${collectStatus ? '取消' : ''}收藏`
    }, /*#__PURE__*/React__default.createElement(IconFont, {
      className: `collection-icon ${collectStatus ? 'active' : ''}`,
      type: "icon-S_Photo_KeepYes",
      onClick: this.handleCollectiton
    })), /*#__PURE__*/React__default.createElement("div", {
      className: `detail-content ${mutPlayerFlag ? ' mut-player' : ''}`
    }, /*#__PURE__*/React__default.createElement("div", {
      className: `detail-content-part  ${radioType === 'image' ? 'detail-show-part' : 'detail-hide-part'}`
    }, /*#__PURE__*/React__default.createElement(CaptureImgView, _extends({
      imagePath: data && (data.sceneUrl || data.url || data.pictureUrl || data.scenePath || data.imageUrl),
      rects: rects,
      data: data,
      type: type,
      frameSelectJumpPage: this.frameSelectJumpPage,
      minHeight: 550,
      imgDownload: this.imgDownload
    }, this.props))), radioType === 'video' && /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("div", {
      className: `detail-content-part detail-content-part-video detail-show-part`
    }, fileDatas.map(item => {
      const {
        cid,
        fileData
      } = item;
      const {
        historyList,
        startTime,
        endTime,
        deviceName
      } = fileData || {};
      return /*#__PURE__*/React__default.createElement(Player, {
        key: cid,
        historyList: historyList,
        isLive: false,
        title: deviceName,
        cid: cid,
        startTime: startTime,
        endTime: endTime,
        downloadVideo: options => this.downloadVideo(options, fileData),
        history: this.props.history
      });
    })), /*#__PURE__*/React__default.createElement("div", {
      className: "fotter-btn"
    }, /*#__PURE__*/React__default.createElement(Button, {
      type: "primary",
      onClick: () => this.videoSwitch(-switchTime)
    }, /*#__PURE__*/React__default.createElement(IconFont, {
      type: "icon-S_Arrow_LinePrev"
    }), "\u4E0A\u4E2A\u7247\u6BB5"), /*#__PURE__*/React__default.createElement(Select, {
      style: {
        margin: '0 8px'
      },
      options: [5, 10, 15, 30].map(v => ({
        label: `前后${v}秒`,
        value: v
      })),
      value: switchTime,
      onChange: this.timeRangeChange
    }), /*#__PURE__*/React__default.createElement(Button, {
      type: "primary",
      onClick: () => this.videoSwitch(switchTime)
    }, "\u4E0B\u4E2A\u7247\u6BB5", /*#__PURE__*/React__default.createElement(IconFont, {
      type: "icon-S_Arrow_LineNext"
    })))), radioType === 'map' && /*#__PURE__*/React__default.createElement("div", {
      className: `detail-content-part detail-content-part-map detail-show-part`
    }, /*#__PURE__*/React__default.createElement(LMap.SinglePointMap, {
      point: BaseStore.device.getDeviceById(data.deviceId) || BaseStore.device.getDeviceByCId(data.cid) || data
    }))));
  }
}) || _class);

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