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; }
/**
 * 日视图：空闲 / 锁台槽多选逻辑（状态仍在 Shell，便于与底部 SelectionBar 共用）。
 */
import { useCallback } from 'react';
import { dayOccupancy, sameSlot } from "../../utils/bookingCalendarDateUtils";
export function useBookingCalendarDaySelection(dayKey, bookings, hourSlots, slotStepHours, courts, selectedFreeSlots, selectedBlockSlots, setSelectedFreeSlots, setSelectedBlockSlots) {
  var isFreeSelected = useCallback(function (courtId, hour) {
    return selectedFreeSlots.some(function (slot) {
      return slot.courtId === courtId && slot.date === dayKey && slot.hour === hour;
    });
  }, [selectedFreeSlots, dayKey]);
  var isBlockSelected = useCallback(function (courtId, hour) {
    return selectedBlockSlots.some(function (slot) {
      return slot.courtId === courtId && slot.date === dayKey && slot.hour === hour;
    });
  }, [selectedBlockSlots, dayKey]);
  var toggleSlot = useCallback(function (courtId, hour) {
    var existing = dayOccupancy(courtId, dayKey, bookings, hourSlots, slotStepHours)[hour];
    var court = courts.find(function (c) {
      return c.id === courtId;
    });
    var slot = {
      courtId: courtId,
      court: court === null || court === void 0 ? void 0 : court.name,
      date: dayKey,
      hour: hour
    };
    if (!existing) {
      setSelectedFreeSlots(function (prev) {
        return prev.some(function (s) {
          return sameSlot(s, slot);
        }) ? prev.filter(function (s) {
          return !sameSlot(s, slot);
        }) : [].concat(_toConsumableArray(prev), [slot]);
      });
      return;
    }
    if (existing.kind === 'block') {
      setSelectedBlockSlots(function (prev) {
        return prev.some(function (s) {
          return sameSlot(s, slot);
        }) ? prev.filter(function (s) {
          return !sameSlot(s, slot);
        }) : [].concat(_toConsumableArray(prev), [slot]);
      });
    }
  }, [bookings, courts, dayKey, hourSlots, setSelectedBlockSlots, setSelectedFreeSlots, slotStepHours]);
  return {
    isFreeSelected: isFreeSelected,
    isBlockSelected: isBlockSelected,
    toggleSlot: toggleSlot
  };
}