<section class="sptb bg-white">
    <div class="container bg-style">
        <div class="row">
            <div class="col-lg-12 col-md-12 text-center">
                <div class="section-title">
                    <p class="fs-22 lead"><?php echo $heading['sub_title'] ?></p>
                    <h2 class="mt-4"> <?php echo $heading['title'] ?></h2>
                </div>
                <div class="line-with-circle">
                    <div class="line"></div>
                    <div class="circle"></div>
                </div>
            </div>
            <div class="col-xl-12 col-lg-12 col-md-12 mt-4">
                <div class="border-0 br-7 course-details ">
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="panel-group1 course_details" id="accordion4">
                                <?php
                                $c = 1;
                                foreach ($all_course as $courseKey => $course):

                                    $this->db->where('course_id', $course->course_id);
                                    $lessions = $this->db->get('lesson')->result();

                                ?>
                                    <div class="panel panel-default mb-4 p-0" id="course_main_<?php echo $course->course_id; ?>">
                                        <div class="panel-heading1">
                                            <h4 class="panel-title1">
                                                <a class="accordion-toggle collapsed" data-bs-toggle="collapse" data-parent="#accordion4" href="#course_<?php echo $courseKey; ?>" aria-expanded="false">
                                                    <div class="row">
                                                        <div class="col-sm-1 d-flex justify-content-center">
                                                            <div class="course_number"><?php echo $c; ?></div>
                                                        </div>
                                                        <div class="col-sm-11 align-items-center">
                                                            <h4 class="course_heading"><?php echo $course->course_heading; ?></h4>
                                                            <div class="mt-3">
                                                                <ul>
                                                                    <li class="course_con_bg d-inline-block"><i class="fa fa-cog"></i> <?php echo count($lessions); ?> Lessions</li>

                                                                    <?php
                                                                    $lessonCounts = [
                                                                        'video' => 0,
                                                                        'doc' => 0,
                                                                        'pdf' => 0,
                                                                        'text' => 0,
                                                                    ];

                                                                    foreach ($lessions as $lession) {
                                                                        $attachmentType = $lession->attachment_type;

                                                                        if ($attachmentType == 'description') {
                                                                            $lessonCounts['doc']++;
                                                                        } elseif (in_array($attachmentType, ['text', 'pdf', 'doc', 'img'])) {
                                                                            $lessonCounts[$attachmentType]++;
                                                                        } else {
                                                                            $lessonCounts['video']++;
                                                                        }
                                                                    }

                                                                    // Generate output
                                                                    foreach ($lessonCounts as $type => $count) :
                                                                        if ($count > 0) {
                                                                            $lesson_type = $type;
                                                                            $lession_name = ucfirst($type); // Capitalize the first letter for display

                                                                            if ($lesson_type == 'doc') {
                                                                                $lession_name = 'Doc';
                                                                                $lesson_type = 'txt'; // This is just an example, adjust as necessary
                                                                            }
                                                                    ?>
                                                                            <li class="course_con_bg d-inline-block">
                                                                                <img src="<?php echo base_url('assets/lesson_icon/' . $lesson_type . '.png'); ?>" alt="" height="12">
                                                                                <?php echo $count; ?> <?php echo $lession_name; ?>
                                                                            </li>
                                                                    <?php
                                                                        }
                                                                    endforeach;
                                                                    ?>
                                                                </ul>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </a>
                                            </h4>
                                        </div>
                                        <div id="course_<?php echo $courseKey; ?>" class="panel-collapse collapse pt-0" role="tabpanel" aria-expanded="false" style="">
                                            <div class="panel-body bg-white pt-0">
                                                <div class="row">
                                                    <div class="col-sm-1 "></div>
                                                    <div class="col-sm-11">
                                                        <div class="course_content_body mb-3">
                                                            <p class="lead"><?php echo $course->course_sub_heading_2;  ?></p>
                                                        </div>
                                                        <div class="course_content_lession">
                                                            <h4><i class="fa fa-table" aria-hidden="true"></i> Course Content</h4>
                                                            <div class="row section_section">
                                                                <?php
                                                                $this->db->where('course_id', $course->course_id);
                                                                $all_section = $this->db->get('section')->result();
                                                                $n = 1;
                                                                foreach ($all_section as $key => $section): ?>
                                                                    <div class="col-sm-6">
                                                                        <div class="row">
                                                                            <div class="col-sm-12">
                                                                                <p class="lead">Lession <?php echo $n; ?> - <?php echo $section->title; ?> </p>
                                                                                <?php
                                                                                $this->db->where('section_id', $section->id);
                                                                                $this->db->where('course_id', $course->course_id);
                                                                                $all_lesson = $this->db->get('lesson')->result();
                                                                                foreach ($all_lesson as $key => $lesson): ?>
                                                                                    <p><?php echo $lesson->title; ?></p>
                                                                                <?php endforeach; ?>
                                                                            </div>
                                                                        </div>

                                                                    </div>
                                                                <?php $n++;
                                                                endforeach; ?>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>

                                            </div>
                                        </div>
                                    </div>
                                <?php $c++;
                                endforeach; ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
<?php include VIEWPATH . 'front/bundle_course_components/cta.php';?>
<style>
    .course_content_lession .section_section {
        padding: 15px;
    }

    .course_content_lession .lead {
        font-weight: 700;
        font-size: 16px;
    }

    .course_content_lession h4 {
        font-weight: 700;
        background-color: #c7c7c7;
        padding: 15px;
    }

    .course_content_lession {
        background-color: #ddd;
    }

    .course_details .course_heading {
        font-weight: 700;
    }

    .course_con_bg {
        background-color: #ddd;
        border-radius: 5px;
        padding: 5px;
        font-size: 12px;
        color: #000;
        font-weight: 700;
    }

    .course_details .panel-default {
        box-shadow: rgba(99, 99, 99, 0.2) 0px 2px 8px 0px;
    }

    .course_number {
        background-color: var(--theme-color-1);
        color: #fff;
        width: 40px;
        height: 40px;
        border-radius: 50%;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        margin-right: 10px;
        font-weight: 900;
        flex-shrink: 0;
    }

    .course_details .panel-heading1 a.collapsed::before,
    .panel-heading1 a::before {
        top: 25px;
    }

    .course_details .panel-body {
        border-top: 1px solid #fff !important;
    }
</style>