(function ($) {
    $.field_pickdatetimedropdown = function (element, options) {
        var defaults = {
            field_name: ""
        }
        var plugin = this;
        plugin.settings = {}
        var $element = $(element),
            element = element;

        plugin.init = function () {
            plugin.settings = $.extend({}, defaults, options);
            $element.find('.calendar').daterangepicker({
                opens: 'left',
                timePicker: true,
                singleDatePicker: true,
                maxYear: parseInt(moment().format('YYYY'), 1),
                locale: {
                    format: 'YYYY/M/DD hh:mm A'
                }
            }, function (start, end, label) {

                let $input_element = $(this.element);
                let field_name = plugin.settings.field_name;
                let $item = $input_element.closest('.item');
                let start_datetime = `${start.format('YYYY-MM-DD hh:mm A')}`;
                $element.find(`input[name="${field_name}"]`).val(start_datetime);

            });
        };
        plugin.getValue = function () {
            let field_name = plugin.settings.field_name;
            return $element.find(`input[name="${field_name}"]`).val();
        };
        plugin.setValue = function (value) {

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

    $.fn.field_pickdatetimedropdown = function (options) {
        return this.each(function () {
            if (undefined == $(this).data('field_pickdatetimedropdown')) {
                var plugin = new $.field_pickdatetimedropdown(this, options);
                $(this).data('field_pickdatetimedropdown', plugin);
            }
        });
    }
})(jQuery);
