"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.SpinLoading = void 0;
var _react = _interopRequireWildcard(require("react"));
var _nativeProps = require("../../utils/native-props");
var _withDefaultProps = require("../../utils/with-default-props");
var _web = require("@react-spring/web");
var _reduceAndRestoreMotion = require("../../utils/reduce-and-restore-motion");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
const classPrefix = 'adm-spin-loading';
const colorRecord = {
  default: 'var(--ldkj-color-weak)',
  primary: 'var(--ldkj-color-primary)',
  white: 'var(--ldkj-color-white)'
};
const defaultProps = {
  color: 'default'
};
const circumference = 15 * 3.14159265358979 * 2;
const SpinLoading = exports.SpinLoading = (0, _react.memo)(p => {
  var _a;
  const props = (0, _withDefaultProps.mergeProps)(defaultProps, p);
  const motionReduced = (0, _reduceAndRestoreMotion.useMotionReduced)();
  const {
    percent
  } = (0, _web.useSpring)({
    cancel: motionReduced,
    loop: {
      reverse: true
    },
    from: {
      percent: 80
    },
    to: {
      percent: 30
    },
    config: {
      duration: 1200
    }
  });
  return (0, _nativeProps.withNativeProps)(props, _react.default.createElement(_web.animated.div, {
    className: classPrefix,
    style: {
      '--color': (_a = colorRecord[props.color]) !== null && _a !== void 0 ? _a : props.color,
      '--percent': percent
    }
  }, _react.default.createElement("svg", {
    className: `${classPrefix}-svg`,
    viewBox: '0 0 32 32'
  }, _react.default.createElement(_web.animated.circle, {
    className: `${classPrefix}-fill`,
    fill: 'transparent',
    strokeWidth: '2',
    strokeDasharray: circumference,
    strokeDashoffset: percent,
    strokeLinecap: 'square',
    r: 15,
    cx: 16,
    cy: 16
  }))));
});