import _defineProperty from "@babel/runtime/helpers/defineProperty";
import { FcrApplicationPlatform, getPlatform, isElectron } from 'agora-foundation/lib/utilities/env';
import { FcrIconButton } from '../icon-button';
import { FcrIconType } from '../icon/type';
import { FcrToolTip } from '../tooltip';
import { FcrIcon } from '../icon';
import { FcrWindowControl } from '../windows-control';
import './index.css';
import classNames from 'classnames';
import { useI18n } from '../../i18n';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
var platformIsWindows = getPlatform() === FcrApplicationPlatform.WINDOWS;
export var WindowType = /*#__PURE__*/function (WindowType) {
  WindowType["WINDOW"] = "window";
  WindowType["MODAL"] = "modal";
  return WindowType;
}({});
export var FcrWindowHeader = function FcrWindowHeader(props) {
  var type = props.type,
    otherActions = props.otherActions,
    otherActionsAfter = props.otherActionsAfter,
    _props$withWindowPopU = props.withWindowPopUpButton,
    withWindowPopUpButton = _props$withWindowPopU === void 0 ? true : _props$withWindowPopU,
    onClose = props.onClose,
    _props$showClose = props.showClose,
    showClose = _props$showClose === void 0 ? type === WindowType.MODAL : _props$showClose,
    enableMaximize = props.enableMaximize,
    enableMinimize = props.enableMinimize,
    onMinimize = props.onMinimize,
    onMaximize = props.onMaximize,
    onReduction = props.onReduction;
  // console.log('[FcrWindowHeader]', props);

  var handlerTypeChange = function handlerTypeChange() {
    if (props.onTypeChange) {
      props.onTypeChange(type === WindowType.WINDOW ? WindowType.MODAL : WindowType.WINDOW);
    }
  };
  var iconColors = {
    iconPrimary: 'var(--fcr_ui_scene_icontext1)'
  };
  var t = useI18n();
  var showInWindowsAndWeb = type === WindowType.WINDOW && platformIsWindows || platformIsWindows && !isElectron();
  var showInMacAndWeb = type === WindowType.WINDOW && !platformIsWindows || !platformIsWindows && !isElectron();
  return /*#__PURE__*/_jsxs("div", {
    className: classNames('frc-window-header', _defineProperty(_defineProperty(_defineProperty({}, "frc-window-header-".concat(type), type), "frc-window-header-web", showInMacAndWeb), 'frc-window-header-reverse', showInWindowsAndWeb && showClose), props.rootClassName || ''),
    children: [showInWindowsAndWeb && showClose && /*#__PURE__*/_jsx(FcrWindowControl, {
      enableMaximize: enableMaximize,
      enableMinimize: enableMinimize,
      onMinimize: onMinimize,
      onClose: onClose,
      onMaximize: onMaximize,
      onReduction: onReduction
    }), showInMacAndWeb && showClose && /*#__PURE__*/_jsx("div", {
      className: "frc-window-header-mac-control",
      children: /*#__PURE__*/_jsx("span", {
        className: "frc-window-header-mac_button frc-window-header-mac_close",
        onClick: onClose,
        children: /*#__PURE__*/_jsx(FcrIcon, {
          className: "frc-window-header-mac-icon frc-window-header-mac_close-icon",
          type: FcrIconType.FCR_CLOSE,
          colors: {
            iconPrimary: 'var(--fcr_ui_scene_black9_5)'
          }
        })
      })
    }), /*#__PURE__*/_jsx("div", {
      className: "frc-window-header__title",
      children: props.title
    }), /*#__PURE__*/_jsxs("div", {
      className: "frc-window-header__operates",
      children: [otherActions, withWindowPopUpButton && /*#__PURE__*/_jsx(FcrToolTip, {
        isArrowAndTargetCenter: true,
        content: type === WindowType.MODAL ? t('fmt_uimanager_option_popwindow') : t('fmt_uimanager_option_mergeview'),
        mouseEnterDelay: 0,
        trigger: "hover",
        children: /*#__PURE__*/_jsx("div", {
          children: /*#__PURE__*/_jsx(FcrIconButton, {
            icon: type === WindowType.MODAL ? FcrIconType.FCR_WINDOWPAGE_LONELY : FcrIconType.FCR_WINDOWPAGE_BIGGER,
            onClick: handlerTypeChange,
            className: "frc-window-header__icon fcr-no-drag",
            iconColors: iconColors
          })
        })
      }), otherActionsAfter]
    })]
  });
};