/**
 * Base.Date 1.0
 *
 * Requiere
 *     Base 1.0
 */
$(function() {

    $.extend(Base, {
        Date : {

            formatStrDate: function (date, format) {

                if (typeof date === 'string' || date instanceof String){

                    date = date + " 00:00";
                }

                var newDate = new Date(date);
                var inputDate = '<input value="">';

                var options = {};
                if(null != format || format != undefined){
                    options = {format: format};
                }

                console.log(format);
                console.log(options);

                var dtPick = Base.Date.create(inputDate, options);

                return dtPick.datepicker('setDate', newDate).val();
            },

            create: function (selector, options) {

                var _i18n = {
                    language: {}
                };

                _i18n = $.extend(true, _i18n, Base.i18n.date);

                if(options != undefined && options._i18n !== undefined && options._i18n != null){
                    _i18n = $.extend(true, _i18n, options._i18n);
                }

                var defaultOptions = {
                    autoApply: false,
                    singleDatePicker: true,
                    todayHighlight: true,
                    language: 'es',
                    showDropdowns: true,
                    minYear: 1901,
                    maxYear: 2050,
                    minDate: '01/01/1901',
                    maxDate: '31/12/2049',
                    timePicker: false,
                    locale: {
                        format: 'DD/MM/YYYY',
                        separator:  '-' ,
                        applyLabel: 'Aceptar',
                        cancelLabel: 'Cancelar',
                        fromLabel: 'Desde',
                        toLabel: 'a',
                        customRangeLabel: "Custom",
                        weekLabel: 'Sem',
                        daysOfWeek: Base.daysOfWeek.acronyms,
                        monthNames: Base.month.fullNames,
                        firstDay: 1
                    }
                };

                var finallyOptions = $.extend(true, defaultOptions, options);

                return $(selector).daterangepicker(finallyOptions);
            },

            _qxDate : function (date) {

                return {

                    ver : function () {

                        console.log("Base.Date 1.0");
                        console.log("Requiere: Base 1.0");
                    },

                    getMonth: function (format) {

                        if(format == undefined) {
                            return moment($(date).val(), "L").format('MMMM');
                        }

                        return moment($(date).val(), "DD/MM/YYYY").format(format);
                    },

                    getYear: function (format) {

                        if(format == undefined) {
                            return moment($(date).val(), "DD/MM/YYYY").format('yyyy');
                        }

                        return moment($(date).val(), "dd/mm/yyyy").format(format);
                    }
                }
            }
        }


    });

    $.fn.QxDate = function () {

        var date = this;

        return Base.Date._qxDate(date);
    }
});