<style>
    @media (min-width: 650px) {
        html {
            height: 100%;
        }
        body {
            height: 100%;
        }
        .body_wrapper_wrapper {
            height: 100%;
        }
    }
    .root_table__bottom > table > tbody > tr:first-child {display: none;}
    .footer_table_main {border-top: 1px solid rgba(150, 150, 150, 0.5);}
</style>

<div class="max_width">
    <i class="br25 mobile_hide"></i>
<?php
slot('title', __('Корзина'));
include_partial('main/breadcrumbs');
echo '<h1 class="content_title">' . __('Корзина') . '</h1>';
?>
</div>
<form method="post" class="basket_wrap">
    <div class="basket_refresh">
        <?php
        include_component('basket', 'basket');
        ?>
    </div>

    <div class="max_width">
        <?php
        $info = $sf_user->getBasketInfo();
            echo $order_form->renderGlobalErrors();
            echo $order_form->renderHiddenFields();

            ?>

        <div class="formsuccess" <?php echo ($info['offerCount'] > 0 ) ? '' : 'style="display: none"' ?> >
            <div class="basket_buyer">
                <?php
                echo '<h2>' . __('Контактные данные') . ':</h2>';
                echo '<div class="basket_buyer__item"><input size="27" maxlength="255" required="1" placeholder="Как к вам обращаться" onchange="form_validator.check($(this))" onkeyup="form_validator.check($(this))" data-check-rule="noempty" class="basket_buyer__inp_name validate_it" name="basket_order[username]" id="basket_order_username" type="text"></div>';
                echo '<div class="basket_buyer__item"><input size="27" maxlength="24" required="1" placeholder="Номер телефона" onchange="form_validator.check($(this))" onkeyup="form_validator.check($(this))" data-check-rule="phone" class="basket_buyer__inp_name validate_it" name="basket_order[phone]" id="basket_order_phone" type="text"></div>';
                echo '<div class="basket_buyer__item"><input size="27" maxlength="24" required="1" placeholder="Email" onchange="form_validator.check($(this))" onkeyup="form_validator.check($(this))" data-check-rule="email" class="basket_buyer__inp_name validate_it" name="basket_order[email]" id="basket_order_email" type="text"></div>';
                ?>
            </div>
            <div class="basket_get">
                <?php echo '<h2>' . __('Как получить товар') . '</h2>';?>
                <div class="basket_get__pickup">
                    <?php
                    echo '<label class="radio"><input type="radio" class="not_custom" name="basket_order[delivery_type]" value="Самовывоз" required="required" autocomplete="off">';
                    echo '<span class="radio_span"></span>';
                    echo '<span class="radio_text">' . __('Самовывоз') . '</span>';
                    echo $order_form['delivery_type']->renderError();
                    echo '</label>';
                    ?>
                    <div class="basket_get__desc">
                        <?php echo __('Вы можете забрать товар по адресу') . ':<br>' . csSettings::get('pickup_address');?>
                    </div>
                </div>
                <div class="basket_get__delivery">
                    <label class="radio">
                        <input class="not_custom" id="basket_order_delivery_type_delivery" type="radio" name="basket_order[delivery_type]" value="Доставка по адресу" required="required" autocomplete="off">
                        <span class="radio_span"></span>
                        <span class="radio_text"><?php echo __('Доставка');?></span>
                    </label>
                        <div class="basket_get__desc" style="margin-top: 10px">
                    <span class="basket_delivery_info">

                    </span>
                        <?php
                        echo $order_form['delivery_address']->render() . $order_form['delivery_address']->renderError();
                        ?>
                    </div>
                </div>
            </div>
            <div class="basket_advanced">
                <?php
                echo '<h2>' . __('Пожелание к заказу') . '</h2>';
                echo $order_form['comment']->render() . $order_form['comment']->renderError();
                ?>
            </div>
            <div class="basket_order">
                <?php
                echo '<h2>' . __('Общая сумма заказа') . '</h2>';
                echo '<div class="basket_order__price">' . $info['priceText'] . '&nbsp;<span class="rub">i</span></div>';
                echo '<input type="submit" class="btn green_b_btn order_btn btn_disabled" value="' . __('Оформить заказ') . '" onclick="yaCounter48466937.reachGoal(\'ORDER\')" disabled>';
                ?>
            </div>
            <script type="text/javascript">

                $(document).ready(function () {
                    var delivery_info = $('.basket_total').data('delivery-info');
                    console.log(delivery_info);
                    if (delivery_info == '0') {
                        $('.basket_delivery_info').html('Свяжитесь с нами, для уточнения стоимости доставки +7 (635) 644-75-75.<br/>Или уточните у оператора, после оформления заказа');
                    }else {
                        $('.basket_delivery_info').html('Доставка бесплатная');
                    }
                });
                var delivery_type = undefined;

                $('.basket_order input[type="submit"]').on('click', function () {

                    var cl = $('.basket_order input[type="submit"]').attr('class');
                    console.log(cl);
                    console.log(cl.indexOf('btn_disabled'));
                    if (cl.indexOf('btn_disabled') > 0)
                    {
                        return false
                    }

                    delivery_adr = $('#basket_order_delivery_address').val();

                    if(typeof delivery_type == 'undefined') {
                        invalid($('.basket_get'));
                        return false;
                    }

                    if(delivery_type == 2 && delivery_adr.length < 3) {
                        invalid($('#basket_order_delivery_address'));
                        return false;
                    }
                    return true;
                });

                $('.basket_get input[type="radio"]').change(function (e) {
                    var deliveryAddress = $('#basket_order_delivery_address');
                    if(e.target.value == 'Самовывоз'){
                        delivery_type = 1;
                        deliveryAddress.removeAttr('required');
                    }else{
                        delivery_type = 2;
                        deliveryAddress.attr('required', 'required');
                    }
                });

                $('#basket_order_delivery_address').focus(function () {
                    $('#basket_order_delivery_type_delivery').click();
                });
                function invalid(el) {
                    $('html, body').animate({
                        scrollTop: el.offset().top - 160
                    }, 300);

                    setTimeout(function() {
                        el.addClass('jump');
                    }, 300);

                    setTimeout(function() {
                        el.removeClass('jump')
                    }, 800);
                }
                var count = <?php echo $info['offerCount'] ?>;
                $(document).ready(function () {
                    form_validator.check($('#basket_order_username'));
                    form_validator.check($('#basket_order_email'));
                    form_validator.check($('#basket_order_phone'));

                })
            </script>
        </div>
        <i class="br40"></i>
    </div>
</form>