'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});

var _typeof2 = require('babel-runtime/helpers/typeof');

var _typeof3 = _interopRequireDefault(_typeof2);

exports.formatFn = formatFn;

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

function formatIt(date, form) {
    var pad = function pad(n) {
        return n < 10 ? '0' + n : n;
    };
    var dateStr = date.getFullYear() + '-' + pad(date.getMonth() + 1) + '-' + pad(date.getDate());
    var timeStr = pad(date.getHours()) + ':' + pad(date.getMinutes());
    if (form === 'YYYY-MM-DD') {
        return dateStr;
    }
    if (form === 'HH:mm') {
        return timeStr;
    }
    return dateStr + ' ' + timeStr;
}
function formatFn(instance, value) {
    var formatsEnum = {
        date: 'YYYY-MM-DD',
        time: 'HH:mm',
        datetime: 'YYYY-MM-DD HH:mm'
    };
    var format = instance.props.format;

    var type = typeof format === 'undefined' ? 'undefined' : (0, _typeof3['default'])(format);
    if (type === 'string') {
        return formatIt(value, format);
    }
    if (type === 'function') {
        return format(value);
    }
    return formatIt(value, formatsEnum[instance.props.mode]);
}