import { cD as isSymbol, cE as isObject, cF as root, bU as _slicedToArray, cw as SizeContext, c3 as ConfigContext, bW as _defineProperty, aA as jsxRuntimeExports, cG as ForwardRef } from './MapEditView-67426f04.js';
import classNames from 'classnames';
import * as React from 'react';

/** Used to match a single whitespace character. */
var reWhitespace = /\s/;

/**
 * Used by `_.trim` and `_.trimEnd` to get the index of the last non-whitespace
 * character of `string`.
 *
 * @private
 * @param {string} string The string to inspect.
 * @returns {number} Returns the index of the last non-whitespace character.
 */
function trimmedEndIndex(string) {
  var index = string.length;

  while (index-- && reWhitespace.test(string.charAt(index))) {}
  return index;
}

/** Used to match leading whitespace. */
var reTrimStart = /^\s+/;

/**
 * The base implementation of `_.trim`.
 *
 * @private
 * @param {string} string The string to trim.
 * @returns {string} Returns the trimmed string.
 */
function baseTrim(string) {
  return string
    ? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, '')
    : string;
}

/** Used as references for various `Number` constants. */
var NAN = 0 / 0;

/** Used to detect bad signed hexadecimal string values. */
var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;

/** Used to detect binary string values. */
var reIsBinary = /^0b[01]+$/i;

/** Used to detect octal string values. */
var reIsOctal = /^0o[0-7]+$/i;

/** Built-in method references without a dependency on `root`. */
var freeParseInt = parseInt;

/**
 * Converts `value` to a number.
 *
 * @static
 * @memberOf _
 * @since 4.0.0
 * @category Lang
 * @param {*} value The value to process.
 * @returns {number} Returns the number.
 * @example
 *
 * _.toNumber(3.2);
 * // => 3.2
 *
 * _.toNumber(Number.MIN_VALUE);
 * // => 5e-324
 *
 * _.toNumber(Infinity);
 * // => Infinity
 *
 * _.toNumber('3.2');
 * // => 3.2
 */
function toNumber(value) {
  if (typeof value == 'number') {
    return value;
  }
  if (isSymbol(value)) {
    return NAN;
  }
  if (isObject(value)) {
    var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
    value = isObject(other) ? (other + '') : other;
  }
  if (typeof value != 'string') {
    return value === 0 ? value : +value;
  }
  value = baseTrim(value);
  var isBinary = reIsBinary.test(value);
  return (isBinary || reIsOctal.test(value))
    ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
    : (reIsBadHex.test(value) ? NAN : +value);
}

/**
 * Gets the timestamp of the number of milliseconds that have elapsed since
 * the Unix epoch (1 January 1970 00:00:00 UTC).
 *
 * @static
 * @memberOf _
 * @since 2.4.0
 * @category Date
 * @returns {number} Returns the timestamp.
 * @example
 *
 * _.defer(function(stamp) {
 *   console.log(_.now() - stamp);
 * }, _.now());
 * // => Logs the number of milliseconds it took for the deferred invocation.
 */
var now = function() {
  return root.Date.now();
};

var now$1 = now;

/** Error message constants. */
var FUNC_ERROR_TEXT = 'Expected a function';

/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeMax = Math.max,
    nativeMin = Math.min;

