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); }
var _excluded = ["responsive", "children"];
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); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import React, { useMemo } from 'react';
import List from "./List";
import { useDevice } from "./hooks/useDevice";
/**
 * ResponsiveWrapper 响应式包装器组件
 * 根据不同设备类型自动选择合适的配置
 */
var ResponsiveWrapper = function ResponsiveWrapper(props) {
  var responsive = props.responsive,
    children = props.children,
    listProps = _objectWithoutProperties(props, _excluded);
  var deviceInfo = useDevice();
  console.log('deviceInfo', deviceInfo);

  // 根据设备类型合并配置
  var finalProps = useMemo(function () {
    if (!responsive) {
      // 如果没有响应式配置，直接返回基础props
      var _classNames = [listProps.className, "list-device-".concat(deviceInfo.type) // 添加设备类型类名
      ].filter(Boolean).join(' ');
      return _objectSpread(_objectSpread({}, listProps), {}, {
        className: _classNames
      });
    }
    var pc = responsive.pc,
      pad = responsive.pad,
      mobile = responsive.mobile;
    var deviceSpecificProps = {};

    // 根据设备类型选择特定配置
    switch (deviceInfo.type) {
      case 'mobile':
        deviceSpecificProps = mobile || {};
        break;
      case 'pad':
        deviceSpecificProps = pad || {};
        break;
      case 'pc':
        deviceSpecificProps = pc || {};
        break;
      default:
        deviceSpecificProps = {};
    }

    // 合并配置：基础props < 设备特定配置
    var mergedProps = _objectSpread(_objectSpread({}, listProps), deviceSpecificProps);

    // 处理className合并
    var classNames = [mergedProps.className, "list-device-".concat(deviceInfo.type) // 添加设备类型类名
    ].filter(Boolean).join(' ');
    return _objectSpread(_objectSpread({}, mergedProps), {}, {
      className: classNames
    });
  }, [responsive, deviceInfo.type, listProps]);

  // 基于设备类型的默认配置调整
  var optimizedProps = useMemo(function () {
    var _props$columns, _props$columnGap, _props$rowGap, _props$defaultPageSiz, _props$columns2, _props$columnGap2, _props$rowGap2, _props$defaultPageSiz2, _props$columns3, _props$columnGap3, _props$rowGap3, _props$defaultPageSiz3;
    var props = _objectSpread({}, finalProps);

    // 根据设备类型进行自动优化
    switch (deviceInfo.type) {
      case 'mobile':
        // 移动端优化
        return _objectSpread(_objectSpread({}, props), {}, {
          // 移动端默认使用垂直布局
          layoutDirection: props.layoutDirection || 'vertical',
          // 移动端默认单列显示
          columns: (_props$columns = props.columns) !== null && _props$columns !== void 0 ? _props$columns : 1,
          // 移动端减少间距
          columnGap: (_props$columnGap = props.columnGap) !== null && _props$columnGap !== void 0 ? _props$columnGap : 8,
          rowGap: (_props$rowGap = props.rowGap) !== null && _props$rowGap !== void 0 ? _props$rowGap : 8,
          // 移动端适合滚动加载
          paginationType: props.paginationType || 'scroll',
          // 移动端默认较小的页面大小
          defaultPageSize: (_props$defaultPageSiz = props.defaultPageSize) !== null && _props$defaultPageSiz !== void 0 ? _props$defaultPageSiz : 10
        });
      case 'pad':
        // 平板端优化
        return _objectSpread(_objectSpread({}, props), {}, {
          // 平板端可以使用2列
          columns: (_props$columns2 = props.columns) !== null && _props$columns2 !== void 0 ? _props$columns2 : 2,
          // 平板端适中的间距
          columnGap: (_props$columnGap2 = props.columnGap) !== null && _props$columnGap2 !== void 0 ? _props$columnGap2 : 12,
          rowGap: (_props$rowGap2 = props.rowGap) !== null && _props$rowGap2 !== void 0 ? _props$rowGap2 : 12,
          // 平板端适合分页或滚动加载
          paginationType: props.paginationType || 'more',
          // 平板端中等的页面大小
          defaultPageSize: (_props$defaultPageSiz2 = props.defaultPageSize) !== null && _props$defaultPageSiz2 !== void 0 ? _props$defaultPageSiz2 : 12
        });
      case 'pc':
        // PC端优化
        return _objectSpread(_objectSpread({}, props), {}, {
          // PC端可以使用更多列
          columns: (_props$columns3 = props.columns) !== null && _props$columns3 !== void 0 ? _props$columns3 : 3,
          // PC端较大的间距
          columnGap: (_props$columnGap3 = props.columnGap) !== null && _props$columnGap3 !== void 0 ? _props$columnGap3 : 16,
          rowGap: (_props$rowGap3 = props.rowGap) !== null && _props$rowGap3 !== void 0 ? _props$rowGap3 : 16,
          // PC端适合传统分页
          paginationType: props.paginationType || 'pager',
          // PC端较大的页面大小
          defaultPageSize: (_props$defaultPageSiz3 = props.defaultPageSize) !== null && _props$defaultPageSiz3 !== void 0 ? _props$defaultPageSiz3 : 15
        });
      default:
        return props;
    }
  }, [finalProps, deviceInfo.type]);
  return /*#__PURE__*/React.createElement(List, optimizedProps, children);
};

/**
 * 用于创建响应式配置的工具函数
 */
export var createResponsiveConfig = function createResponsiveConfig(overrides) {
  return {
    pc: overrides === null || overrides === void 0 ? void 0 : overrides.pc,
    pad: overrides === null || overrides === void 0 ? void 0 : overrides.pad,
    mobile: overrides === null || overrides === void 0 ? void 0 : overrides.mobile
  };
};
export default ResponsiveWrapper;