<?php
/**
 * Template for Single Product on Sie
 */
$course_counters = true;
$course_students = true;
if (class_exists('Redux')) {
    $course_post_share = codebean_option('course_share_story');
    $course_share_text = codebean_option('course_share_text');
    $course_students = codebean_option('course_students');
    $course_counters = codebean_option('course_counters');
    $course_student_text = codebean_option('course_student_text');
    $course_downloads = codebean_option('course_downloads');
} else {
    $course_post_share = false;
    $course_share_text = '';
    $course_student_text = 'شما دانشجوی دوره هستید';
}

$student_display = true;
$prefix = '_studiare_';

// Product Meta
$course_stock = get_post_meta(get_the_id(), '_stock', true);
$duration = get_post_meta(get_the_ID(), $prefix . 'course_duration', true);
$lessons = get_post_meta(get_the_ID(), $prefix . 'course_lesseons', true);
$skill_level = get_post_meta(get_the_ID(), $prefix . 'course_level', true);
$certificate = get_post_meta(get_the_ID(), $prefix . 'course_certificate', true);
$course_language = get_post_meta(get_the_ID(), $prefix . 'course_language', true);
$course_type = get_post_meta(get_the_ID(), $prefix . 'course_type', true);
$course_prerequisite = get_post_meta(get_the_ID(), $prefix . 'course_prerequisite', true);
$course_start_date = get_post_meta(get_the_ID(), $prefix . 'course_start_date', true);
$course_update_date = get_post_meta(get_the_ID(), $prefix . 'course_update_date', true);
$course_file_size = get_post_meta(get_the_ID(), $prefix . 'course_file_size', true);
$course_support = get_post_meta(get_the_ID(), $prefix . 'course_support', true);
$course_receive_type = get_post_meta(get_the_ID(), $prefix . 'course_receive_type', true);
$extra_content = get_post_meta(get_the_ID(), $prefix . 'extra_content', true);
$course_percent = get_post_meta(get_the_ID(), $prefix . 'course_percent', true);

global $product;
$downloads = array();
if (is_user_logged_in()) {
    $user_id = get_current_user_id();
    $downloads = wc_get_customer_available_downloads($user_id);
}
?>

<div class="product-info-box std-add-t-cart">

    <?php
    $current_user = wp_get_current_user();
    if (wc_customer_bought_product($current_user->user_email, $current_user->ID, $product->get_id()) ) {
        echo '<div class="purchased-info-box">';
        echo '<i class="fas fa-graduation-cap"></i>';
        echo($course_student_text);
        echo '</div>';
    } else {
        echo'<div class="sell_course">
	        <strong>قیمت :</strong>
	        <p class="price">'; echo wp_kses_post( $product->get_price_html() ); echo'</p>
        </div>';
        woocommerce_template_single_add_to_cart();

    }

    ?>
   
</div>



