"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.FloatingPanelHeader = void 0;
var _react = _interopRequireWildcard(require("react"));
var _faXmark = require("@fortawesome/free-solid-svg-icons/faXmark");
var _button = require("../button");
var _fontAwesomeIcon = require("../font-awesome-icon");
var _useTranslation = require("../hooks/use-translation");
var _floatingPanelDockButton = require("./floating-panel-dock-button");
var _floatingPanelDragHandle = require("./floating-panel-drag-handle");
var _useDraggableArea = require("./use-draggable-area");
var _constants = require("./constants");
var _floatingPanelCollapseButton = require("./floating-panel-collapse-button");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
const FloatingPanelHeader = exports.FloatingPanelHeader = /*#__PURE__*/(0, _react.forwardRef)(({
  actions = null,
  onClose,
  isDocked,
  setIsDocked,
  getPosition,
  dragIcon
}, ref) => {
  const {
    t
  } = (0, _useTranslation.useTranslation)();
  const {
    onDrag,
    onDragStart,
    onDragEnd,
    isCollapsed,
    setIsCollapsed
  } = (0, _react.useContext)(_constants.FloatingPanelContext);
  const onStart = (0, _useDraggableArea.useDraggableArea)({
    areaId: 'drag-header',
    onDrag,
    onDragStart,
    onDragEnd
  });
  return (
    /*#__PURE__*/
    // FloatingPanelDragHandle is responsible for accessibility of the drag handle
    // eslint-disable-next-line jsx-a11y/no-static-element-interactions
    (0, _jsxRuntime.jsxs)("header", {
      ref: ref,
      className: "floating-panel-header",
      onMouseDown: onStart,
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_floatingPanelDragHandle.FloatingPanelDragHandle, {
        dragIcon: dragIcon
      }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
        className: "actions",
        onMouseDown: event => {
          // Prevent dragging when clicking on action buttons
          event.stopPropagation();
        },
        children: [actions, /*#__PURE__*/(0, _jsxRuntime.jsx)(_floatingPanelCollapseButton.FloatingPanelCollapseButton, {
          isCollapsed: isCollapsed,
          setIsCollapsed: setIsCollapsed
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_floatingPanelDockButton.FloatingPanelDockButton, {
          isDocked: isDocked,
          setIsDocked: setIsDocked
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_button.Button, {
          testId: "floating-panel-close-action",
          accentType: _button.ACCENT_TYPES.ROUND_ICON,
          onClick: () => onClose(getPosition()),
          "aria-label": t('Close'),
          children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_fontAwesomeIcon.FontAwesomeIcon, {
            icon: _faXmark.faXmark
          })
        })]
      })]
    })
  );
});
FloatingPanelHeader.displayName = 'FloatingPanelHeader';