<?php
/** @var \Magetop\Advancepreview\Block\Order\CustomOrders $block */
//echo get_class($block);
$url = $block->getUrl('sales/order/history/'); ?>
<input type="hidden" id="txt-history-url" value="<?php echo $url; ?>">
<script>
require([
    'jquery',
    'lib_date_range_picker'
],function ($) {
    $('#txt-custom-increment-id, #txt-custom-project-name').change(function () {
        console.log("Hhihi");
        $('#form-custom-order').submit();
    })
    $('#txt-custom-year, #txt-custom-month').change(function () {
        $('#form-custom-order').submit();
    })
    $('#txt-date-range').daterangepicker(
        {
            singleDatePicker: false,
            showDropdowns: true,
            locale: {
                format: 'MM/DD/YYYY',
                firstDay: 0,
                applyLabel : 'Apply',
                cancelLabel: 'cancel',
            },
        }
    );
    $('#txt-date-range').on('apply.daterangepicker', function(ev, picker) {
        var checkIn = picker.startDate.format('YYYY-MM-DD');
        var checkOut = picker.endDate.format('YYYY-MM-DD');
        $('#txt-from-date').val(checkIn);
        $('#txt-to-date').val(checkOut);
        setTimeout(function () {
            $('#form-custom-order').submit();
        },100)
    });
    $('#txt-date-range').on('cancel.daterangepicker', function(ev, picker) {
        $(this).val('');
        $('#txt-from-date').val('');
        $('#txt-to-date').val('');
    });
    setTimeout(function () {
        var tmpDate = $('#txt-tmp-date-rage').val();
        if($.trim(tmpDate) !== '') {
            $('#txt-date-range').val(tmpDate);
        }
        else {
            $('#txt-date-range').val('');
        }

    },200)
})
</script>
