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); }
/**
 * MapLayer - 楼层图底层
 * 负责背景（无/纯色/图片/SVG）、网格线、padding、gap
 */
import React from 'react';
import classNames from 'classnames';
import "./MapLayer.less";
var PREFIX = 'pisell-floor-map-layout';
/**
 * 解析 padding/gap 为 CSS 值
 */
function toCssSize(v) {
  if (v === undefined) return undefined;
  return typeof v === 'number' ? "".concat(v, "px") : v;
}
export function MapLayer(props) {
  var _config$snapStep;
  var _props$config = props.config,
    config = _props$config === void 0 ? {} : _props$config,
    _props$contentWidth = props.contentWidth,
    contentWidth = _props$contentWidth === void 0 ? 0 : _props$contentWidth,
    _props$contentHeight = props.contentHeight,
    contentHeight = _props$contentHeight === void 0 ? 0 : _props$contentHeight,
    _props$cellSize = props.cellSize,
    cellSize = _props$cellSize === void 0 ? 64 : _props$cellSize,
    _props$preferCanvasGr = props.preferCanvasGrid,
    preferCanvasGrid = _props$preferCanvasGr === void 0 ? false : _props$preferCanvasGr,
    _props$pointerEventsN = props.pointerEventsNone,
    pointerEventsNone = _props$pointerEventsN === void 0 ? false : _props$pointerEventsN,
    children = props.children,
    className = props.className;
  var _config$backgroundTyp = config.backgroundType,
    backgroundType = _config$backgroundTyp === void 0 ? 'none' : _config$backgroundTyp,
    backgroundColor = config.backgroundColor,
    backgroundImage = config.backgroundImage,
    backgroundSvg = config.backgroundSvg,
    _config$showGrid = config.showGrid,
    showGrid = _config$showGrid === void 0 ? false : _config$showGrid,
    padding = config.padding,
    gap = config.gap;
  var paddingCss = toCssSize(padding);
  var gapCss = toCssSize(gap);
  var backgroundStyle = {};
  if (preferCanvasGrid) {
    backgroundStyle.backgroundColor = 'transparent';
  } else if (backgroundType === 'color' && backgroundColor) {
    backgroundStyle.backgroundColor = backgroundColor;
  }
  if (backgroundType === 'image' && backgroundImage) {
    backgroundStyle.backgroundImage = "url(".concat(backgroundImage, ")");
    backgroundStyle.backgroundSize = 'cover';
    backgroundStyle.backgroundPosition = 'center';
  }
  if (backgroundType === 'svg' && backgroundSvg) {
    var isUrl = backgroundSvg.startsWith('http') || backgroundSvg.startsWith('/');
    backgroundStyle.backgroundImage = isUrl ? "url(".concat(backgroundSvg, ")") : "url(\"data:image/svg+xml,".concat(encodeURIComponent(backgroundSvg), "\")");
    backgroundStyle.backgroundSize = 'cover';
    backgroundStyle.backgroundPosition = 'center';
  }
  var containerStyle = _objectSpread({
    padding: paddingCss,
    gap: gapCss
  }, pointerEventsNone ? {
    pointerEvents: 'none'
  } : {});

  /** 网格线：用 CSS 线性渐变模拟（默认不小于 50px，避免像素模式下格线过密） */
  var snapStep = Math.max(1, Number((_config$snapStep = config.snapStep) !== null && _config$snapStep !== void 0 ? _config$snapStep : 1) || 1);
  var gridSize = Math.max(50, Math.round(cellSize * snapStep));
  var gridStyle = showGrid ? {
    backgroundImage: "\n          linear-gradient(to right, rgba(0,0,0,0.08) 1px, transparent 1px),\n          linear-gradient(to bottom, rgba(0,0,0,0.08) 1px, transparent 1px)\n        ",
    backgroundSize: "".concat(gridSize, "px ").concat(gridSize, "px")
  } : {};
  return /*#__PURE__*/React.createElement("div", {
    className: classNames("".concat(PREFIX, "-map-layer"), className),
    style: _objectSpread(_objectSpread(_objectSpread({}, backgroundStyle), containerStyle), gridStyle)
  }, children);
}
export default MapLayer;