import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import { useEffect, useState } from 'react';
import { FcrButton } from '../button';
import { FcrIcon } from '../icon';
import { FcrIconType } from '../icon/type';
import './index.css';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
export var FcrWindowControl = function FcrWindowControl(props) {
  var _props$enableMaximize = props.enableMaximize,
    enableMaximize = _props$enableMaximize === void 0 ? false : _props$enableMaximize,
    _props$enableMinimize = props.enableMinimize,
    enableMinimize = _props$enableMinimize === void 0 ? false : _props$enableMinimize;
  var _useState = useState(window.outerWidth === screen.availWidth && window.outerHeight === screen.availHeight),
    _useState2 = _slicedToArray(_useState, 2),
    isWindowMaximized = _useState2[0],
    setIsWindowMaximized = _useState2[1];
  var changeMaximizeState = function changeMaximizeState() {
    var newState = window.outerWidth === screen.availWidth && window.outerHeight === screen.availHeight;
    if (newState !== isWindowMaximized) {
      setIsWindowMaximized(newState);
    }
  };
  useEffect(function () {
    window.addEventListener('resize', changeMaximizeState);
    return function () {
      window.removeEventListener('resize', changeMaximizeState);
    };
  }, []);
  return /*#__PURE__*/_jsxs("div", {
    className: "fcr-window-control",
    children: [enableMinimize && /*#__PURE__*/_jsx(FcrButton, {
      onClick: props.onMinimize,
      type: "secondary",
      size: "XXS",
      className: "fcr-window-control-button-primary fcr-no-drag",
      children: /*#__PURE__*/_jsx(FcrIcon, {
        type: FcrIconType.FCR_WEB_SMALLEST,
        size: 24,
        colors: {
          iconPrimary: 'var(--fcr_ui_scene_icontext1)'
        }
      })
    }), enableMaximize && isWindowMaximized ? /*#__PURE__*/_jsx(FcrButton, {
      size: "XXS",
      onClick: props.onReduction,
      className: "fcr-window-control-button-primary fcr-no-drag",
      type: "secondary",
      children: /*#__PURE__*/_jsx(FcrIcon, {
        type: FcrIconType.FCR_WEB_RESTORATION,
        size: 24,
        colors: {
          iconPrimary: 'var(--fcr_ui_scene_icontext1)'
        }
      })
    }) : enableMaximize && /*#__PURE__*/_jsx(FcrButton, {
      onClick: props.onMaximize,
      size: "XXS",
      type: "secondary",
      className: "fcr-window-control-button-primary fcr-no-drag",
      children: /*#__PURE__*/_jsx(FcrIcon, {
        className: "fcr-icon-fullscream",
        type: FcrIconType.FCR_WEB_FULLSCREAM,
        size: 24,
        colors: {
          iconPrimary: 'var(--fcr_ui_scene_icontext1)'
        }
      })
    }), /*#__PURE__*/_jsx(FcrButton, {
      size: "XXS",
      onClick: props.onClose,
      className: "fcr-window-control-button-danger fcr-no-drag",
      type: "secondary",
      children: /*#__PURE__*/_jsx(FcrIcon, {
        type: FcrIconType.FCR_CLOSE,
        size: 24,
        colors: {
          iconPrimary: 'var(--fcr_ui_scene_icontext1)'
        }
      })
    })]
  });
};