$(document).ready(function () {
    "use strict";

    if ($('.datepicker').length) {
        $('.datepicker').each(function () {
            var $picker = $(this);
            var options = {
                format: 'yyyy-mm-dd',
                autoclose: true,
                todayHighlight: true
            };

            // Block past dates for non-admin roles on ticket search journey date
            if ($picker.attr('id') === 'filterjourneydate' && $picker.attr('data-can-backdate') !== '1') {
                options.startDate = new Date();
            }

            // Journey list backdated permission uses data-date-start-date on its own field
            if ($picker.attr('id') === 'filterjourneylistdate' && $picker.is('[data-date-start-date]')) {
                options.startDate = new Date();
            }

            $picker.datepicker(options);
        });
    }

    if ($('#start_date').length && $('#end_date').length) {
        bdtaskIlmCommonJs.dateRange.init('#start_date', '#end_date');
    }

    if ($('#filterjourneydate').length && $('#filterreturndate').length) {
        bdtaskIlmCommonJs.dateRange.init('#filterjourneydate', '#filterreturndate');
    }
});
