import React, { JSX } from 'react';
import styled from 'styled-components';

import { CatalogSortButton } from '@redocly/theme/components/Catalog/CatalogSortButton';
import { CatalogViewModeToggle } from '@redocly/theme/components/Catalog/CatalogViewModeToggle';
import { CatalogViewMode } from '@redocly/theme/core';

type CatalogMobileTopBarControlsProps = {
  setSortOption: (sortOption: string | null) => void;
  sortOption: string | null;
  viewMode: CatalogViewMode;
  setViewMode: (viewMode: CatalogViewMode) => void;
};

export function CatalogMobileTopBarControls({
  setSortOption,
  sortOption,
  viewMode,
  setViewMode,
}: CatalogMobileTopBarControlsProps): JSX.Element {
  return (
    <CatalogMobileTopBarControlsWrapper>
      <CatalogSortButton onSortChange={setSortOption} currentSort={sortOption} />
      <CatalogViewModeToggle viewMode={viewMode} onViewModeChange={setViewMode} />
    </CatalogMobileTopBarControlsWrapper>
  );
}

const CatalogMobileTopBarControlsWrapper = styled.div`
  display: flex;
  align-items: center;
  gap: var(--catalog-controls-wrapper-gap);
`;
