<?php echo $header; ?>
<?= htmlspecialchars_decode($poc_custom_code); ?>
<?= $poc_styles; ?>

<?php if(!$poc_is_logged) { ?>
    <?php include(DIR_TEMPLATE.'default/template/checkout/perfect_one_checkout/modal_login.tpl'); ?>
<?php } ?>
<?php include(DIR_TEMPLATE.'default/template/checkout/perfect_one_checkout/modal_billing_address.tpl'); ?>
<?php if ($poc_modals_in_forms) { ?>
    <?php if(!$poc_is_logged) { ?>
        <?php include(DIR_TEMPLATE.'default/template/checkout/perfect_one_checkout/modal_register.tpl'); ?>
        <?php include(DIR_TEMPLATE.'default/template/checkout/perfect_one_checkout/modal_delivery_address.tpl'); ?>
    <?php } ?>
<?php } ?>

<?php if($poc_popup_form_validations) { ?>
    <?php include(DIR_TEMPLATE.'default/template/checkout/perfect_one_checkout/modal_form_validations.tpl'); ?>
<?php } ?>

<?= $layout_vars ?>
    <script type="text/javascript">
        var none_state = '<?= $addresses_none_state;?>';
        var url_coupon = '<?= $url_coupon; ?>';
        var url_voucher = '<?= $url_voucher; ?>';
        var url_reward = '<?= $url_reward; ?>';
        var is_logged = <?= $poc_is_logged ? 1 : 0 ?>;
        var more_oc_2 = <?= $more_oc_2 ? 1 : 0 ?>;
        var button_confirm_order_text = "<?= $confirm_button ?>";
        var error_in_cart = false;
        var poc_hide_uncompleted_panels = <?= $poc_hide_uncompleted_panels ? 1 : 0 ?>;
        var poc_modals_in_forms = <?= $poc_modals_in_forms ? 1 : 0 ?>;
        var poc_sign_in_google_client_id = '<?= isset($poc_sign_in_google_client_id) ? $poc_sign_in_google_client_id : ''?>';
        var poc_sign_in_success_title = '<?= $sign_in_success_title ?>';
        var poc_confirm_buttons_targets = '<?= $poc_confirm_buttons_targets ?>';
        var poc_popup_form_validations = <?= $poc_popup_form_validations ? 1 : 0 ?>;

        var confirm_error_billing = "<?= $confirm_error_billing ?>";
        var confirm_error_shipping = "<?= $confirm_error_shipping ?>";
        var confirm_error_shipping_method = "<?= $confirm_error_shipping_method ?>";
        var confirm_error_payment_method = "<?= $confirm_error_payment_method ?>";
        var confirm_error_panel_confirm = "<?= $confirm_error_panel_confirm ?>";
        var confirm_error_register = "<?= $confirm_error_register ?>";

        var text_cart_coupon_success = "<?= $cart_coupon_success ?>";
        var text_cart_gift_success = "<?= $cart_gift_success ?>";
        var text_cart_reward_success = "<?= $cart_reward_success ?>";

        $(document).on('ready', function(){
            $('.date').datetimepicker({
                pickTime: false
            });

            $('.datetime').datetimepicker({
                pickDate: true,
                pickTime: true
            });

            $('.time').datetimepicker({
                pickDate: false
            });

            <?= !empty($poc_phone_mask) ? "$('input[name=telephone]').mask('".$poc_phone_mask."');" : '' ?>
            <?= !empty($poc_post_code_mask) ? "$('input[name=postcode]').mask('".$poc_post_code_mask."');" : '' ?>
        });
    </script>
    <div class="poc_container remodal-bg poc_styles">
        <?php
        if(!empty($privacy_policy))
            include(DIR_TEMPLATE.'default/template/checkout/perfect_one_checkout/modal_privacy_policy.tpl');
        if(!empty($terms))
            include(DIR_TEMPLATE.'default/template/checkout/perfect_one_checkout/modal_terms.tpl');
        ?>


        <?php if ($more_oc_2) { ?>
            <ul class="breadcrumb">
                <?php foreach ($breadcrumbs as $breadcrumb) { ?>
                    <li><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a></li>
                <?php } ?>
            </ul>
        <?php } ?>

        <?php if (!$more_oc_2) { ?>
            <div class="breadcrumb">
                <?php foreach ($breadcrumbs as $breadcrumb) { ?>
                    <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
                <?php } ?>
            </div>
        <?php } ?>

        <?php if (!empty($error_warning)) { ?>
            <div class="poc_alert poc_alert-danger"><?= $poc_icon_error ?> <?php echo $error_warning; ?>
                <button type="button" class="poc_close" data-dismiss="alert">&times;</button>
            </div>
        <?php } ?>

        <div class="poc_row"><?php echo $column_left; ?>
            <?php $some_in_column_left = strlen(rtrim($column_left)) > 0;
            $some_in_column_right = strlen(rtrim($column_right)) > 0;
            ?>
            <?php if ($some_in_column_left && $some_in_column_right) { ?>
                <?php $class = 'poc_col-sm-6'; ?>
            <?php } elseif ($some_in_column_left || $some_in_column_right) { ?>
                <?php $class = 'poc_col-sm-9'; ?>
            <?php } else { ?>
                <?php $class = 'poc_col-sm-12'; ?>
            <?php } ?>
            <div id="content" class="<?php echo $class; ?>"><?php echo $content_top; ?>
                <h1><?php echo $heading_title; ?></h1>

                <?php include(DIR_TEMPLATE.'default/template/checkout/perfect_one_checkout/steps.tpl'); ?>

                <div style="clear:both;"></div>
                <div class="perfect_one_checkout_main_container">
                    <div class="flex_column poc_col_main col_1"></div>
                    <div class="flex_column poc_col_main col_2"></div>
                    <div class="flex_column poc_col_main col_3"></div>
                </div>

                <div class="panels" style="display:none;">
                    <?php if (!$poc_is_logged) { ?>
                        <div class="panel_container panel_identification">
                            <div class="panel_poc">
                                <?php $icon = !empty($identification_icon) ? str_replace('classIcon', $identification_icon, $poc_icon_html) : ''; ?>
                                <div class="panel_poc-heading"><?= $icon ?><?= $identification_title; ?></div>
                                <div class="panel_poc-body flex text-center">
                                    <?php if($poc_guest_buy) { ?>
                                        <input type="hidden" name="guest" <?= !empty($guest) ? ' value="1"' : ''; ?>>
                                    <?php } ?>
                                    <?php if (!$poc_modals_in_forms) { ?>
                                        <input type="hidden" name="registered" value="<?= !empty($poc_is_logged) ? ' 1' : '0'; ?>">
                                    <?php } ?>
                                    <div class="poc_btn-group">
                                        <button type="button" class="poc_btn poc_btn-default button_login" data-remodal-target="modal_login"><?= $identification_button_login; ?></button>
                                        <input type="hidden" name="register" <?= !empty($register) ? ' value="1"' : ''; ?>>
                                        <button type="button" class="poc_btn poc_btn-default button_register" <?= !empty($register) && !$poc_modals_in_forms ? ' disabled="disabled"' : ''; ?> <?= $poc_modals_in_forms ? 'data-remodal-target="modal_register"' : 'onclick="register_mode()"' ?>><?= $identification_button_register; ?></button>
                                        <?php if($poc_guest_buy) { ?>
                                            <input type="hidden" name="guest" <?= !empty($guest) ? ' value="1"' : ''; ?>>
                                            <button type="button" class="poc_btn poc_btn-default button_guest"<?= !empty($guest) ? ' disabled="disabled"' : ''; ?> onclick="guest();"><?= $identification_button_guest; ?></button>
                                        <?php } ?>
                                    </div>
                                    <?php if (!empty($some_sign_in)) { ?>
                                        <div class="poc_sign_in_container">
                                            <?= !empty($sign_in_main_title) ? '<span class="poc_sign_in_main_title">'.$sign_in_main_title.'</span>' : ''; ?>
                                            <?php if(!empty($poc_sign_in_facebook) && !empty($poc_sign_in_facebook_link)) {  ?>
                                                <div onclick="window.location='<?= $poc_sign_in_facebook_link ?>'" class="poc_sign_in poc_facebook<?= empty($sign_in_facebook_text) ? ' poc_sign_in_no_text' : ''  ?>" id="poc_sign_in_facebook">
                                                    <?= $sign_in_facebook_icon?><?= !empty($sign_in_facebook_text) ? $sign_in_facebook_text : '&nbsp;'  ?>
                                                </div>
                                            <?php } ?>
                                            <?php if(!empty($poc_sign_in_paypal) && !empty($poc_sign_in_paypal_js_code)) {  ?>
                                                <div onclick="$('div.poc_sign_in_container').find('button.LIwPP').click(); return false;" class="poc_sign_in poc_paypal<?= empty($sign_in_paypal_text) ? ' poc_sign_in_no_text' : ''  ?>">
                                                    <?= $sign_in_paypal_icon?><?= !empty($sign_in_paypal_text) ? $sign_in_paypal_text : '&nbsp;'  ?>
                                                </div>
                                                <?= $poc_sign_in_paypal_js_code ?>
                                                <span id='poc_sign_in_paypal'></span>
                                            <?php } ?>
                                            <?php if(!empty($poc_sign_in_linkedin) && !empty($poc_sign_in_linkedin_link)) {  ?>
                                                <div onclick="window.location='<?= $poc_sign_in_linkedin_link ?>'" class="poc_sign_in poc_linkedin<?= empty($sign_in_linkedin_text) ? ' poc_sign_in_no_text' : ''  ?>" id="poc_sign_in_linkedin">
                                                    <?= $sign_in_linkedin_icon?><?= !empty($sign_in_linkedin_text) ? $sign_in_linkedin_text : '&nbsp;'  ?>
                                                </div>
                                            <?php } ?>
                                            <?php if(!empty($poc_sign_in_google)) {  ?>
                                                <div class="poc_sign_in poc_google<?= empty($sign_in_google_text) ? ' poc_sign_in_no_text' : ''  ?>" id="poc_sign_in_google">
                                                    <?= $sign_in_google_icon?><?= !empty($sign_in_google_text) ? $sign_in_google_text : '&nbsp;'  ?>
                                                    <script>startGoogleSign();</script>
                                                </div>
                                            <?php } ?>
                                        </div>
                                    <?php } ?>
                                </div>
                            </div>
                        </div>
                    <?php } ?>
                    <div class="panel_container panel_addresses">
                        <div class="panel_poc">
                            <?php $icon = !empty($addresses_icon) ? str_replace('classIcon', $addresses_icon, $poc_icon_html) : ''; ?>
                            <div class="panel_poc-heading"><?= $icon ?><?= $addresses_title; ?> <?= $poc_is_logged ? '<a href="javascript:{}" class="new_address" data-remodal-target="modal_new_address" title="'.$addresses_button_add_new_address_text.'">'.$poc_icon_add_address.$addresses_button_add_new_address_text.'</a>':'';?></div>
                            <div class="panel_poc-body flex">
                                <?php if(!$poc_is_logged) { ?>
                                    <?php if (!$poc_modals_in_forms) { ?>
                                        <div class="poc_form form_register" <?= !empty($register) ? 'style="display:block;"' : '' ?>>
                                            <h3 class="poc_title"><span><?= $identification_button_register; ?></span></h3>
                                            <?= $form_register ?>
                                            <input type="hidden" name="address_type" value="payment_address">
                                        </div>

                                        <?php if($show_guest_forms) { ?>
                                            <div class="poc_form form_billing_address" <?= !empty($guest) ? 'style="display:block;"' : 'style="display:none;"' ?>>
                                                <h3 class="poc_title sames_addresses" style="display: <?= $poc_same_address ? 'block' : 'none' ?>;"><span><?= $addresses_button_delivery_billing_address; ?></span></h3>
                                                <h3 class="poc_title differents_addresses" style="display: <?= !$poc_same_address ? 'block' : 'none' ?>;"><span><?= $addresses_button_billing_address ?></span></h3>
                                                <?= $form_billing_address ?>
                                                <input type="hidden" name="address_type" value="payment_address">
                                            </div>
                                        <?php } ?>
                                        <div class="poc_col-md-12">
                                            <div class="poc_form-group">
                                                <div class="checkbox">
                                                    <label>
                                                        <input name="shipping_address" onchange="same_address($(this))" type="checkbox"<?= !empty($poc_same_address) ? ' checked="checked"' : ''; ?>> <?= $addresses_same_address; ?>
                                                    </label>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="poc_form form_delivery_address" <?= empty($poc_same_address) ? ' style="display:block;"' : 'style="display:none;"'; ?>>
                                            <h3 class="poc_title"><span><?= $addresses_button_delivery_address ?></span></h3>
                                            <?= $form_delivery_address ?>
                                            <input type="hidden" name="address_type" value="shipping_address">
                                        </div>
                                    <?php } else { ?>
                                        <div class="flex poc_col-12 show_on_guest"<?= empty($guest) ? ' style="display: none;"' : ''; ?>>
                                            <div class="poc_col-12">
                                                <div class="checkbox">
                                                    <label>
                                                        <input name="shipping_address" onchange="same_address($(this))" type="checkbox"<?= !empty($poc_same_address) ? ' checked="checked"' : ''; ?>> <?= $addresses_same_address; ?>
                                                    </label>
                                                </div>
                                            </div>
                                            <div class="poc_col-12 flex addresses_buttons text-center">
                                                <div class="poc_col-6" <?= !empty($poc_same_address) ? 'style="display:none;"' : ''; ?>>
                                                    <?php $icon = !empty($addresses_button_billing_address_icon) ? str_replace('classIcon', $addresses_button_billing_address_icon, $poc_icon_html) : ''; ?>
                                                    <button type="button" class="poc_btn poc_btn-default with_icon billing_address" data-remodal-target="modal_billing_address"><?= !empty($icon) ? $icon:''; ?><?= $addresses_button_billing_address; ?></button>
                                                </div>
                                                <div class="poc_col-6" <?= !empty($poc_same_address) ? 'style="display:none;"' : ''; ?>>
                                                    <?php $icon = !empty($addresses_button_delivery_address_icon) ? str_replace('classIcon', $addresses_button_delivery_address_icon, $poc_icon_html) : ''; ?>
                                                    <button type="button" class="poc_btn poc_btn-default with_icon delivery_address" data-remodal-target="modal_delivery_address"><?= !empty($icon) ? $icon:''; ?><?= $addresses_button_delivery_address; ?></button>
                                                </div>

                                                <div class="poc_col-12 same_address_container" <?= empty($poc_same_address) ? 'style="display:none;"' : ''; ?>>
                                                    <button type="button" class="poc_btn poc_btn-default billing_delivery_address with_icon" data-remodal-target="modal_billing_address">
                                                        <?php $icon = !empty($addresses_button_delivery_billing_address_icon) ? str_replace('classIcon', $addresses_button_delivery_billing_address_icon, $poc_icon_html) : ''; ?>
                                                        <?= $icon; ?>
                                                        <?= $addresses_button_delivery_billing_address; ?>
                                                    </button>
                                                </div>
                                            </div>
                                        </div>
                                    <?php } ?>
                                <?php } else { ?>
                                    <div class="delivery_address poc_col-6">
                                        <label><?= $addresses_delivery_address_selector_title; ?></label>
                                        <div style="clear:both;"></div>
                                        <select name="shipping_address" class="poc_form-control" onchange="set_address($(this));">
                                            <?php foreach ($addresses as $address_id => $address_name) { ?>
                                                <option <?= !empty($default_delivery_address_id) && $default_delivery_address_id == $address_id ? 'selected="selected" ':'';?> value="<?= $address_id; ?>"><?= $address_name; ?></option>
                                            <?php } ?>
                                        </select>
                                    </div>

                                    <div class="billing_address poc_col-6">
                                        <label><?= $addresses_billing_address_selector_title; ?></label>
                                        <div style="clear:both;"></div>
                                        <select name="payment_address" class="poc_form-control" onchange="set_address($(this));">
                                            <?php foreach ($addresses as $address_id => $address_name) { ?>
                                                <option <?= !empty($default_billing_address_id) && $default_billing_address_id == $address_id ? 'selected="selected"':'';?> value="<?= $address_id; ?>"><?= $address_name; ?></option>
                                            <?php } ?>
                                        </select>
                                    </div>
                                <?php } ?>
                            </div>
                        </div>
                    </div>

                    <div class="panel_container panel_shipping">
                        <div class="panel_poc">
                            <?php $icon = !empty($shipping_icon) ? str_replace('classIcon', $shipping_icon, $poc_icon_html) : ''; ?>
                            <div class="panel_poc-heading"><?= !empty($icon) ? $icon:''; ?><?= $shipping_title; ?></div>
                            <div class="panel_poc-body flex">
                                <?= $shipping_methods; ?>
                            </div>
                        </div>
                    </div>

                    <div class="panel_container panel_payment">
                        <div class="panel_poc">
                            <?php $icon = !empty($payment_icon) ? str_replace('classIcon', $payment_icon, $poc_icon_html) : ''; ?>
                            <div class="panel_poc-heading"><?= !empty($icon) ? $icon:''; ?><?= $payment_title; ?></div>
                            <div class="panel_poc-body flex">
                                <?= $payment_methods; ?>
                            </div>
                        </div>
                    </div>

                    <div class="panel_container panel_cart">
                        <div class="panel_poc">
                            <?php $icon = !empty($cart_icon) ? str_replace('classIcon', $cart_icon, $poc_icon_html) : ''; ?>
                            <div class="panel_poc-heading"><?= !empty($icon) ? $icon:''; ?><span class="cart_heading"><?= $cart_title; ?><?= !empty($poc_cart_weight) ? ' ('.$poc_cart_weight.')' : ''; ?></span></div>
                            <div class="panel_poc-body flex">
                                <?= $cart_info; ?>
                            </div>
                        </div>
                    </div>

                    <div class="panel_container panel_confirm">
                        <div class="panel_poc">
                            <?php $icon = !empty($confirm_icon) ? str_replace('classIcon', $confirm_icon, $poc_icon_html) : ''; ?>
                            <div class="panel_poc-heading"><?= !empty($icon) ? $icon:''; ?><?= $confirm_title; ?></div>
                            <div class="panel_poc-body flex">

                                <div class="poc_col-12 poc_form-group order_comment <?= $poc_order_comment_required ? 'poc_required' : '' ?>">
                                    <label class="poc_control-label"><?= $confirm_comments ?></label>
                                    <textarea name="comment" class="poc_form-control" <?= $poc_order_comment_required ? 'data-validationrule="not_empty"' : '' ?>><?= $comment ?></textarea>
                                    <span class="error_message"><?= $confirm_comments_error; ?></span>
                                </div>


                                <?php if(!empty($terms)) { ?>
                                    <div class="poc_col-12 poc_form-group poc_required checkbox confirm_terms">
                                        <label class="poc_control-label"><input data-validationrule="not_empty" name="confirm_terms" type="checkbox" onclick="ajax_set_terms_accepted($(this).is(':checked'))" <?= $poc_terms_accepted ? 'checked' : ''; ?>> <?= $confirm_checkbox_terms; ?></label><div style="clear:both;"></div><span class="error_message"><?= $confirm_checkbox_terms_error; ?></span>
                                    </div>
                                <?php } ?>

                                <div class="poc_col-12 poc_alert poc_alert-danger confirm_error"><button type="button" class="poc_close" onClick="$(this).closest('div.poc_alert').hide();" aria-label="Close"><span aria-hidden="true">&times;</span></button><?= $poc_icon_warning; ?><span class="message"><?= $confirm_error; ?></span> <a href="javascript:{}" onclick="validate_steps()"><?= $confirm_error_show_errors ?></a></div>
                                <div style="clear:both;"></div>
                                <div class="payment_info"><?= $payment_info; ?></div>
                                <div style="clear:both;"></div>
                                <?php if(!$poc_is_logged) { ?>
                                    <a href="javascript:{}" class="poc_btn poc_btn-default confirm_register_button" onclick="register();"><?= $confirm_register_button ?></a>
                                <?php } ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="poc_content_bottom">
                <?php echo $content_bottom; ?>
            </div>
        </div>
    </div>
    <?php if(!empty($poc_google_api_address_autocomplete)) { ?>
        <script src="https://maps.googleapis.com/maps/api/js?key=<?= $poc_google_api_address_autocomplete ?>&libraries=places&callback=initAutocomplete" async defer></script>
    <?php } ?>
<?php echo $footer; ?>