import React, { useState, useRef } from 'react';
import { hideControlsClassName } from '@atlaskit/media-ui';
import { ItemViewer } from './item-viewer';
import { HeaderWrapper, ListWrapper } from './styleWrappers';
import { Navigation } from './navigation';
import { getRandomTelemetryId } from '@atlaskit/media-common';
import Header from './header';
export const List = ({
  defaultSelectedItem,
  onClose,
  showControls,
  extensions,
  onSidebarButtonClick,
  contextId,
  featureFlags,
  isSidebarVisible,
  onNavigationChange,
  items,
  viewerOptions
}) => {
  const [selectedItem, setSelectedItem] = useState(defaultSelectedItem);
  const [previewCount, setPreviewCount] = useState(0);
  const [isArchiveSideBarVisible, setIsArchiveSideBarVisible] = useState(false);
  const traceContext = useRef({
    traceId: getRandomTelemetryId()
  });
  return /*#__PURE__*/React.createElement(ListWrapper, null, /*#__PURE__*/React.createElement(HeaderWrapper
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
  , {
    className: hideControlsClassName,
    isArchiveSideBarVisible: isArchiveSideBarVisible
  }, /*#__PURE__*/React.createElement(Header, {
    identifier: selectedItem,
    onClose: onClose,
    extensions: extensions,
    onSidebarButtonClick: onSidebarButtonClick,
    isSidebarVisible: isSidebarVisible,
    isArchiveSideBarVisible: isArchiveSideBarVisible,
    featureFlags: featureFlags,
    onSetArchiveSideBarVisible: setIsArchiveSideBarVisible,
    traceContext: traceContext.current
  })), /*#__PURE__*/React.createElement(ItemViewer, {
    identifier: selectedItem,
    showControls: showControls,
    onClose: onClose,
    previewCount: previewCount,
    contextId: contextId,
    featureFlags: featureFlags,
    viewerOptions: viewerOptions,
    traceContext: traceContext.current
  }), /*#__PURE__*/React.createElement(Navigation, {
    items: items,
    selectedItem: selectedItem,
    onChange: selectedItem => {
      onNavigationChange === null || onNavigationChange === void 0 ? void 0 : onNavigationChange(selectedItem);
      showControls === null || showControls === void 0 ? void 0 : showControls();
      setSelectedItem(selectedItem);
      setPreviewCount(previewCount + 1);
    },
    isArchiveSideBarVisible: isArchiveSideBarVisible
  }));
};