import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { isNotEmpty } from '@bigbinary/neeto-cist';
import withT$1 from '@bigbinary/neeto-commons-frontend/react-utils/withT';
import Refresh from '@bigbinary/neeto-icons/Refresh';
import Button from '@bigbinary/neetoui/Button';
import Typography from '@bigbinary/neetoui/Typography';
import Pane from '@bigbinary/neetoui/Pane';
import Spinner from '@bigbinary/neetoui/Spinner';
import { t } from 'i18next';
import classnames from 'classnames';
import { withT } from '@bigbinary/neeto-commons-frontend/react-utils';
import Tag from '@bigbinary/neetoui/Tag';
import Avatar from '@bigbinary/neetoui/Avatar';
import DateFormat from './DateFormat.js';
import MoreDropdown from './MoreDropdown.js';
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
import { createElement } from 'react';
import '@bigbinary/neeto-commons-frontend/react-utils/useTimer';
import '@bigbinary/neeto-commons-frontend/utils/datetime';
import '@bigbinary/neetoui/Tooltip';
import 'ramda';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@bigbinary/neeto-icons/MenuHorizontal';
import '@bigbinary/neeto-icons/MenuVertical';
import '@bigbinary/neetoui/Dropdown';
import 'react-i18next';
import './inject-css-C2dztUxs.js';

var REFRESH_BUTTON_TOOLTIP_PROPS = Object.freeze({
  content: t("neetoMolecules.versionHistory.refreshButtonTooltip"),
  position: "bottom"
});

