function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure 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 _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; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import { useEffect, useState } from 'react';

/**
 * 预约页响应式断点：宽度 ≤ 该值时落到 `phone` 布局。
 *
 * 选 768 与仓库内既有手机断点一致（见 ToolBarFilter.less / ResourceWallViewport.less）。
 */
export var PISELL_RESERVATION_PHONE_MAX_WIDTH = 768;
function readPhoneByWidth() {
  if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') {
    return false;
  }
  return window.matchMedia("(max-width: ".concat(PISELL_RESERVATION_PHONE_MAX_WIDTH, "px)")).matches;
}

/**
 * 监听视口宽度，得到预约页应使用的 `variant`。
 *
 * - 调用方显式传入 `forced` 时，优先使用之，避免覆盖业务/低代码意图（见 responsive 规则中 props 优先级）；
 * - 否则按断点动态返回 `'phone'` / `'desktop'`，并在 resize / orientation 变化时同步更新。
 *
 * @param forced 调用方显式指定的 variant；不传则按断点判定
 */
export function useReservationResponsiveVariant(forced) {
  var _useState = useState(function () {
      return readPhoneByWidth();
    }),
    _useState2 = _slicedToArray(_useState, 2),
    isPhone = _useState2[0],
    setIsPhone = _useState2[1];
  useEffect(function () {
    var _legacy$addListener;
    if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') {
      return undefined;
    }
    var mql = window.matchMedia("(max-width: ".concat(PISELL_RESERVATION_PHONE_MAX_WIDTH, "px)"));
    var handle = function handle(event) {
      setIsPhone(Boolean(event.matches));
    };
    handle(mql);
    if (typeof mql.addEventListener === 'function') {
      mql.addEventListener('change', handle);
      return function () {
        mql.removeEventListener('change', handle);
      };
    }
    /** Safari < 14 兼容：addListener / removeListener */
    var legacy = mql;
    (_legacy$addListener = legacy.addListener) === null || _legacy$addListener === void 0 || _legacy$addListener.call(legacy, handle);
    return function () {
      var _legacy$removeListene;
      (_legacy$removeListene = legacy.removeListener) === null || _legacy$removeListene === void 0 || _legacy$removeListene.call(legacy, handle);
    };
  }, []);
  if (typeof forced === 'string' && forced.length > 0) {
    return forced;
  }
  return isPhone ? 'phone' : 'desktop';
}
export default useReservationResponsiveVariant;