/**
 * Creates a debounced function that delays invoking `func` until after `wait`
 * milliseconds have elapsed since the last time the debounced function was
 * invoked. The debounced function comes with a `cancel` method to cancel
 * delayed `func` invocations and a `flush` method to immediately invoke them.
 * Provide `options` to indicate whether `func` should be invoked on the
 * leading and/or trailing edge of the `wait` timeout. The `func` is invoked
 * with the last arguments provided to the debounced function. Subsequent
 * calls to the debounced function return the result of the last `func`
 * invocation.
 *
 * **Note:** If `leading` and `trailing` options are `true`, `func` is
 * invoked on the trailing edge of the timeout only if the debounced function
 * is invoked more than once during the `wait` timeout.
 *
 * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
 * until to the next tick, similar to `setTimeout` with a timeout of `0`.
 *
 * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
 * for details over the differences between `_.debounce` and `_.throttle`.
 *
 * @static
 * @memberOf _
 * @since 0.1.0
 * @category Function
 * @param {Function} func The function to debounce.
 * @param {number} [wait=0] The number of milliseconds to delay.
 * @param {Object} [options={}] The options object.
 * @param {boolean} [options.leading=false]
 *  Specify invoking on the leading edge of the timeout.
 * @param {number} [options.maxWait]
 *  The maximum time `func` is allowed to be delayed before it's invoked.
 * @param {boolean} [options.trailing=true]
 *  Specify invoking on the trailing edge of the timeout.
 * @returns {Function} Returns the new debounced function.
 * @example
 *
 * // Avoid costly calculations while the window size is in flux.
 * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
 *
 * // Invoke `sendMail` when clicked, debouncing subsequent calls.
 * jQuery(element).on('click', _.debounce(sendMail, 300, {
 *   'leading': true,
 *   'trailing': false
 * }));
 *
 * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
 * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
 * var source = new EventSource('/stream');
 * jQuery(source).on('message', debounced);
 *
 * // Cancel the trailing debounced invocation.
 * jQuery(window).on('popstate', debounced.cancel);
 */
function debounce(func, wait, options) {
  var lastArgs,
      lastThis,
      maxWait,
      result,
      timerId,
      lastCallTime,
      lastInvokeTime = 0,
      leading = false,
      maxing = false,
      trailing = true;

  if (typeof func != 'function') {
    throw new TypeError(FUNC_ERROR_TEXT);
  }
  wait = toNumber(wait) || 0;
  if (isObject(options)) {
    leading = !!options.leading;
    maxing = 'maxWait' in options;
    maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
    trailing = 'trailing' in options ? !!options.trailing : trailing;
  }

  function invokeFunc(time) {
    var args = lastArgs,
        thisArg = lastThis;

    lastArgs = lastThis = undefined;
    lastInvokeTime = time;
    result = func.apply(thisArg, args);
    return result;
  }

  function leadingEdge(time) {
    // Reset any `maxWait` timer.
    lastInvokeTime = time;
    // Start the timer for the trailing edge.
    timerId = setTimeout(timerExpired, wait);
    // Invoke the leading edge.
    return leading ? invokeFunc(time) : result;
  }

  function remainingWait(time) {
    var timeSinceLastCall = time - lastCallTime,
        timeSinceLastInvoke = time - lastInvokeTime,
        timeWaiting = wait - timeSinceLastCall;

    return maxing
      ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke)
      : timeWaiting;
  }

  function shouldInvoke(time) {
    var timeSinceLastCall = time - lastCallTime,
        timeSinceLastInvoke = time - lastInvokeTime;

    // Either this is the first call, activity has stopped and we're at the
    // trailing edge, the system time has gone backwards and we're treating
    // it as the trailing edge, or we've hit the `maxWait` limit.
    return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
      (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
  }

  function timerExpired() {
    var time = now$1();
    if (shouldInvoke(time)) {
      return trailingEdge(time);
    }
    // Restart the timer.
    timerId = setTimeout(timerExpired, remainingWait(time));
  }

  function trailingEdge(time) {
    timerId = undefined;

    // Only invoke if we have `lastArgs` which means `func` has been
    // debounced at least once.
    if (trailing && lastArgs) {
      return invokeFunc(time);
    }
    lastArgs = lastThis = undefined;
    return result;
  }

  function cancel() {
    if (timerId !== undefined) {
      clearTimeout(timerId);
    }
    lastInvokeTime = 0;
    lastArgs = lastCallTime = lastThis = timerId = undefined;
  }

  function flush() {
    return timerId === undefined ? result : trailingEdge(now$1());
  }

  function debounced() {
    var time = now$1(),
        isInvoking = shouldInvoke(time);

    lastArgs = arguments;
    lastThis = this;
    lastCallTime = time;

    if (isInvoking) {
      if (timerId === undefined) {
        return leadingEdge(lastCallTime);
      }
      if (maxing) {
        // Handle invocations in a tight loop.
        clearTimeout(timerId);
        timerId = setTimeout(timerExpired, wait);
        return invokeFunc(lastCallTime);
      }
    }
    if (timerId === undefined) {
      timerId = setTimeout(timerExpired, wait);
    }
    return result;
  }
  debounced.cancel = cancel;
  debounced.flush = flush;
  return debounced;
}