function ownKeys$1(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var Version = withT(function (_ref) {
  var t = _ref.t,
    id = _ref.id,
    date = _ref.date,
    user = _ref.user,
    onClick = _ref.onClick,
    _ref$isDraft = _ref.isDraft,
    isDraft = _ref$isDraft === void 0 ? false : _ref$isDraft,
    _ref$isPublished = _ref.isPublished,
    isPublished = _ref$isPublished === void 0 ? false : _ref$isPublished,
    _ref$showMoreDropdown = _ref.showMoreDropdown,
    showMoreDropdown = _ref$showMoreDropdown === void 0 ? false : _ref$showMoreDropdown,
    _ref$moreDropdownProp = _ref.moreDropdownProps,
    moreDropdownProps = _ref$moreDropdownProp === void 0 ? {} : _ref$moreDropdownProp,
    _ref$isLast = _ref.isLast,
    isLast = _ref$isLast === void 0 ? false : _ref$isLast;
  return /*#__PURE__*/jsxs("div", {
    className: "flex w-full gap-2",
    children: [/*#__PURE__*/jsxs("div", {
      className: "relative mt-2.5 flex flex-col items-center",
      children: [/*#__PURE__*/jsx("span", {
        className: classnames("neeto-ui-rounded-full neeto-ui-bg-gray-300 relative z-10 h-2 w-2", {
          "neeto-ui-bg-warning-500": isDraft
        }, {
          "neeto-ui-bg-primary-500": isPublished
        })
      }), !isLast && /*#__PURE__*/jsx("span", {
        "aria-hidden": "true",
        className: "neeto-ui-bg-gray-300 absolute start-1/2 top-[9px] z-0 h-full w-px -translate-x-1/2 rtl:translate-x-1/2"
      })]
    }), /*#__PURE__*/jsx("div", {
      onClick: onClick,
      className: classnames("w-full", {
        "pb-3": !isDraft
      }),
      children: /*#__PURE__*/jsxs("div", {
        className: "neeto-ui-rounded hover:neeto-ui-bg-gray-100 flex flex-grow cursor-pointer justify-between gap-4 px-1.5 pb-1.5 pt-1 transition-all duration-300",
        "data-testid": "version-history-event",
        children: [/*#__PURE__*/jsxs("div", {
          className: "flex flex-grow flex-col gap-2",
          children: [/*#__PURE__*/jsxs("div", {
            className: "flex items-center gap-2",
            children: [/*#__PURE__*/jsx(Typography, {
              style: "h5",
              weight: "medium",
              children: /*#__PURE__*/jsx(DateFormat.DateWeekTime, {
                date: date,
                typographyProps: {
                  style: "body3",
                  lineHeight: "snug"
                }
              })
            }), isDraft && /*#__PURE__*/jsx(Tag, {
              className: "float-start",
              "data-testid": "version-history-draft-tag",
              label: t("neetoMolecules.common.actions.draft"),
              size: "small",
              style: "warning"
            })]
          }), /*#__PURE__*/jsxs("div", {
            className: "flex items-center gap-2",
            children: [/*#__PURE__*/jsx(Avatar, {
              size: "small",
              user: {
                name: user
              }
            }), /*#__PURE__*/jsx(Typography, {
              style: "body3",
              children: user
            })]
          })]
        }), showMoreDropdown && /*#__PURE__*/jsx("div", {
          className: "flex-shrink-0",
          onClick: function onClick(e) {
            return e.stopPropagation();
          },
          children: /*#__PURE__*/jsx(MoreDropdown, _objectSpread$1({
            dropdownButtonProps: {
              className: "m-1",
              size: "small",
              disabled: moreDropdownProps.disabled
            },
            dropdownProps: {
              strategy: "fixed",
              appendTo: function appendTo() {
                return document.body;
              }
            }
          }, moreDropdownProps))
        })]
      })
    })]
  }, id);
});

function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var VersionHistory = withT$1(function (_ref) {
  var t = _ref.t,
    isOpen = _ref.isOpen,
    onClose = _ref.onClose,
    isLoading = _ref.isLoading,
    _ref$draftVersions = _ref.draftVersions,
    draftVersions = _ref$draftVersions === void 0 ? [] : _ref$draftVersions,
    _ref$publishedVersion = _ref.publishedVersions,
    publishedVersions = _ref$publishedVersion === void 0 ? [] : _ref$publishedVersion,
    paneTitle = _ref.paneTitle,
    _ref$showRefreshButto = _ref.showRefreshButton,
    showRefreshButton = _ref$showRefreshButto === void 0 ? false : _ref$showRefreshButto,
    onRefreshClick = _ref.onRefreshClick;
  return /*#__PURE__*/jsx(Pane, {
    isOpen: isOpen,
    onClose: onClose,
    children: isLoading ? /*#__PURE__*/jsx("div", {
      className: "flex h-full w-full items-center justify-center",
      children: /*#__PURE__*/jsx(Spinner, {})
    }) : /*#__PURE__*/jsxs(Fragment, {
      children: [/*#__PURE__*/jsxs(Pane.Header, {
        className: "flex justify-between",
        children: [/*#__PURE__*/jsx(Typography, {
          "data-testid": "version-history-pane-header",
          lineHeight: "normal",
          style: "h2",
          weight: "semibold",
          children: paneTitle || t("neetoMolecules.versionHistory.paneTitle")
        }), showRefreshButton && /*#__PURE__*/jsx(Button, {
          "data-testid": "version-history-refresh-button",
          icon: Refresh,
          iconSize: 18,
          size: "small",
          style: "text",
          tooltipProps: REFRESH_BUTTON_TOOLTIP_PROPS,
          onClick: onRefreshClick
        })]
      }), /*#__PURE__*/jsx(Pane.Body, {
        children: /*#__PURE__*/jsxs("div", {
          className: "flex w-full flex-col gap-y-4",
          children: [isNotEmpty(draftVersions) && /*#__PURE__*/jsx("div", {
            className: "flex flex-col",
            children: draftVersions.map(function (version, index) {
              var isLast = index === draftVersions.length - 1;
              return /*#__PURE__*/createElement(Version, _objectSpread(_objectSpread({}, _objectSpread(_objectSpread({}, version), {}, {
                isLast: isLast
              })), {}, {
                key: version.id
              }));
            })
          }), isNotEmpty(publishedVersions) && /*#__PURE__*/jsxs("div", {
            className: "flex items-center",
            children: [/*#__PURE__*/jsx("hr", {
              className: "neeto-ui-border-gray-200 flex-grow"
            }), /*#__PURE__*/jsx(Typography, {
              className: "neeto-ui-bg-gray-200 neeto-ui-text-gray-800 neeto-ui-rounded inline-block px-3 py-1",
              "data-testid": "version-history-published-title",
              lineHeight: "normal",
              style: "body3",
              weight: "medium",
              children: t("neetoMolecules.versionHistory.publishedVersions")
            }), /*#__PURE__*/jsx("hr", {
              className: "neeto-ui-border-gray-200 flex-grow"
            })]
          }), /*#__PURE__*/jsx("div", {
            className: "flex flex-col",
            children: publishedVersions.map(function (version, index) {
              var isLast = index === publishedVersions.length - 1;
              return /*#__PURE__*/createElement(Version, _objectSpread(_objectSpread({}, _objectSpread(_objectSpread({}, version), {}, {
                isLast: isLast
              })), {}, {
                key: version.id
              }));
            })
          })]
        })
      })]
    })
  });
});

export { VersionHistory as default };
//# sourceMappingURL=VersionHistory.js.map
