var Wick = Wick || {};
Wick.DeliveryDetails = (function () {
    var $page = $('.page_checkout-delivery-details');

    function bindEvents() {
        var dateAlert;

        $page
            .find(
                '.btn-payment-details, .delivery-details__payment-details, .delivery-details__payment-details_mobile'
            )
            .on('click', function () {
                if (navigator.userAgent.match(/TradeProMobile_Android|DIYMobile_Android/i)) {
                    document.body.scrollTop = 0;
                    document.documentElement.scrollTop = 0;
                }

                if (!Wick.DateSelection.isDateSelected()) {
                    dateAlert = Wick.Notification.show({
                        text: 'Sorry, please select a delivery date and/or time',
                        container: '.checkout-heading',
                        type: 'error',
                    });
                    return false;
                }
            });

        $('.date-selection').on('selected', function () {
            dateAlert && dateAlert.hide();
        });
    }

    if (!$page.length) {
        return;
    }

    bindEvents();
})();
