var _excluded = ["children", "className", "hasSide", "hideScaling", "hideToolbar", "isFullWidth", "startDate", "endDate", "today", "range", "unitWidth"];
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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 _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
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 from 'react';
import { isAfter, setHours, startOfToday } from 'date-fns';
import { TimelineProvider } from './context';
import logger from '../../utils/logger';
import { extractChildren } from './helpers/children';
import { TimelineHours } from '.';
import { DEFAULTS } from './constants';
import { TimelineGrid } from './TimelineGrid';
function getHoursBlockSize(children) {
  var hoursChildren = extractChildren(children, [TimelineHours]);
  if (!hoursChildren.length) {
    return null;
  }
  return hoursChildren[0].props.blockSize || DEFAULTS.HOURS_BLOCK_SIZE;
}
function getEndDate(startDate, endDate) {
  if (startDate && endDate && isAfter(startDate, endDate)) {
    logger.error('`startDate` is after `endDate`');
    return null;
  }
  return endDate;
}
export var Timeline = function Timeline(_ref) {
  var children = _ref.children,
    className = _ref.className,
    _ref$hasSide = _ref.hasSide,
    hasSide = _ref$hasSide === void 0 ? false : _ref$hasSide,
    _ref$hideScaling = _ref.hideScaling,
    hideScaling = _ref$hideScaling === void 0 ? false : _ref$hideScaling,
    _ref$hideToolbar = _ref.hideToolbar,
    hideToolbar = _ref$hideToolbar === void 0 ? false : _ref$hideToolbar,
    _ref$isFullWidth = _ref.isFullWidth,
    isFullWidth = _ref$isFullWidth === void 0 ? false : _ref$isFullWidth,
    startDate = _ref.startDate,
    _ref$endDate = _ref.endDate,
    endDate = _ref$endDate === void 0 ? null : _ref$endDate,
    _ref$today = _ref.today,
    today = _ref$today === void 0 ? setHours(startOfToday(), 12) : _ref$today,
    _ref$range = _ref.range,
    range = _ref$range === void 0 ? 1 : _ref$range,
    unitWidth = _ref.unitWidth,
    rest = _objectWithoutProperties(_ref, _excluded);
  var options = {
    range: range,
    startDate: startDate,
    endDate: getEndDate(startDate, endDate),
    hoursBlockSize: getHoursBlockSize(children),
    unitWidth: unitWidth || DEFAULTS.UNIT_WIDTH
  };
  return /*#__PURE__*/React.createElement(TimelineProvider, {
    hasSide: hasSide,
    options: options,
    today: today
  }, /*#__PURE__*/React.createElement(TimelineGrid, _extends({
    className: className,
    hasSide: hasSide,
    hideScaling: hideScaling,
    hideToolbar: hideToolbar,
    isFullWidth: isFullWidth
  }, rest), children));
};
Timeline.displayName = 'Timeline';