"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = formatDate;

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

var pad = function pad(n) {
  return n < 10 ? "0".concat(n) : "".concat(n);
};

function formatDate() {
  var args = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  var outputType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'utc';
  var inputType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'local';

  if (Array.isArray(args) && args.length === 3) {
    var _args = _slicedToArray(args, 3),
        year = _args[0],
        month = _args[1],
        date = _args[2];

    return "".concat(year).concat(pad(month)).concat(pad(date));
  }

  var outDate = new Date(new Date().setUTCSeconds(0, 0));

  if (Array.isArray(args) && args.length > 0 && args[0]) {
    var _args2 = _slicedToArray(args, 6),
        _year = _args2[0],
        _month = _args2[1],
        _date = _args2[2],
        _args2$ = _args2[3],
        hours = _args2$ === void 0 ? 0 : _args2$,
        _args2$2 = _args2[4],
        minutes = _args2$2 === void 0 ? 0 : _args2$2,
        _args2$3 = _args2[5],
        seconds = _args2$3 === void 0 ? 0 : _args2$3;

    if (inputType === 'local') {
      outDate = new Date(_year, _month - 1, _date, hours, minutes, seconds);
    } else {
      outDate = new Date(Date.UTC(_year, _month - 1, _date, hours, minutes, seconds));
    }
  }

  if (outputType === 'local') {
    return [outDate.getFullYear(), pad(outDate.getMonth() + 1), pad(outDate.getDate()), 'T', pad(outDate.getHours()), pad(outDate.getMinutes()), pad(outDate.getSeconds())].join('');
  }

  return [outDate.getUTCFullYear(), pad(outDate.getUTCMonth() + 1), pad(outDate.getUTCDate()), 'T', pad(outDate.getUTCHours()), pad(outDate.getUTCMinutes()), pad(outDate.getUTCSeconds()), 'Z'].join('');
}