"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.AnimatedTick = void 0;
var _react = require("react");
var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
var _reactNativeSvg = _interopRequireWildcard(require("react-native-svg"));
var _jsxRuntime = require("react/jsx-runtime");
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 AnimatedPath = _reactNativeReanimated.default.createAnimatedComponent(_reactNativeSvg.Path);
// Tick is designed to be within a 24x24 box
const TickSVGPath = "m7 12 4 4 7-7";

/**
 * Animated tick used as a small brick for the selection components (e.g: Checkbox, Radio, etc…)
 * It comes without any state logic.
 *
 */
const AnimatedTick = ({
  size,
  progress,
  ...pathProps
}) => {
  const [length, setLength] = (0, _react.useState)(0);
  const ref = (0, _reactNativeReanimated.useAnimatedRef)();

  // SVG trick to animate the checkmark
  // Ref: https://github.com/craftzdog/react-native-checkbox-reanimated/blob/master/src/animated-stroke.tsx
  const animatedProps = (0, _reactNativeReanimated.useAnimatedProps)(() => ({
    strokeDashoffset: Math.max(0, length - length * progress.value - 0.1)
  }));
  const onLayout = () => {
    // "as any" to fix an annoying TS error.
    // I honestly don't know which type to use
    const currentRef = ref.current;
    setLength(currentRef.getTotalLength());
  };
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeSvg.default, {
    viewBox: `0 0 24 24`,
    ...(size ? {
      width: size,
      height: size
    } : {}),
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(AnimatedPath, {
      ref: ref,
      onLayout: onLayout,
      d: TickSVGPath,
      animatedProps: animatedProps,
      strokeDasharray: length,
      strokeWidth: 2,
      strokeLinecap: "round",
      strokeLinejoin: "round",
      fill: "none",
      ...pathProps
    })
  });
};
exports.AnimatedTick = AnimatedTick;
//# sourceMappingURL=AnimatedTick.js.map