function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import { useSetState } from 'ahooks';
import dayjs from 'dayjs';
import React, { useMemo } from 'react';
import { VmCustom, VmIframeModal, VmVideo } from "../_components";
import useGetChannels from "../_hooks/useGetChannels";
import useGetConfig from "../_hooks/useGetConfig";
import VtxBaseModal from "../vtx-base-modal";
import { BaseService, OilService } from "./api";
import { Cc, Common, JXH, Jzlj, Ljsy, Ljzy } from "./content";
import "./style";
// 总览信息
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
var TABS_BASE = 'base';
// 车辆档案
var TABS_DETAIL = 'detail';
// 报警信息
var TABS_ALARM = 'alarm';
// 运行日历
var TABS_STATIC = 'static';
// 水耗信息
var TABS_WATER = 'water';
// 油耗信息
var TABS_OIL = 'oil';
// 维保信息
var TABS_MAINTENANCE = 'maintenance';
// 视频信息
var TABS_VIDEO = 'video';
// 设备档案
var TABS_DEVICE = 'device';
// 机械化-总览信息
var TABS_JXH_BASE = 'jxh-base';
// 机械化-作业日历
var TABS_JXH_STATIC = 'jxh-static';
// 机械化-报警信息
var TABS_JXH_ALARM = 'jxh-alarm';
// 机械化-作业记录
var TABS_JXH_WORK = 'jxh-work';
// 机械化-总览信息
var TABS_JXH_BASE_HW_2 = 'jxh-base-hw2';
// 机械化-作业日历
var TABS_JXH_STATIC_HW_2 = 'jxh-static-hw2';
// 机械化-报警信息
var TABS_JXH_ALARM_HW_2 = 'jxh-alarm-hw2';
// 机械化-作业记录
var TABS_JXH_WORK_HW_2 = 'jxh-work-hw2';
// 垃圾收运-总览信息
var TABS_LJSY_BASE = 'ljsy-base';
// 垃圾收运-运行日历
var TABS_LJSY_STATIC = 'ljsy-static';
// 垃圾收运-报警信息
var TABS_LJSY_ALARM = 'ljsy-alarm';
// 垃圾收运-收运记录
var TABS_LJSY_WORK = 'ljsy-work';
// 餐厨-总览信息
var TABS_CC_BASE = 'cc-base';
// 餐厨-运行日历
var TABS_CC_STATIC = 'cc-static';
// 餐厨-报警信息
var TABS_CC_ALARM = 'cc-alarm';
// 餐厨-收运记录
var TABS_CC_WORK = 'cc-work';
// 餐厨-联单信息
var TABS_CC_ORDER = 'cc-order';
// 垃圾转运-总览信息
var TABS_LJZY_BASE = 'ljzy-base';
// 垃圾转运-统计信息
var TABS_LJZY_STATIC = 'ljzy-static';
// 垃圾转运-进厂信息
var TABS_LJZY_WORK = 'ljzy-work';

