var _excluded = ["lineWidth", "size", "time", "duration", "delay", "style"];

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

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, { forwardRef, useRef, useImperativeHandle } from 'react';
var BiClock = forwardRef(function (_ref, ref) {
  var _ref$lineWidth = _ref.lineWidth,
      lineWidth = _ref$lineWidth === void 0 ? 2 : _ref$lineWidth,
      _ref$size = _ref.size,
      size = _ref$size === void 0 ? 50 : _ref$size,
      time = _ref.time,
      _ref$duration = _ref.duration,
      duration = _ref$duration === void 0 ? 500 : _ref$duration,
      _ref$delay = _ref.delay,
      delay = _ref$delay === void 0 ? 0 : _ref$delay,
      style = _ref.style,
      others = _objectWithoutPropertiesLoose(_ref, _excluded);

  var rootRef = useRef(null);
  var hourRef = useRef(null);
  var minuteRef = useRef(null);
  useImperativeHandle(ref, function () {
    return rootRef.current;
  });

  function getHourDeg(hour) {
    return hour * 30;
  }

  function getMinuteDeg(minute) {
    return minute * 6;
  }

  function aniRotate() {
    var hour = '00';
    var minute = '00';

    if (/\d{2}:\d{2}/.test(time)) {
      hour = time.split(':')[0];
      minute = time.split(':')[1];
    }

    setTimeout(function () {
      if (hourRef.current) {
        hourRef.current.style.WebkitTransitionDuration = duration + "ms";
        hourRef.current.style.WebkitTransform = "rotate(" + getHourDeg(hour) + "deg)";
      }

      if (minuteRef.current) {
        minuteRef.current.style.WebkitTransitionDuration = duration + "ms";
        minuteRef.current.style.WebkitTransform = "rotate(" + getMinuteDeg(minute) + "deg)";
      }
    }, delay);
  } // 动画旋转


  aniRotate();
  return /*#__PURE__*/React.createElement("div", _extends({}, others, {
    ref: rootRef,
    className: "bi-clock" + (others.className ? ' ' + others.className : ''),
    style: Object.assign({
      width: size + "px",
      height: size + "px",
      borderWidth: lineWidth + "px"
    }, style || {})
  }), /*#__PURE__*/React.createElement("div", {
    ref: hourRef,
    className: "bi-clock-hour",
    style: {
      width: lineWidth + "px"
    }
  }), /*#__PURE__*/React.createElement("div", {
    ref: minuteRef,
    className: "bi-clock-minute",
    style: {
      width: lineWidth + "px"
    }
  }), /*#__PURE__*/React.createElement("div", {
    className: "bi-clock-origin",
    style: {
      width: lineWidth + 1 + "px",
      height: lineWidth + 1 + "px"
    }
  }));
});
export default BiClock;