"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.TimelineSection = void 0;

var _preact = require("preact");

var _milliseconds = _interopRequireDefault(require("milliseconds"));

var _ = require("../");

var _componentCode = _interopRequireDefault(require("./component-code"));

var _section = _interopRequireDefault(require("./section"));

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

const randomize = (max = 20) => Math.round(Math.random() * max);

const getRandomEvents = (start = Date.now() - _milliseconds.default.minutes(randomize(100))) => ({
  caseStart: start,
  vitalsEnd: start + _milliseconds.default.minutes(30 + randomize(40)),
  ivStart: start + _milliseconds.default.minutes(3 + randomize()),
  ivEnd: start + _milliseconds.default.minutes(34 + randomize(40)),
  surgeryStart: start + _milliseconds.default.minutes(10 + randomize()),
  surgeryEnd: start + _milliseconds.default.minutes(30 + randomize(40)),
  anesthesiaStart: start + _milliseconds.default.minutes(10 + randomize()),
  anesthesiaEnd: start + _milliseconds.default.minutes(23 + randomize(40)),
  recoveryStart: start + _milliseconds.default.minutes(23 + randomize()),
  end: start + _milliseconds.default.minutes(63 + randomize(40))
});

class TimelineSection extends _preact.Component {
  constructor(props) {
    super(props);
    this.updateState();
    this.setState({
      events2: getRandomEvents()
    });
    setInterval(() => this.updateState(), 2000);
  }

  updateState() {
    this.setState({
      events: getRandomEvents()
    });
  }

  render() {
    return (0, _preact.h)(_section.default, {
      title: "Timeline"
    }, (0, _preact.h)(_componentCode.default, {
      name: "Timeline",
      code: ""
    }, (0, _preact.h)(_.CaseTimeline, {
      timeLabels: true,
      events: this.state.events
    }), (0, _preact.h)(_.CaseTimeline, {
      timeLabels: true,
      events: this.state.events2
    })));
  }

}

exports.TimelineSection = TimelineSection;