"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.List = void 0;
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _react = _interopRequireWildcard(require("react"));
var _mediaUi = require("@atlaskit/media-ui");
var _itemViewer = require("./item-viewer");
var _styleWrappers = require("./styleWrappers");
var _navigation = require("./navigation");
var _mediaCommon = require("@atlaskit/media-common");
var _header = _interopRequireDefault(require("./header"));
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(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 (var _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); }
var List = exports.List = function List(_ref) {
  var defaultSelectedItem = _ref.defaultSelectedItem,
    onClose = _ref.onClose,
    showControls = _ref.showControls,
    extensions = _ref.extensions,
    onSidebarButtonClick = _ref.onSidebarButtonClick,
    contextId = _ref.contextId,
    featureFlags = _ref.featureFlags,
    isSidebarVisible = _ref.isSidebarVisible,
    onNavigationChange = _ref.onNavigationChange,
    items = _ref.items,
    viewerOptions = _ref.viewerOptions;
  var _useState = (0, _react.useState)(defaultSelectedItem),
    _useState2 = (0, _slicedToArray2.default)(_useState, 2),
    selectedItem = _useState2[0],
    setSelectedItem = _useState2[1];
  var _useState3 = (0, _react.useState)(0),
    _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
    previewCount = _useState4[0],
    setPreviewCount = _useState4[1];
  var _useState5 = (0, _react.useState)(false),
    _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
    isArchiveSideBarVisible = _useState6[0],
    setIsArchiveSideBarVisible = _useState6[1];
  var traceContext = (0, _react.useRef)({
    traceId: (0, _mediaCommon.getRandomTelemetryId)()
  });
  return /*#__PURE__*/_react.default.createElement(_styleWrappers.ListWrapper, null, /*#__PURE__*/_react.default.createElement(_styleWrappers.HeaderWrapper
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
  , {
    className: _mediaUi.hideControlsClassName,
    isArchiveSideBarVisible: isArchiveSideBarVisible
  }, /*#__PURE__*/_react.default.createElement(_header.default, {
    identifier: selectedItem,
    onClose: onClose,
    extensions: extensions,
    onSidebarButtonClick: onSidebarButtonClick,
    isSidebarVisible: isSidebarVisible,
    isArchiveSideBarVisible: isArchiveSideBarVisible,
    featureFlags: featureFlags,
    onSetArchiveSideBarVisible: setIsArchiveSideBarVisible,
    traceContext: traceContext.current
  })), /*#__PURE__*/_react.default.createElement(_itemViewer.ItemViewer, {
    identifier: selectedItem,
    showControls: showControls,
    onClose: onClose,
    previewCount: previewCount,
    contextId: contextId,
    featureFlags: featureFlags,
    viewerOptions: viewerOptions,
    traceContext: traceContext.current
  }), /*#__PURE__*/_react.default.createElement(_navigation.Navigation, {
    items: items,
    selectedItem: selectedItem,
    onChange: function onChange(selectedItem) {
      onNavigationChange === null || onNavigationChange === void 0 || onNavigationChange(selectedItem);
      showControls === null || showControls === void 0 || showControls();
      setSelectedItem(selectedItem);
      setPreviewCount(previewCount + 1);
    },
    isArchiveSideBarVisible: isArchiveSideBarVisible
  }));
};