<?php
$store_user = dokan()->vendor->get(get_query_var('author'));
$store_info = $store_user->get_shop_info();
$social_info = $store_user->get_social_profiles();
$store_tabs = dokan_get_store_tabs($store_user->get_id());
$social_fields = dokan_get_social_profile_fields();

$dokan_appearance = get_option('dokan_appearance');
$profile_layout = empty($dokan_appearance['store_header_template']) ? 'default' : $dokan_appearance['store_header_template'];
$store_address = dokan_get_seller_short_address($store_user->get_id(), false);

$dokan_store_time_enabled = isset($store_info['dokan_store_time_enabled']) ? $store_info['dokan_store_time_enabled'] : '';
$store_open_notice = isset($store_info['dokan_store_open_notice']) && !empty($store_info['dokan_store_open_notice']) ? $store_info['dokan_store_open_notice'] : __('Store Open', 'dokan-lite');
$store_closed_notice = isset($store_info['dokan_store_close_notice']) && !empty($store_info['dokan_store_close_notice']) ? $store_info['dokan_store_close_notice'] : __('Store Closed', 'dokan-lite');
$show_store_open_close = dokan_get_option('store_open_close', 'dokan_appearance', 'on');

$general_settings = get_option('dokan_general', []);
$banner_width = dokan_get_option('store_banner_width', 'dokan_appearance', 625);

if (('default' === $profile_layout) || ('layout2' === $profile_layout)) {
    $profile_img_class = 'profile-img-circle';
} else {
    $profile_img_class = 'profile-img-square';
}

if ('layout3' === $profile_layout) {
    unset($store_info['banner']);
    $no_banner_class = ' profile-frame-no-banner';
    $no_banner_class_tabs = ' dokan-store-tabs-no-banner';

} else {
    $no_banner_class = '';
    $no_banner_class_tabs = '';
}


global $post;

$_overwrite_shipping = get_post_meta($post->ID, '_overwrite_shipping', true);
$dps_processing = get_user_meta($post->post_author, '_dps_pt', true);
$from = get_user_meta($post->post_author, '_dps_form_location', true);
$dps_country_rates = get_user_meta($post->post_author, '_dps_country_rates', true);
$shipping_policy = get_user_meta($post->post_author, '_dps_ship_policy', true);
$refund_policy = get_user_meta($post->post_author, '_dps_refund_policy', true);
$product_processing_time = get_post_meta($post->ID, '_dps_processing_time', true);
$processing_time = $dps_processing;
if ($_overwrite_shipping == 'yes') {
    $processing_time = ($product_processing_time) ? $product_processing_time : $dps_processing;
}
$country_obj = new WC_Countries();
$countries = $country_obj->countries;
?>
<?php if ($processing_time || $shipping_policy || $refund_policy): ?>
    <div class="store-shipping-tabs">
        <div class="nav-tabs clearfix">
            <?php if ($processing_time || $shipping_policy): ?>
                <button data-pane="pane-shipping-policy">
                    <span class="icon" data-icon="Icon-Badges-Delivery-FastDelivery"></span>
                    <span><?php _e('Shipping Policy', 'dokan'); ?></span>
                </button>
            <?php endif; ?>
            <?php if ($refund_policy): ?>
                <button data-pane="pane-refund-policy">
                    <span class="icon" data-icon="Icon-Badges-Return"></span>
                    <span><?php _e('Refund Policy', 'dokan'); ?></span>
                </button>
            <?php endif; ?>
        </div>
        <div class="tab-content">
            <?php if ($processing_time || $shipping_policy): ?>
                <div class="tab-pane" id="pane-shipping-policy">
                    <?php if ($processing_time): ?>
                        <p>
                            <strong>
                                <?php _e('Ready to ship in', 'dokan'); ?><?php echo dokan_get_processing_time_value($processing_time); ?>
                                <?php echo $from ? __('from', 'dokan') . ' ' . $countries[$from] : ''; ?>
                            </strong>
                        </p>
                    <?php endif; ?>
                    <?php if ($shipping_policy): ?>
                        <?php echo wpautop($shipping_policy); ?>
                    <?php endif; ?>
                </div>
            <?php endif; ?>
            <?php if ($refund_policy): ?>
                <div class="tab-pane" id="pane-refund-policy">
                    <?php echo wpautop($refund_policy); ?>
                </div>
            <?php endif; ?>
        </div>
    </div>
<?php endif; ?>
<div class="store-holder">
    <div class="profile-frame<?php echo esc_attr($no_banner_class); ?>">
        <div class="profile-info-box profile-layout-<?php echo esc_attr($profile_layout); ?>">
            <?php if ($store_user->get_banner()) { ?>
                <img src="<?php echo esc_url($store_user->get_banner()); ?>" alt="<?php echo esc_attr($store_user->get_shop_name()); ?>" title="<?php echo esc_attr($store_user->get_shop_name()); ?>" class="profile-info-img">
            <?php } else { ?>
                <div class="profile-info-img dummy-image">&nbsp;</div>
            <?php } ?>
        </div> <!-- .profile-info-box -->
    </div>
    <?php if ($store_tabs) { ?>
        <div class="dokan-store-tabs<?php echo esc_attr($no_banner_class_tabs); ?>">
            <ul class="dokan-list-inline">
                <?php foreach ($store_tabs as $key => $tab) { ?>
                    <?php if ($tab['url']): ?>
                        <li>
                            <a href="<?php echo esc_url($tab['url']); ?>"><?php echo esc_html($tab['title']); ?></a>
                        </li>
                    <?php endif; ?>
                <?php } ?>
                <?php do_action('dokan_after_store_tabs', $store_user->get_id()); ?>
            </ul>
        </div>
    <?php } ?>
</div>