'use strict';

exports.__esModule = true;
exports.default = undefined;

var _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; };

var _class, _temp;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var BiClock = (_temp = _class = function (_Component) {
  _inherits(BiClock, _Component);

  function BiClock(props) {
    _classCallCheck(this, BiClock);

    var _this = _possibleConstructorReturn(this, _Component.call(this, props));

    _this.getHourDeg = function (hour) {
      return hour * 30;
    };

    _this.getMinuteDeg = function (minute) {
      return minute * 6;
    };

    _this.aniRotate = function () {
      var _this$props = _this.props,
          time = _this$props.time,
          duration = _this$props.duration;

      var hour = '00';
      var minute = '00';
      if (/\d{2}:\d{2}/.test(time)) {
        hour = time.split(':')[0];
        minute = time.split(':')[1];
      }
      setTimeout(function () {
        if (_this.$hour) {
          _this.$hour.style.WebkitTransitionDuration = duration + 'ms';
          _this.$hour.style.WebkitTransform = 'rotate(' + _this.getHourDeg(hour) + 'deg)';
        }
        if (_this.$minute) {
          _this.$minute.style.WebkitTransitionDuration = duration + 'ms';
          _this.$minute.style.WebkitTransform = 'rotate(' + _this.getMinuteDeg(minute) + 'deg)';
        }
      }, _this.props.delay);
    };

    return _this;
  }

  BiClock.prototype.render = function render() {
    var _this2 = this;

    var _props = this.props,
        style = _props.style,
        lineWidth = _props.lineWidth,
        size = _props.size,
        time = _props.time,
        duration = _props.duration,
        delay = _props.delay,
        others = _objectWithoutProperties(_props, ['style', 'lineWidth', 'size', 'time', 'duration', 'delay']);
    // 动画旋转


    this.aniRotate();
    return _react2.default.createElement(
      'div',
      _extends({}, others, { ref: function ref(el) {
          _this2.$el = el;
        }, className: 'bi-clock' + (others.className ? ' ' + others.className : ''), style: Object.assign({ width: size + 'px', height: size + 'px', borderWidth: lineWidth + 'px' }, style || {}) }),
      _react2.default.createElement('div', { ref: function ref(el) {
          _this2.$hour = el;
        }, className: 'bi-clock-hour', style: { width: lineWidth + 'px' } }),
      _react2.default.createElement('div', { ref: function ref(el) {
          _this2.$minute = el;
        }, className: 'bi-clock-minute', style: { width: lineWidth + 'px' } }),
      _react2.default.createElement('div', { className: 'bi-clock-origin', style: { width: lineWidth + 1 + 'px', height: lineWidth + 1 + 'px' } })
    );
  };

  return BiClock;
}(_react.Component), _class.defaultProps = {
  lineWidth: 2,
  size: 50,
  duration: 500,
  delay: 0
}, _temp);
exports.default = BiClock;
BiClock.propTypes = process.env.NODE_ENV !== "production" ? {
  style: _propTypes2.default.object,
  lineWidth: _propTypes2.default.number, // 边框宽度
  size: _propTypes2.default.number, // 大小,px
  time: _propTypes2.default.string, // hh:mm
  duration: _propTypes2.default.number, // 时长
  delay: _propTypes2.default.number // 延时
} : {};
module.exports = exports['default'];