(function ($) {
    $.field_recurring = function (element, options) {
        var defaults = {
        }
        var plugin = this;
        plugin.settings = {};
        var $element = $(element);

        plugin.init = function () {
            plugin.settings = $.extend({}, defaults, options);
            $element.find('.until-when').daterangepicker({
                singleDatePicker: true,
                showDropdowns: true,
                minYear: 1901,
                maxYear: parseInt(moment().format('YYYY'),10)
            }, function(start, end, label) {
                $('input[name="<?php name_recurring_until ?>"]').val(start.format('YYYY-MM-DD'));
            });
            $element.find('.repeat-event').select2();
            $element.find('input[type="checkbox"].recurring').click(function (e) {
                if($(this).is(':checked')){
                    $element.removeClass('hide-option');
                    $element.find('.option').removeClass('invisible');
                }else{
                    $element.addClass('hide-option');
                    $element.find('.option').addClass('invisible');
                }
            });

        };

        plugin.example_function = function () {
        };
        plugin.init();
    }

    $.fn.field_recurring = function (options) {

        return this.each(function () {

            if (undefined == $(this).data('field_recurring')) {
                var plugin = new $.field_recurring(this, options);
                $(this).data('field_recurring', plugin);
            }
        });
    }
})(jQuery);