function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import { useMemo } from 'react';
var VARIANT_MAP = _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, 'default', ['1', '2', '3', '4']), 'select', ['1']), 'card', ['1', '2', '3', '4', '5']), 'media', ['1', '2']);
var EMPTY_CONFIG = {};

/**
 * 预设响应式配置
 * 使用 ResizeObserver 实现容器级响应式布局
 */
var RESPONSIVE_PRESETS = {
  /** 响应式布局 - 最小宽度 210px，最多 5 列 */
  responsive210: {
    breakpoints: {
      0: {
        columns: 1,
        gap: 16
      },
      420: {
        columns: 2,
        gap: 16
      },
      630: {
        columns: 3,
        gap: 16
      },
      841: {
        columns: 4,
        gap: 16
      },
      1367: {
        columns: 5,
        gap: 16
      }
    }
  },
  /** 响应式布局 - 最小宽度 330px，最多 4 列 */
  responsive330: {
    breakpoints: {
      0: {
        columns: 1,
        gap: 16
      },
      660: {
        columns: 2,
        gap: 16
      },
      995: {
        columns: 3,
        gap: 16
      },
      1367: {
        columns: 4,
        gap: 16
      }
    }
  }
};

/**
 * 预设布局配置库
 * 定义所有可用的布局模式，配置更加语义化和集中化
 * selector 默认使用竖向flex
 */
var PRESET_LAYOUTS = {
  /** 自动宽度布局 - 内容自适应 */
  autoFlex: {
    className: 'pisell-pro-selector_layout-auto-flex'
  },
  /** 响应式布局 - 最小宽度 210px，最多 5 列 */
  responsive210: {
    responsive: RESPONSIVE_PRESETS.responsive210
  },
  /** 响应式布局 - 最小宽度 330px，最多 4 列 */
  responsive330: {
    responsive: RESPONSIVE_PRESETS.responsive330
  }
};
var VARIANT_PRESET_MAP = {
  default: {
    '1': 'column',
    '2': 'autoFlex',
    '3': 'column',
    '4': 'autoFlex'
  },
  card: {
    '1': 'responsive210',
    '2': 'responsive210',
    '3': 'column',
    '4': 'responsive330',
    '5': 'column'
  },
  media: {
    '1': 'autoFlex',
    '2': 'autoFlex'
  }
};
/**
 * 根据预设配置生成 layout 和 indicatorProps
 * Layout 规则：
 * - 根据 variant 和 preset.variant 计算布局样式
 * IndicatorProps 规则：
 * 1. 当 variant='card' 且 preset.variant='2' 时，indicator 默认 variant='filled'
 * 2. 当 variant='media' 时，indicator 默认 variant='filled'
 * 3. 外部传入的 indicatorProps 优先级更高（会合并到预设配置中）
 */
var usePresetProps = function usePresetProps(_ref) {
  var layout = _ref.layout,
    _ref$mode = _ref.mode,
    mode = _ref$mode === void 0 ? 'single' : _ref$mode,
    preset = _ref.preset,
    _ref$itemLayout = _ref.itemLayout,
    itemLayout = _ref$itemLayout === void 0 ? 'horizontal' : _ref$itemLayout,
    _ref$variant = _ref.variant,
    variant = _ref$variant === void 0 ? 'default' : _ref$variant,
    indicatorProps = _ref.indicatorProps;
  return useMemo(function () {
    // ========== 计算 Layout 配置 ==========
    var layoutConfig = null;

    // select 和没有 preset.variant 时不应用布局配置
    if (variant === 'select' || !(preset !== null && preset !== void 0 && preset.variant)) {
      layoutConfig = layout || null;
    } else {
      // 1. 获取预设的基础布局配置
      var baseLayoutConfig = null;

      // 1.1 校验 preset.variant 是否合法
      var validVariants = VARIANT_MAP[variant] || [];
      var presetVariant = validVariants.includes(preset === null || preset === void 0 ? void 0 : preset.variant) ? preset === null || preset === void 0 ? void 0 : preset.variant : '1';

      // 1.2 根据 variant 和 presetVariant 查找对应的布局配置
      var presetLayoutInfo = VARIANT_PRESET_MAP[variant];
      if (presetLayoutInfo) {
        var layoutType = presetLayoutInfo[presetVariant];
        if (layoutType) {
          // 1.3 从预设布局库中获取完整的布局配置
          var _config = PRESET_LAYOUTS[layoutType];
          if (_config) {
            baseLayoutConfig = _config;
          } else {
            baseLayoutConfig = EMPTY_CONFIG;
          }
        } else {
          baseLayoutConfig = EMPTY_CONFIG;
        }
      } else {
        baseLayoutConfig = EMPTY_CONFIG;
      }

      // 2. 如果用户传入了 layout 配置，与基础配置合并
      if (layout) {
        layoutConfig = _objectSpread(_objectSpread({}, baseLayoutConfig), layout);
      } else {
        layoutConfig = baseLayoutConfig;
      }
    }

    // ========== 计算 IndicatorProps 配置 ==========
    var computedIndicatorProps = {};

    // 判断是否需要设置默认的 filled variant
    var shouldUseFilled = variant === 'media' || variant === 'card' && (preset === null || preset === void 0 ? void 0 : preset.variant) === '2';
    if (shouldUseFilled) {
      // 设置默认值
      computedIndicatorProps = {
        variant: 'filled',
        size: 'small'
      };
    }

    // 外部传入的 indicatorProps 优先级更高，进行合并
    if (indicatorProps) {
      computedIndicatorProps = _objectSpread(_objectSpread({}, computedIndicatorProps), indicatorProps);
    }
    return {
      layout: layoutConfig,
      indicatorProps: computedIndicatorProps
    };
  }, [JSON.stringify(preset), itemLayout, variant, layout, mode, JSON.stringify(indicatorProps)]);
};
export default usePresetProps;