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

        plugin.init = function () {

            plugin.settings = $.extend({}, defaults, options);
            $element.find('.close-date').daterangepicker({
                singleDatePicker: true,
                showDropdowns: true,
                timePicker: true,
                minYear: 1901,
                locale: {
                    format: 'M/DD/YYYY hh:mm A'
                },
                maxYear: '+10'
            }, function(start, end, label) {
                var years = moment().diff(start, 'years');
                $('input[name="<?php name_close_date ?>"]').val(start.format('YYYY-MM-DD HH:mm'));

            });
            $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_closedate = function (options) {

        return this.each(function () {

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