<div class="product-info-box">
    <?php if (!empty($course_stock) || !empty($course_language) || !empty($duration) || !empty($lessons) || !empty($skill_level) || !empty($certificate) || !empty($course_start_date) || !empty($course_prerequisite) || !empty($course_receive_type) || !empty($course_update_date) || !empty($feture_entries)) : ?>
        <div class="product-meta-info-list">


            <?php if ($course_students) : ?>
                <div class="total_sales">
                    <i class="iconly-User3"></i> تعداد دانشجو :
                    <span><?php $count = get_post_meta($post->ID, 'total_sales', true);
                        $text = sprintf(_n('%s', '%s', $count, 'wpdocs_textdomain'), number_format_i18n($count));
                        echo $text; ?></span>
                </div>
            <?php endif; ?>

            <?php if (!empty($course_type)) : ?>
                <div class="meta-info-unit">
                    <div class="icon"><i class="iconly-Location"></i></div>
                    <div class="value"><?php echo esc_attr(__('نوع دوره:', 'studiare') . ' ' . $course_type); ?></div>
                </div>
            <?php endif; ?>

            <?php if (!empty($skill_level)) : ?>
                <div class="meta-info-unit">
                    <div class="icon"><i class="iconly-Arrow-Left-2"></i></div>
                    <div class="value"><?php echo esc_attr(__('سطح دوره:', 'studiare') . ' ' . $skill_level); ?></div>
                </div>
            <?php endif; ?>

            <?php if (!empty($course_prerequisite)) : ?>
                <div class="meta-info-unit">
                    <div class="icon"><i class="iconly-Arrow-Left-2"></i></div>
                    <div class="value"><?php echo esc_attr(__('پیش نیاز:', 'studiare') . ' ' . $course_prerequisite); ?></div>
                </div>
            <?php endif; ?>

            <?php if (!empty($course_start_date)) : ?>
                <div class="meta-info-unit">
                    <div class="icon"><i class="iconly-Arrow-Left-2"></i></div>
                    <div class="value"><?php echo esc_attr(__('تاریخ شروع:', 'studiare') . ' ' . $course_start_date); ?></div>
                </div>
            <?php endif; ?>

            <?php if (!empty($course_update_date)) : ?>
                <div class="meta-info-unit">
                    <div class="icon"><i class="iconly-Arrow-Left-2"></i></div>
                    <div class="value"><?php echo esc_attr(__('تاریخ بروزرسانی:', 'studiare') . ' ' . $course_update_date); ?></div>
                </div>
            <?php endif; ?>

            <?php if (!empty($course_language)) : ?>
                <div class="meta-info-unit">
                    <div class="icon"><i class="iconly-Arrow-Left-2"></i></div>
                    <div class="value"><?php echo esc_attr(__('زبان دوره:', 'studiare') . ' ' . $course_language); ?></div>
                </div>
            <?php endif; ?>

            <?php if (!empty($duration)) : ?>
                <div class="meta-info-unit">
                    <div class="icon"><i class="iconly-Arrow-Left-2"></i></div>
                    <div class="value"><?php echo esc_html($duration); ?></div>
                </div>
            <?php endif; ?>

            <?php if (!empty($lessons)) : ?>
                <div class="meta-info-unit">
                    <div class="icon"><i class="iconly-Arrow-Left-2"></i></div>
                    <div class="value"><?php echo esc_html($lessons); ?></div>
                </div>
            <?php endif; ?>

            <?php if (!empty($course_file_size)) : ?>
                <div class="meta-info-unit">
                    <div class="icon"><i class="iconly-Arrow-Left-2"></i></div>
                    <div class="value"><?php echo esc_attr(__('', 'studiare') . ' ' . $course_file_size); ?></div>
                </div>
            <?php endif; ?>


            <?php if (!empty($course_receive_type)) : ?>
                <div class="meta-info-unit">
                    <div class="icon"><i class="iconly-Arrow-Left-2"></i></div>
                    <div class="value"><?php echo esc_attr(__('روش دریافت:', 'studiare') . ' ' . $course_receive_type); ?></div>
                </div>
            <?php endif; ?>


            <?php if (!empty($course_support)) : ?>
                <div class="meta-info-unit">
                    <div class="icon"><i class="iconly-Arrow-Left-2"></i></div>
                    <div class="value"><?php echo esc_attr(__('روش پشتیبانی:', 'studiare') . ' ' . $course_support); ?></div>
                </div>
            <?php endif; ?>

            <?php if (!empty($certificate)) : ?>
                <div class="meta-info-unit">
                    <div class="icon"><i class="iconly-Arrow-Left-2"></i></div>
                    <div class="value"><?php echo esc_html($certificate); ?></div>
                </div>
            <?php endif; ?>

            <?php

            $feture_entries = get_post_meta(get_the_ID(), 'feture_group', true);
            if ($feture_entries) {
                foreach ($feture_entries as $key => $entry) { ?>

                    <div class="meta-info-unit">
                        <div class="icon"><i class="iconly-Arrow-Left-2"></i></div>
                        <div class="value"><?php echo esc_html($entry[$prefix . 'feture_title']); ?> :
                            <span> <?php echo esc_html($entry[$prefix . 'feture_input']); ?></span></div>
                    </div>
                <?php }
            } ?>


        </div>

        <?php if (!empty($course_percent)) : ?>
            <div class="progress-title">
                 درصد پیشرفت دوره: %<?php echo esc_html($course_percent); ?>
                <div class="meter animate">
                    <span style="width: <?php echo esc_html($course_percent); ?>%"><span></span></span>
                </div>
            </div>
        <?php endif; ?>


    <?php endif; ?>

</div>


<?php wc_get_template_part('content', 'single-product-counter'); ?>

