var _excluded = ["request", "storage"];
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
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 { Alert } from 'antd';
import React, { useEffect, useState } from 'react';
import ComponentUninstalled from "../ComponentUninstalled";
import { LogCenterProvider, useLogCenterContext, useLogCenterLocale } from "./context";
import HistoryLog from "./history-log";
import RealtimeLog from "./realtime-log";
import "./index.less";
export { logCenterLocaleZhCN } from "./locale";
export { LOG_CENTER_API, createLogCenterServices } from "./services";
var LogCenterInner = function LogCenterInner(props) {
  var _props$type = props.type,
    type = _props$type === void 0 ? 'realtimeLog' : _props$type,
    _props$space = props.space,
    space = _props$space === void 0 ? 'cluster' : _props$space,
    clusterId = props.clusterId,
    toSearchAnalysis = props.toSearchAnalysis,
    _props$isEmbed = props.isEmbed,
    isEmbed = _props$isEmbed === void 0 ? false : _props$isEmbed,
    embedParams = props.embedParams,
    _props$wsClose = props.wsClose,
    wsClose = _props$wsClose === void 0 ? false : _props$wsClose,
    menuData = props.menuData,
    clusterAliasName = props.clusterAliasName;
  var locale = useLogCenterLocale();
  var _useLogCenterContext = useLogCenterContext(),
    services = _useLogCenterContext.services,
    storage = _useLogCenterContext.storage;
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    isFullScreen = _useState2[0],
    setIsFullScreen = _useState2[1];
  var _useState3 = useState(false),
    _useState4 = _slicedToArray(_useState3, 2),
    isHasUninstalledCompo = _useState4[0],
    setIsHasUninstalledCompo = _useState4[1];
  var logTips = {
    realtimeLog: locale.log['实时日志Tips'],
    stdoutLog: locale.log['标准日志Tips'],
    filesLog: locale.log['日志文件Tips']
  };
  var handleFullScreen = function handleFullScreen(e) {
    var _parentElement;
    var fullScreenEle = (_parentElement = e.currentTarget.parentElement) === null || _parentElement === void 0 || (_parentElement = _parentElement.parentElement) === null || _parentElement === void 0 ? void 0 : _parentElement.parentElement;
    if (!fullScreenEle) return;
    if (document.fullscreenElement) {
      setIsFullScreen(false);
      document.exitFullscreen();
      return;
    }
    setIsFullScreen(true);
    fullScreenEle.requestFullscreen();
  };
  useEffect(function () {
    var handleKeyDown = function handleKeyDown(e) {
      if (e.key === 'Escape' && isFullScreen) {
        setIsFullScreen(false);
        if (document.fullscreenElement) {
          document.exitFullscreen();
        }
      }
    };
    var handleFullscreenChange = function handleFullscreenChange() {
      if (!document.fullscreenElement && isFullScreen) {
        setIsFullScreen(false);
      }
    };
    if (isFullScreen) {
      document.addEventListener('keydown', handleKeyDown);
      document.addEventListener('fullscreenchange', handleFullscreenChange);
    }
    return function () {
      document.removeEventListener('keydown', handleKeyDown);
      document.removeEventListener('fullscreenchange', handleFullscreenChange);
    };
  }, [isFullScreen]);
  return /*#__PURE__*/React.createElement("div", {
    className: "log-center-wrapper"
  }, type !== 'componentLog' && !isHasUninstalledCompo && logTips[type] && /*#__PURE__*/React.createElement(Alert, {
    message: logTips[type],
    type: "info",
    showIcon: true,
    closable: true
  }), type === 'realtimeLog' ? /*#__PURE__*/React.createElement(RealtimeLog, {
    type: type,
    space: space,
    clusterId: clusterId,
    isFullScreen: isFullScreen,
    onFullScreen: handleFullScreen,
    isEmbed: isEmbed,
    embedParams: embedParams,
    wsClose: wsClose
  }) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ComponentUninstalled, {
    clusterName: clusterId,
    clusterAliasName: clusterAliasName,
    menuData: menuData,
    getClusterAddons: services.getClusterAddons,
    storage: storage,
    onCallback: function onCallback(flag) {
      setIsHasUninstalledCompo(flag);
    }
  }), !isHasUninstalledCompo && /*#__PURE__*/React.createElement(HistoryLog, {
    type: type,
    space: space,
    clusterId: clusterId,
    toSearchAnalysis: toSearchAnalysis,
    isFullScreen: isFullScreen,
    onFullScreen: handleFullScreen,
    isEmbed: isEmbed,
    embedParams: embedParams
  })));
};
var LogCenter = function LogCenter(_ref) {
  var request = _ref.request,
    storage = _ref.storage,
    rest = _objectWithoutProperties(_ref, _excluded);
  return /*#__PURE__*/React.createElement(LogCenterProvider, {
    request: request,
    storage: storage
  }, /*#__PURE__*/React.createElement(LogCenterInner, rest));
};
export default LogCenter;