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; }
import classNames from 'classnames';
import { useEffect, useRef, useState } from 'react';
import { AccessIcon, AlarmIcon, AnalysisIcon, AnnouncementIcon, AnnualInspectionIcon, AppraisalIcon, AppraiseIcon, AssessmentIcon, AssetIcon, AttendanceIcon, CalendarIcon, CaseIcon, ChargingIcon, CollectionIcon, ContractIcon, DeviceIcon, DocumentIcon, EquipmentIcon, EvaluationIcon, FactoryIcon, HistoryIcon, IndexIcon, InspectionIcon, InsuranceIcon, InterviewIcon, LifeCycleIcon, LogIcon, MaintenanceIcon, MeasurementIcon, MeteringIcon, OilIcon, OperationIcon, PointIcon, ProcessIcon, ProductionUnitIcon, RmIcon, RouteIcon, SbzjIcon, SchedulingIcon, ScoreIcon, SparePartsIcon, SpeedCurveIcon, StatisticsIcon, SummaryIcon, SyInfoIcon, TfdIcon, TfrdIcon, ThrowIcon, TrashIcon, VideoIcon, ViolationIcon, WaterIcon, WgrgsIcon, WgxwIcon, WorkConditionIcon, WorkInfoIcon, WorkingConditionIcon, WorkOrderIcon } from "../../_util/iconSvgHtml";
import "./index.less";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
var Tabs = function Tabs(props) {
  var _props$tabs = props.tabs,
    tabs = _props$tabs === void 0 ? [] : _props$tabs,
    onChange = props.onChange,
    active = props.active,
    _props$theme = props.theme,
    theme = _props$theme === void 0 ? 'light' : _props$theme;
  var wrapRef = useRef(null);
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    isScrollable = _useState2[0],
    setIsScrollable = _useState2[1];
  useEffect(function () {
    var wrapDom = wrapRef.current;
    if (!wrapDom) return undefined;
    var checkScrollable = function checkScrollable() {
      setIsScrollable(wrapDom.scrollWidth > wrapDom.clientWidth + 1);
    };
    checkScrollable();
    var resizeObserver;
    if (typeof ResizeObserver !== 'undefined') {
      resizeObserver = new ResizeObserver(checkScrollable);
      resizeObserver.observe(wrapDom);
    } else {
      window.addEventListener('resize', checkScrollable);
    }
    return function () {
      if (resizeObserver) {
        resizeObserver.disconnect();
      } else {
        window.removeEventListener('resize', checkScrollable);
      }
    };
  }, [tabs]);
  var iconRender = {
    'default-base': SummaryIcon,
    base: SummaryIcon,
    summary: SummaryIcon,
    history: HistoryIcon,
    alarm: AlarmIcon,
    'cp-sy': SyInfoIcon,
    'cp-warning': AlarmIcon,
    'cp-exeception': AlarmIcon,
    sy: SyInfoIcon,
    warning: AlarmIcon,
    exeception: AlarmIcon,
    rm: RmIcon,
    'default-rm': RmIcon,
    appraisal: AppraisalIcon,
    'default-appraisal': AppraisalIcon,
    equipment: EquipmentIcon,
    sbzj: SbzjIcon,
    wgxw: WgxwIcon,
    tfrd: TfrdIcon,
    throw: ThrowIcon,
    tfd: TfdIcon,
    wgrgs: WgrgsIcon,
    water: WaterIcon,
    oil: OilIcon,
    video: VideoIcon,
    calendar: CalendarIcon,
    maintenance: MaintenanceIcon,
    statistics: StatisticsIcon,
    device: DeviceIcon,
    workInfo: WorkInfoIcon,
    collection: CollectionIcon,
    access: AccessIcon,
    factory: FactoryIcon,
    asset: AssetIcon,
    document: DocumentIcon,
    log: LogIcon,
    point: PointIcon,
    interview: InterviewIcon,
    contract: ContractIcon,
    charging: ChargingIcon,
    annualInspection: AnnualInspectionIcon,
    insurance: InsuranceIcon,
    trash: TrashIcon,
    violation: ViolationIcon,
    process: ProcessIcon,
    case: CaseIcon,
    speedCurve: SpeedCurveIcon,
    lifeCycle: LifeCycleIcon,
    productionUnit: ProductionUnitIcon,
    spareParts: SparePartsIcon,
    operation: OperationIcon,
    inspection: InspectionIcon,
    attendance: AttendanceIcon,
    announcement: AnnouncementIcon,
    analysis: AnalysisIcon,
    route: RouteIcon,
    measurement: MeasurementIcon,
    workingCondition: WorkingConditionIcon,
    workCondition: WorkConditionIcon,
    metering: MeteringIcon,
    evaluation: EvaluationIcon,
    scheduling: SchedulingIcon,
    workOrder: WorkOrderIcon,
    assessment: AssessmentIcon,
    index: IndexIcon,
    appraise: AppraiseIcon,
    score: ScoreIcon,
    build: WorkInfoIcon,
    file: DocumentIcon
  };
  return tabs.length ? /*#__PURE__*/_jsx("div", {
    className: 'vm-modal-tabs',
    children: /*#__PURE__*/_jsx("div", {
      ref: wrapRef,
      className: classNames('vm-modal-tabs-wrap', {
        'vm-modal-tabs-wrap-scrollable': isScrollable
      }),
      children: tabs.map(function (tab, index) {
        var width = 26,
          height = 26;
        var ComponentIcon = iconRender[tab.key] || SummaryIcon;
        return /*#__PURE__*/_jsxs("div", {
          onClick: function onClick() {
            onChange(tab.key);
          },
          className: classNames('vm-modal-tabs-item', active === tab.key ? 'vm-modal-tabs-item-active' : 'vm-modal-tabs-item-normal', {
            'vm-modal-tabs-item-dark': theme !== 'light'
          }),
          children: [ComponentIcon && /*#__PURE__*/_jsx(ComponentIcon, {
            width: width,
            height: height,
            fill: theme === 'light' ? active === tab.key ? '#fff' : '#1F1F1F' : '#fff',
            style: {
              transform: 'scale(0.55)'
            }
          }), /*#__PURE__*/_jsx("span", {
            children: tab.title
          })]
        }, index);
      })
    })
  }) : null;
};
export default Tabs;