function shouldDelay(spinning, delay) {
  return !!spinning && !!delay && !isNaN(Number(delay));
}
var Spin = function Spin(props) {
  var _classNames;
  var customizePrefixCls = props.prefixCls,
    _props$spinning = props.spinning,
    customSpinning = _props$spinning === void 0 ? true : _props$spinning,
    _props$delay = props.delay,
    delay = _props$delay === void 0 ? 0 : _props$delay,
    className = props.className,
    rootClassName = props.rootClassName,
    _props$size = props.size,
    customSize = _props$size === void 0 ? 'middle' : _props$size,
    tip = props.tip,
    wrapperClassName = props.wrapperClassName,
    style = props.style,
    children = props.children,
    brand = props.brand,
    fillParent = props.fillParent;
  var _React$useState = React.useState(function () {
      return customSpinning && !shouldDelay(customSpinning, delay);
    }),
    _React$useState2 = _slicedToArray(_React$useState, 2),
    spinning = _React$useState2[0],
    setSpinning = _React$useState2[1];
  React.useEffect(function () {
    if (customSpinning) {
      var showSpinning = debounce(function () {
        setSpinning(true);
      }, delay);
      showSpinning();
      return function () {
        var _showSpinning$cancel;
        showSpinning === null || showSpinning === void 0 ? void 0 : (_showSpinning$cancel = showSpinning.cancel) === null || _showSpinning$cancel === void 0 ? void 0 : _showSpinning$cancel.call(showSpinning);
      };
    }
    setSpinning(false);
  }, [delay, customSpinning]);
  var isNestedPattern = React.useMemo(function () {
    return typeof children !== 'undefined' || !!fillParent;
  }, [children]);
  var contextSize = React.useContext(SizeContext);
  var size = customSize || contextSize;
  var _React$useContext = React.useContext(ConfigContext),
    getPrefixCls = _React$useContext.getPrefixCls;
  var prefixCls = getPrefixCls('spin', customizePrefixCls);
  var spinClassName = classNames(prefixCls, (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-sm"), size === 'small'), _defineProperty(_classNames, "".concat(prefixCls, "-lg"), size === 'large'), _defineProperty(_classNames, "".concat(prefixCls, "-spinning"), spinning), _defineProperty(_classNames, "".concat(prefixCls, "-show-text"), !!tip), _classNames), className, rootClassName);
  var containerClassName = classNames("".concat(prefixCls, "-container"), _defineProperty({}, "".concat(prefixCls, "-blur"), spinning));
  var loadingDom = /*#__PURE__*/jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, {
    children: brand ? /*#__PURE__*/jsxRuntimeExports.jsx("i", {
      className: classNames("".concat(prefixCls, "-loading"), 'metro-icon'),
      children: /*#__PURE__*/jsxRuntimeExports.jsxs("svg", {
        width: "1em",
        height: "1em",
        viewBox: "0 0 32 32",
        fill: "none",
        xmlns: "http://www.w3.org/2000/svg",
        children: [/*#__PURE__*/jsxRuntimeExports.jsx("path", {
          fillRule: "evenodd",
          clipRule: "evenodd",
          d: "M3.9452 16C3.9452 9.34232 9.34232 3.9452 16 3.9452C22.6577 3.9452 28.0548 9.34232 28.0548 16C28.0548 22.6577 22.6577 28.0548 16 28.0548C9.34232 28.0548 3.9452 22.6577 3.9452 16ZM16 0C7.16344 -3.86258e-07 3.86258e-07 7.16344 0 16C-3.86258e-07 24.8365 7.16344 32 16 32C24.8365 32 32 24.8365 32 16C32 7.16344 24.8365 3.86258e-07 16 0Z",
          fill: "#838C9C",
          fillOpacity: "0.07"
        }), /*#__PURE__*/jsxRuntimeExports.jsx("path", {
          fillRule: "evenodd",
          clipRule: "evenodd",
          d: "M1.9726 14.0274C0.883164 14.0274 4.76209e-08 14.9106 0 16C-1.28982e-07 18.9508 0.81599 21.8441 2.35776 24.36C3.89952 26.8759 6.107 28.9165 8.73615 30.2561C11.3653 31.5957 14.3137 32.1822 17.2553 31.9507C20.197 31.7192 23.0173 30.6787 25.4046 28.9443C27.7918 27.2099 29.6529 24.8491 30.7821 22.1229C31.9113 19.3968 32.2646 16.4115 31.803 13.4971C31.3414 10.5826 30.0828 7.85262 28.1665 5.60885C26.2501 3.36508 23.7506 1.69495 20.9443 0.783114C19.9081 0.446459 18.7953 1.01348 18.4586 2.0496C18.122 3.08572 18.689 4.19857 19.7251 4.53523C21.8395 5.22222 23.7227 6.48054 25.1665 8.17105C26.6104 9.86157 27.5586 11.9184 27.9064 14.1142C28.2541 16.31 27.9879 18.5592 27.1372 20.6132C26.2864 22.6671 24.8842 24.4458 23.0856 25.7525C21.287 27.0593 19.1621 27.8432 16.9458 28.0176C14.7295 28.1921 12.5081 27.7502 10.5272 26.7409C8.54637 25.7316 6.8832 24.1942 5.7216 22.2986C4.55999 20.4031 3.9452 18.2232 3.9452 16C3.9452 14.9106 3.06204 14.0274 1.9726 14.0274Z",
          fill: "url(#paint0_linear_3878_63369)"
        }), /*#__PURE__*/jsxRuntimeExports.jsx("defs", {
          children: /*#__PURE__*/jsxRuntimeExports.jsxs("linearGradient", {
            id: "paint0_linear_3878_63369",
            x1: "-1",
            y1: "19",
            x2: "15",
            y2: "-9.5",
            gradientUnits: "userSpaceOnUse",
            children: [/*#__PURE__*/jsxRuntimeExports.jsx("stop", {
              stopColor: "#6994F0"
            }), /*#__PURE__*/jsxRuntimeExports.jsx("stop", {
              offset: "1",
              stopColor: "#5588F4",
              stopOpacity: "0"
            })]
          })
        })]
      })
    }) : /*#__PURE__*/jsxRuntimeExports.jsx(ForwardRef, {
      className: "".concat(prefixCls, "-loading")
    })
  });
  var spinElement = /*#__PURE__*/jsxRuntimeExports.jsxs("div", {
    style: style,
    className: spinClassName,
    "aria-live": "polite",
    "aria-busy": spinning,
    children: [loadingDom, tip ? /*#__PURE__*/jsxRuntimeExports.jsx("div", {
      className: "".concat(prefixCls, "-text"),
      children: tip
    }) : null]
  });
  if (isNestedPattern) {
    return /*#__PURE__*/jsxRuntimeExports.jsxs("div", {
      className: classNames("".concat(prefixCls, "-nested-loading"), _defineProperty({}, "".concat(prefixCls, "-fill-parent"), fillParent), wrapperClassName),
      children: [spinning && /*#__PURE__*/jsxRuntimeExports.jsx("div", {
        children: spinElement
      }, "loading"), /*#__PURE__*/jsxRuntimeExports.jsx("div", {
        className: containerClassName,
        children: children
      }, "container")]
    });
  }
  return spinElement;
};
Spin.displayName = 'Spin';

export { Spin as S };
