function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
/**
 * 场地筛选器
 * 包含搜索框和场地类型标签（All / Badminton / Pickleball 等）
 * 类型从 timeSlotGrid.resources 的 productTitle 去重提取
 */
import React, { useMemo } from 'react';
import { locales } from '@pisell/utils';
import { useVenueBookingContext } from "../../../context";
export default function CourtFilter() {
  var _useVenueBookingConte = useVenueBookingContext(),
    search = _useVenueBookingConte.search,
    setSearch = _useVenueBookingConte.setSearch,
    filter = _useVenueBookingConte.filter,
    setFilter = _useVenueBookingConte.setFilter,
    viewModel = _useVenueBookingConte.viewModel;

  // 从当前日期的 timeSlotGrid 资源中提取场地类型
  var courtTypes = useMemo(function () {
    var _viewModel$timeSlotGr;
    var resources = ((_viewModel$timeSlotGr = viewModel.timeSlotGrid) === null || _viewModel$timeSlotGr === void 0 ? void 0 : _viewModel$timeSlotGr.resources) || [];
    return Array.from(new Set(resources.map(function (r) {
      return r.productTitle;
    })));
  }, [viewModel.timeSlotGrid]);
  var filterOptions = [{
    label: locales.getText('pisell2.venue.filter.all') || '全部',
    value: 'ALL'
  }].concat(_toConsumableArray(courtTypes.map(function (type) {
    return {
      label: type,
      value: type
    };
  })));
  return /*#__PURE__*/React.createElement("div", {
    className: "mt-4 grid gap-3 md:mt-5 xl:grid-cols-[1fr_auto] xl:items-center"
  }, courtTypes.length > 1 ? /*#__PURE__*/React.createElement("div", {
    className: "flex flex-wrap gap-2"
  }, filterOptions.map(function (opt) {
    return /*#__PURE__*/React.createElement("button", {
      key: opt.value,
      onClick: function onClick() {
        return setFilter(opt.value);
      },
      className: "rounded-full px-4 py-2 text-sm font-semibold transition ".concat(filter === opt.value ? 'text-white' : 'bg-[#fafafa] text-zinc-700 ring-1 ring-black/8'),
      style: filter === opt.value ? {
        backgroundColor: 'var(--vb-primary)'
      } : undefined
    }, opt.label);
  })) : null);
}