'use client';

import { SortOption, ViewMode } from '@/features/search/types';

interface SearchHeaderProps {
  totalResults: number;
  viewMode: ViewMode;
  sortBy: SortOption;
  onViewModeChange: (mode: ViewMode) => void;
  onSortChange: (sort: SortOption) => void;
  destination?: string;
  isLoading?: boolean;
}

export default function SearchHeader({
  totalResults,
  viewMode,
  sortBy,
  onViewModeChange,
  onSortChange,
  destination,
  isLoading = false,
}: SearchHeaderProps) {
  return (
    <>
      <div className="d-md-flex justify-content-between gap-2 mb-3">
        <h3 className="contentHeading color-text-dark fw-semibold mb-0 pt-2">
          {isLoading ? 'Searching for properties' : `${totalResults} Properties  ${destination ? 'in ' + destination : ''}`}
        </h3>
        <div className="d-none d-md-flex justify-content-between align-items-center gap-1 lightBg border rounded-5 w-fit-content p-1">
          <button
            id="listBtn"
            onClick={() => onViewModeChange('list')}
            className={`list-grid-btn lightBg rounded-5 py-1 px-3 ${viewMode === 'list' ? 'active' : ''}`}
          >
            List
          </button>
          <button
            id="gridBtn"
            onClick={() => onViewModeChange('grid')}
            className={`list-grid-btn lightBg rounded-5 py-1 px-3 ${viewMode === 'grid' ? 'active' : ''}`}
          >
            Grid
          </button>
        </div>
      </div>
      <div className="sort-by-section bgColor-white d-md-flex d-none flex-md-row flex-column flex-md-nowrap justify-content-center gap-2 align-items-center btn-group sorting-listing w-100 border p-1 mb-3" role="group">
        <div className="sort-by-div flex-1 w-100 text-center">
          <button
            type="button"
            onClick={() => onSortChange('default')}
            className={`text-sm fw-semibold ${sortBy === 'default' ? 'active' : ''}`}
          >
            Popularity
          </button>
        </div>
        <div className="sort-by-div flex-1 w-100 text-center border-start">
          <button
            type="button"
            onClick={() => onSortChange('price-low')}
            className={`text-sm fw-semibold ${sortBy === 'price-low' ? 'active' : ''}`}
          >
            Price <span className="text-sm fw-400">(Low to High)</span>
          </button>
        </div>
        <div className="sort-by-div flex-1 w-100 text-center border-start">
          <button
            type="button"
            onClick={() => onSortChange('price-high')}
            className={`text-sm fw-semibold ${sortBy === 'price-high' ? 'active' : ''}`}
          >
            Price <span className="text-sm fw-400">(High to Low)</span>
          </button>
        </div>
        {/* <div className="sort-by-div flex-1 w-100 text-center border-start">
          <button
            type="button"
            onClick={() => onSortChange('rating')}
            className={`text-sm fw-semibold ${sortBy === 'rating' ? 'active' : ''}`}
          >
            User Rating <span className="text-sm fw-400">(Highest)</span>
          </button>
        </div>
        <div className="sort-by-div flex-1 w-100 text-center border-start px-1">
          <button
            type="button"
            onClick={() => onSortChange('best-value')}
            className={`text-sm fw-semibold ${sortBy === 'best-value' ? 'active' : ''}`}
          >
            Lowest Price & best rated
          </button>
        </div> */}
      </div>
    </>
  );
}
