import { SortTypeKeys, SortTypeBoxProps } from '../model/types';
import { useTranslation } from 'react-i18next';

export const SortTypeBox = ({
  sortType,
  onClickToSort,
  sortOptions
}: SortTypeBoxProps) => {
  const { t } = useTranslation();

  const defaultSortOptions = [
    { key: SortTypeKeys.LATEST, label: t('filter.sortOrders.latest') },
    { key: SortTypeKeys.HIGH_AMOUNT, label: t('filter.sortOrders.highest') }
  ];

  const options = sortOptions || defaultSortOptions;

  return (
    <>
      <div className="sort-options">
        { options.map((option: Record<string, any>, index: number) => (
          <>
          { (index > 0) && 
            <span 
              key={ option.key + '-divider' } 
              className="sort-divider"
            >|</span>
          }
            <span key={ option.key }>
              <button
                className={ `sort-btn ${(sortType === option.key)? 'active': ''}` }
                onClick={ () => onClickToSort(option.key) }
              >{ option.label }</button>
            </span>
          </>
        ))}
      </div>
    </>
  );
};