// 建筑垃圾车（渣土车）
// 建筑垃圾车-总览信息
var TABS_JZLJ_CAR_BASE = 'jzlj-car-base';
// 建筑垃圾车-处置证信息
var TABS_JZLJ_CAR_DISPOSE = 'jzlj-car-dispose';
// 建筑垃圾车-联单信息
var TABS_JZLJ_CAR_COLLECTION = 'jzlj-car-collection';
// 建筑垃圾车-报警信息
var TABS_JZLJ_CAR_ALARM = 'jzlj-car-alarm';
// 建筑垃圾车-运行日历
var TABS_JZLJ_CAR_RUNNING_CALENDAR = 'jzlj-car-running-calendar';
export var CarContext = /*#__PURE__*/React.createContext({
  id: '',
  info: {},
  detail: {},
  startDate: dayjs(),
  endDate: dayjs(),
  showFields: []
});
var Provider = CarContext.Provider;
var VtxCarModal = function VtxCarModal(props) {
  var _contents;
  var id = props.id,
    title = props.title,
    theme = props.theme,
    visible = props.visible,
    onCancel = props.onCancel,
    source = props.source,
    startDate = props.startDate,
    endDate = props.endDate,
    onTdClick = props.onTdClick,
    _props$tabChose = props.tabChose,
    tabChose = _props$tabChose === void 0 ? '' : _props$tabChose,
    _props$showCollect = props.showCollect,
    showCollect = _props$showCollect === void 0 ? true : _props$showCollect,
    _props$frameParams = props.frameParams,
    frameParams = _props$frameParams === void 0 ? {} : _props$frameParams,
    _props$defaultCode = props.defaultCode,
    defaultCode = _props$defaultCode === void 0 ? '' : _props$defaultCode,
    _props$iframeUrl = props.iframeUrl,
    iframeUrl = _props$iframeUrl === void 0 ? '' : _props$iframeUrl,
    _props$width = props.width,
    width = _props$width === void 0 ? null : _props$width;
  var _BaseService$useBaseI = BaseService.useBaseInfo(id),
    detail = _BaseService$useBaseI.detail,
    info = _BaseService$useBaseI.info;
  var _useGetChannels = useGetChannels(info === null || info === void 0 ? void 0 : info.carCode, !!(info !== null && info !== void 0 && info.carCode)),
    channels = _useGetChannels.channels;
  var _OilService$useHasOil = OilService.useHasOil(id),
    beenOilStatus = _OilService$useHasOil.beenOilStatus;
  var _BaseService$useField = BaseService.useFieldConfig(),
    showFields = _BaseService$useField.showFields;
  var code = useMemo(function () {
    var code = '';
    var actionType = info === null || info === void 0 ? void 0 : info.actionType;
    if (defaultCode) {
      code = defaultCode;
    } else if (actionType && !defaultCode) {
      if (actionType.includes('ACTION_LJSY')) {
        code = 'car-ljsy';
      } else if (actionType.includes('ACTION_JXH')) {
        code = 'car-jxh';
      } else if (actionType.includes('ACTION_CC')) {
        code = 'car-cc';
      } else if (actionType.includes('ACTION_LJZY')) {
        code = 'car-ljzy';
      } else if (actionType.includes('ACTION_ZT')) {
        code = 'jzlj-car';
      } else {
        code = 'car';
      }
    }
    return code;
  }, [defaultCode, info === null || info === void 0 ? void 0 : info.actionType]);
  var tabs = useMemo(function () {
    var tabs = [];
    var _ref = info || {},
      _ref$actionType = _ref.actionType,
      actionType = _ref$actionType === void 0 ? '' : _ref$actionType;
    if (!actionType) {
      return [];
    }
    if (actionType.includes('ACTION_LJSY')) {
      tabs = [{
        key: TABS_LJSY_BASE,
        title: '总览信息'
      }, {
        key: TABS_LJSY_STATIC,
        title: '运行日历'
      }, {
        key: TABS_LJSY_WORK,
        title: '收运记录'
      }, {
        key: TABS_LJSY_ALARM,
        title: '报警信息'
      }];
    } else if (actionType.includes('ACTION_JXH')) {
      tabs = [{
        key: TABS_JXH_BASE,
        title: '总览信息'
      }, {
        key: TABS_JXH_STATIC,
        title: '作业日历'
      }, {
        key: TABS_JXH_WORK,
        title: '作业记录'
      }, {
        key: TABS_JXH_ALARM,
        title: '报警信息'
      }];
    } else if (actionType.includes('ACTION_CC')) {
      tabs = [{
        key: TABS_CC_BASE,
        title: '总览信息'
      }, {
        key: TABS_CC_STATIC,
        title: '运行日历'
      }, {
        key: TABS_CC_WORK,
        title: '收运记录'
      }, {
        key: TABS_CC_ALARM,
        title: '报警信息'
      }];
    } else if (actionType.includes('ACTION_LJZY')) {
      tabs = [{
        key: TABS_LJZY_BASE,
        title: '总览信息'
      }, {
        key: TABS_LJZY_STATIC,
        title: '统计信息'
      }, {
        key: TABS_LJZY_WORK,
        title: '进厂信息'
      }];
    } else if (actionType.includes('ACTION_ZT')) {
      tabs = [{
        key: TABS_JZLJ_CAR_BASE,
        title: '总览信息'
      }, {
        key: TABS_JZLJ_CAR_DISPOSE,
        title: '处置证信息'
      }, {
        key: TABS_JZLJ_CAR_COLLECTION,
        title: '联单信息'
      }, {
        key: TABS_JZLJ_CAR_ALARM,
        title: '报警信息'
      }, {
        key: TABS_JZLJ_CAR_RUNNING_CALENDAR,
        title: '运输日历'
      }];
    } else {
      tabs = [{
        key: TABS_BASE,
        title: '总览信息'
      }, {
        key: TABS_STATIC,
        title: '运行日历'
      }, {
        key: TABS_ALARM,
        title: '报警信息'
      }];
    }
    return tabs.concat([{
      key: TABS_VIDEO,
      title: '视频信息'
    }]);
  }, [info === null || info === void 0 ? void 0 : info.actionType]);
  var contents = (_contents = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_contents, TABS_BASE, /*#__PURE__*/_jsx(Common.BaseInfo, {})), TABS_STATIC, /*#__PURE__*/_jsx(Common.StaticInfo, {})), TABS_ALARM, /*#__PURE__*/_jsx(Common.AlarmInfo, {})), TABS_VIDEO, /*#__PURE__*/_jsx(VmVideo, {
    channels: channels
  })), TABS_OIL, /*#__PURE__*/_jsx(Common.OilConsumption, {})), TABS_WATER, /*#__PURE__*/_jsx(Common.WaterConsumption, {})), TABS_MAINTENANCE, /*#__PURE__*/_jsx(Common.Maintenance, {})), TABS_DETAIL, /*#__PURE__*/_jsx(Common.DetailInfo, {})), TABS_DEVICE, /*#__PURE__*/_jsx(Common.DeviceInfo, {})), TABS_JXH_BASE, /*#__PURE__*/_jsx(JXH.BaseInfo, {})), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_contents, TABS_JXH_STATIC, /*#__PURE__*/_jsx(JXH.StaticInfo, {})), TABS_JXH_WORK, /*#__PURE__*/_jsx(JXH.WorkRecord, {})), TABS_JXH_ALARM, /*#__PURE__*/_jsx(JXH.AlarmInfo, {})), TABS_JXH_BASE_HW_2, /*#__PURE__*/_jsx(JXH.Hw2BaseInfo, {})), TABS_JXH_STATIC_HW_2, /*#__PURE__*/_jsx(JXH.Hw2StaticInfo, {})), TABS_JXH_WORK_HW_2, /*#__PURE__*/_jsx(JXH.Hw2WorkRecord, {})), TABS_JXH_ALARM_HW_2, /*#__PURE__*/_jsx(JXH.Hw2AlarmInfo, {})), TABS_LJSY_BASE, /*#__PURE__*/_jsx(Ljsy.BaseInfo, {})), TABS_LJSY_STATIC, /*#__PURE__*/_jsx(Ljsy.StaticInfo, {})), TABS_LJSY_WORK, /*#__PURE__*/_jsx(Ljsy.WorkRecord, {})), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_contents, TABS_LJSY_ALARM, /*#__PURE__*/_jsx(Ljsy.AlarmInfo, {})), TABS_CC_BASE, /*#__PURE__*/_jsx(Cc.BaseInfo, {})), TABS_CC_ORDER, /*#__PURE__*/_jsx(Cc.OrderInfo, {})), TABS_CC_STATIC, /*#__PURE__*/_jsx(Cc.StaticInfo, {})), TABS_CC_WORK, /*#__PURE__*/_jsx(Cc.WorkRecord, {})), TABS_CC_ALARM, /*#__PURE__*/_jsx(Cc.AlarmInfo, {})), TABS_LJZY_BASE, /*#__PURE__*/_jsx(Ljzy.BaseInfo, {})), TABS_LJZY_STATIC, /*#__PURE__*/_jsx(Ljzy.StaticInfo, {})), TABS_LJZY_WORK, /*#__PURE__*/_jsx(Ljzy.WorkRecord, {})), TABS_JZLJ_CAR_BASE, /*#__PURE__*/_jsx(Jzlj.BaseInfo, {})), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_contents, TABS_JZLJ_CAR_DISPOSE, /*#__PURE__*/_jsx(Jzlj.Dispose, {})), TABS_JZLJ_CAR_COLLECTION, /*#__PURE__*/_jsx(Jzlj.Collection, {})), TABS_JZLJ_CAR_ALARM, /*#__PURE__*/_jsx(Jzlj.Alarm, {})), TABS_JZLJ_CAR_RUNNING_CALENDAR, /*#__PURE__*/_jsx(Jzlj.RunCalendar, {})));
  var _useGetConfig = useGetConfig(code, tabs),
    tabsData = _useGetConfig.tabsData;
  var tabsList = useMemo(function () {
    var tabsList = tabsData;
    if (tabsList.findIndex(function (ele) {
      return ele.key === 'video';
    }) > -1 && (channels === null || channels === void 0 ? void 0 : channels.length) < 1) {
      tabsList = tabsList.filter(function (ele) {
        return ele.key !== 'video';
      });
    }
    if (tabsList.findIndex(function (ele) {
      return ele.key === 'oil';
    }) > -1 && !beenOilStatus) {
      tabsList = tabsList.filter(function (ele) {
        return ele.key !== 'oil';
      });
    }
    return tabsList;
  }, [JSON.stringify(tabsData), JSON.stringify(channels), beenOilStatus]);
  if (tabsList !== null && tabsList !== void 0 && tabsList.length) {
    tabsList.forEach(function (ele) {
      if (ele.url) {
        contents[ele.key] = /*#__PURE__*/_jsx(VmCustom, {
          id: id,
          url: ele === null || ele === void 0 ? void 0 : ele.url
        }, ele.key);
      }
    });
  }
  var _useSetState = useSetState({
      src: '',
      visible: false,
      title: ''
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    iframeModalInfo = _useSetState2[0],
    setIframeModalInfo = _useSetState2[1];
  var value = useMemo(function () {
    return {
      id: id,
      info: info,
      detail: detail,
      startDate: startDate ? dayjs(startDate) : undefined,
      endDate: endDate ? dayjs(endDate) : undefined,
      showFields: showFields,
      onTdClick: onTdClick,
      onCancel: onCancel,
      setIframeModalInfo: setIframeModalInfo
    };
  }, [id, info, detail, startDate, endDate, showFields, onCancel, onTdClick, setIframeModalInfo]);
  return /*#__PURE__*/_jsx(_Fragment, {
    children: visible && /*#__PURE__*/_jsxs(Provider, {
      value: value,
      children: [/*#__PURE__*/_jsx(VtxBaseModal, {
        title: title,
        subTitle: '',
        width: width,
        id: id,
        type: "car",
        source: source,
        theme: theme,
        visible: visible,
        onCancel: onCancel,
        tabs: tabsList,
        tabChose: tabChose,
        startDate: startDate,
        endDate: endDate,
        showCollect: showCollect,
        frameParams: frameParams,
        iframeUrl: iframeUrl,
        tagList: [{
          color: 'blue',
          value: info.carClassName
        }, {
          color: info.carStatus === 'OFFLINE' ? 'red' : 'green',
          value: info.carStatusStr
        }],
        contents: contents
      }), /*#__PURE__*/_jsx(VmIframeModal, _objectSpread(_objectSpread({}, iframeModalInfo), {}, {
        theme: theme,
        onCancel: function onCancel() {
          return setIframeModalInfo({
            visible: false
          });
        }
      }))]
    })
  });
};
export default VtxCarModal;