/**
 * PickADate Fields, aka the new date picker
 */
import IGDATAPOOLFE from '@dp/ig_datapool_fe.js';

const dateFieldPlugin = {
    initFields(form) {
        this.init(form);
    },
    init(form) {
	let $form = $(form);
	this.form = $form;
	$('.dp-pickadate', $form).each(function() {
	    var options = $(this).data('dateoptions');

	    $(this).pickadate(options);
	    if($(this).data('submit')) {
		$(this ).on('change', function() {
		    $(this).parents('form').submit();
		});
	    }
	});
    }
};

IGDATAPOOLFE.addPlugin('dateField', dateFieldPlugin);
export default dateFieldPlugin;

