@extends('main.layouts.app')

@section('title', 'Materi')

@section('content')
<div class="container-xxl flex-grow-1 container-p-y">
    <!-- Konten materi -->
    <div class="row">
        <div class="col-lg-12 mx-auto mb-4 order-1">
            <div class="card">
                <div class="d-flex align-items-start row">
                    <div class="col-md-7">
                        <div class="card-body">
                            <h5 class="card-title text-primary">Hai, {{ auth()->user()->nama_lengkap ?? 'Tamu' }} 🎉</h5>
                            <p class="mb-4">Gaya belajar kamu adalah</p>
                            <h2 class="card-title text-primary">Kinestetik</h2>
                        </div>
                    </div>
                    <div class="col-md-3 ms-auto text-end">
                        <div class="card-body pb-0 px-0 px-md-5">
                            <img src="https://raw.githubusercontent.com/Sangga123/asset/refs/heads/main/welcome.jpg" class="img-fluid" alt="Welcome Illustration" />
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
      <!-- Encapsulation Game Container -->
    <div class="row">
        <div class="col-lg-12 mx-auto mb-4">
            <div class="card">
                <div class="card-body">
                    <h5 class="card-title text-primary">Permainan Encapsulation: Bangun Kelas Mahasiswa!</h5>
                    <p class="mb-4">Seret dan susun potongan kode di sebelah kiri ke area kode di sebelah kanan untuk membuat kelas PHP dengan encapsulation yang benar. Pastikan atribut bersifat private dan gunakan getter/setter dengan benar!</p>
                    <div class="row">
                        <!-- Code Snippets (Draggable) -->
                        <div class="col-md-4">
                            <h6 class="text-center mb-3">Potongan Kode</h6>
                            <div id="code-snippets" class="d-flex flex-column gap-2">
                                <div class="code-snippet card p-2 bg-light" data-correct-order="1">
                                    <pre class="mb-0">class Mahasiswa {</pre>
                                </div>
                                <div class="code-snippet card p-2 bg-light" data-correct-order="2">
                                    <pre class="mb-0">private $nama;</pre>
                                </div>
                                <div class="code-snippet card p-2 bg-light" data-correct-order="3">
                                    <pre class="mb-0">private $nim;</pre>
                                </div>
                                <div class="code-snippet card p-2 bg-light" data-correct-order="4">
                                    <pre class="mb-0">public function __construct($nama, $nim) {
    $this->nama = $nama;
    $this->nim = $nim;
}</pre>
                                </div>
                                <div class="code-snippet card p-2 bg-light" data-correct-order="5">
                                    <pre class="mb-0">public function getNama() {
    return $this->nama;
}</pre>
                                </div>
                                <div class="code-snippet card p-2 bg-light" data-correct-order="6">
                                    <pre class="mb-0">public function setNama($nama) {
    $this->nama = $nama;
}</pre>
                                </div>
                                <div class="code-snippet card p-2 bg-light" data-correct-order="7">
                                    <pre class="mb-0">public function getNim() {
    return $this->nim;
}</pre>
                                </div>
                                <div class="code-snippet card p-2 bg-light" data-correct-order="8">
                                    <pre class="mb-0">public function setNim($nim) {
    $this->nim = $nim;
}</pre>
                                </div>
                                <div class="code-snippet card p-2 bg-light" data-correct-order="9">
                                    <pre class="mb-0">}</pre>
                                </div>
                            </div>
                        </div>
                        <!-- Code Builder (Droppable) -->
                        <div class="col-md-8">
                            <h6 class="text-center mb-3">Area Kode</h6>
                            <div id="code-builder" class="card p-3 bg-white border border-primary" style="min-height: 400px;">
                                <p class="text-muted text-center" id="placeholder-text">Seret potongan kode ke sini...</p>
                            </div>
                            <div class="text-center mt-3">
                                <button id="check-code" class="btn btn-primary">Cek Kode</button>
                                <button id="reset-code" class="btn btn-secondary">Reset</button>
                            </div>
                        </div>
                    </div>
                    <!-- Feedback Area -->
                    <div id="feedback" class="mt-3 alert d-none"></div>
                </div>
            </div>
        </div>
    </div>
    

   <!-- Learning Style Sidebar Container -->
<div class="learning-style-sidebar-container position-fixed end-0 top-0 h-100 d-flex flex-column align-items-end" style="z-index: 1050;">
    <!-- Show/Hide Button -->
    <button id="toggleLearningStyleSidebar" class="btn btn-secondary m-3" type="button" style="z-index:1060;">
        <span id="sidebarToggleIcon" class="fas fa-chevron-left"></span> Learning Styles
    </button>
    <!-- Sidebar -->
    <div id="learningStyleSidebar" class="card shadow-lg p-3 bg-white rounded h-100" style="width: 320px; min-width: 220px; max-width: 340px; transition: transform 0.3s; transform: translateX(0);">
        <div class="d-flex flex-column gap-3 mt-4">
            @php
                $current = Route::currentRouteName();
                // List of learning styles
                $learningStyles = [
                    [
                        'route' => 'materi-visual',
                        'icon' => 'eye',
                        'label' => 'Visual',
                        'btnClass' => 'btn-primary'
                    ],
                    [
                        'route' => 'materi-auditory',
                        'icon' => 'volume-2',
                        'label' => 'Auditory',
                        'btnClass' => 'btn-success'
                    ],
                    [
                        'route' => 'materi-read/write',
                        'icon' => 'book-open',
                        'label' => 'Read/Write',
                        'btnClass' => 'btn-secondary'
                    ],
                    [
                        'route' => 'materi-kinesthetic',
                        'icon' => 'move',
                        'label' => 'Kinesthetic',
                        'btnClass' => 'btn-warning'
                    ],
                    [
                        'route' => 'materi-multimodal',
                        'icon' => 'layers',
                        'label' => 'Multimodal',
                        'btnClass' => 'btn-info'
                    ],
                ];
                // Filter out the current learning style
                $filteredStyles = array_filter($learningStyles, function($style) use ($current) {
                    return $style['route'] !== $current;
                });
            @endphp
            @foreach($filteredStyles as $style)
                <a href="{{ route($style['route']) }}" class="text-decoration-none">
                    <div class="card h-100">
                        <div class="card-body d-flex flex-column align-items-center justify-content-center text-center" style="padding-top: 18px; padding-bottom: 18px;">
                            <img src="https://cdn.jsdelivr.net/gh/feathericons/feather/icons/{{ $style['icon'] }}.svg" alt="{{ $style['label'] }} Icon" width="36" height="36" class="mb-2" />
                            <p class="mb-3" style="font-size: 22px; font-weight: bold;">{{ $style['label'] }}</p>
                            <button class="btn {{ $style['btnClass'] }} mt-1" style="width: 90%; font-size: 0.95rem; padding: 6px 0;">Coba Belajar</button>
                        </div>
                    </div>
                </a>
            @endforeach
        </div>
    </div>
</div>

<!-- FontAwesome for chevron icon (if not already loaded) -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">

<style>
    .learning-style-sidebar-container {
        pointer-events: none;
    }
    #toggleLearningStyleSidebar, #learningStyleSidebar {
        pointer-events: auto;
    }
    @media (max-width: 991.98px) {
        .learning-style-sidebar-container {
            position: static !important;
            width: 100%;
            height: auto;
        }
        #learningStyleSidebar {
            width: 100% !important;
            min-width: unset !important;
            max-width: unset !important;
            position: static !important;
            transform: none !important;
        }
        #toggleLearningStyleSidebar {
            position: static !important;
            margin-bottom: 1rem;
        }
    }
</style>

<script>
    const sidebar = document.getElementById('learningStyleSidebar');
    const toggleBtn = document.getElementById('toggleLearningStyleSidebar');
    const icon = document.getElementById('sidebarToggleIcon');
    let sidebarVisible = true;

    toggleBtn.addEventListener('click', function() {
        sidebarVisible = !sidebarVisible;
        if (sidebarVisible) {
            sidebar.style.transform = 'translateX(0)';
            icon.classList.remove('fa-chevron-right');
            icon.classList.add('fa-chevron-left');
        } else {
            sidebar.style.transform = 'translateX(110%)';
            icon.classList.remove('fa-chevron-left');
            icon.classList.add('fa-chevron-right');
        }
    });
</script>
</div>
@section('helpInstructions')
{!! json_encode($helpInstructions) !!}
@endsection
@endsection