@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">Multimodal</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>
    <!-- Multimodal Learning Content: Enhanced UX -->
<div class="row justify-content-center align-items-stretch mb-5">
    <div class="col-12 mb-4">
        <div class="card shadow-lg border-0 h-100">
            <div class="card-body d-flex flex-column justify-content-center align-items-center text-center p-5">
                <h2 class="text-primary mb-3" style="font-weight: 700; letter-spacing: 1px;">
                    Selamat Datang di Materi Multimodal!
                </h2>
                <p class="lead mb-4" style="font-size: 1.2rem;">
                    Gaya belajar <span class="fw-bold text-info">Multimodal</span> menggabungkan visual, audio, membaca/menulis, dan kinestetik. Kamu akan belajar dengan berbagai cara: membaca, melihat gambar, mendengarkan audio, menonton video, dan mencoba langsung!
                </p>
                <div class="d-flex flex-wrap justify-content-center gap-3 mb-4">
                    <span class="badge bg-primary fs-6 px-3 py-2"><i class="fas fa-eye me-2"></i>Visual</span>
                    <span class="badge bg-success fs-6 px-3 py-2"><i class="fas fa-volume-up me-2"></i>Auditory</span>
                    <span class="badge bg-warning text-dark fs-6 px-3 py-2"><i class="fas fa-pen-nib me-2"></i>Read/Write</span>
                    <span class="badge bg-danger fs-6 px-3 py-2"><i class="fas fa-running me-2"></i>Kinestetik</span>
                </div>
                <div class="row g-3">
                    <div class="col-6 col-md-3">
                        <img src="https://cdn.pixabay.com/photo/2017/01/31/13/14/online-2025930_1280.png" alt="Visual" class="img-fluid rounded shadow-sm" style="max-height: 80px;">
                        <div class="small mt-2 text-muted">Visual</div>
                    </div>
                    <div class="col-6 col-md-3">
                        <img src="https://cdn.pixabay.com/photo/2016/03/31/19/56/headphones-1296529_1280.png" alt="Audio" class="img-fluid rounded shadow-sm" style="max-height: 80px;">
                        <div class="small mt-2 text-muted">Audio</div>
                    </div>
                    <div class="col-6 col-md-3">
                        <img src="https://cdn.pixabay.com/photo/2014/04/03/10/32/book-312417_1280.png" alt="Read/Write" class="img-fluid rounded shadow-sm" style="max-height: 80px;">
                        <div class="small mt-2 text-muted">Read/Write</div>
                    </div>
                    <div class="col-6 col-md-3">
                        <img src="https://cdn.pixabay.com/photo/2016/03/31/20/11/hand-1296530_1280.png" alt="Kinestetik" class="img-fluid rounded shadow-sm" style="max-height: 80px;">
                        <div class="small mt-2 text-muted">Kinestetik</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="col-12 mb-4">
        <div class="card shadow-lg border-0 h-100 bg-gradient" style="background: linear-gradient(135deg, #e0f7fa 0%, #fffde7 100%);">
            <div class="card-body d-flex flex-column justify-content-center align-items-center text-center p-5">
                <h4 class="mb-3 text-secondary fw-bold">Tips Belajar Multimodal</h4>
                <ul class="list-unstyled text-start mx-auto" style="max-width: 340px;">
                    <li class="mb-2"><i class="fas fa-check-circle text-primary me-2"></i>Gunakan warna & gambar untuk memahami konsep.</li>
                    <li class="mb-2"><i class="fas fa-check-circle text-success me-2"></i>Dengarkan penjelasan audio atau rekaman.</li>
                    <li class="mb-2"><i class="fas fa-check-circle text-warning me-2"></i>Buat catatan atau rangkuman sendiri.</li>
                    <li class="mb-2"><i class="fas fa-check-circle text-danger me-2"></i>Coba praktikkan langsung dengan simulasi atau permainan.</li>
                </ul>
                <div class="mt-3">
                    <a href="#encapsulation-game" class="btn btn-info btn-lg shadow-sm px-4 py-2">
                        <i class="fas fa-gamepad me-2"></i>Mulai Permainan Interaktif
                    </a>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- Encapsulation Game Container -->
<a id="encapsulation-game"></a>
<div class="row">
    <div class="col-lg-12 mx-auto mb-4">
        <div class="card shadow border-0">
            <div class="card-body">
                <h5 class="card-title text-primary d-flex align-items-center">
                    <i class="fas fa-puzzle-piece me-2"></i>Permainan: Bangun & Visualisasikan Encapsulation
                </h5>
                <p class="mb-4">
                    <span class="fw-bold text-info">Seret</span> potongan kode di sebelah kiri ke area kode untuk membangun kelas PHP <code>Mahasiswa</code> dengan enkapsulasi.<br>
                    <span class="fw-bold text-success">Lihat</span> diagram kelas di sebelah kanan yang akan terbentuk secara real-time berdasarkan kode yang kamu susun!<br>
                    <span class="fw-bold text-warning">Dengarkan</span> penjelasan audio di bawah jika ingin memahami lebih lanjut.
                </p>
                <div class="mb-3">
                    <audio controls>
                        <source src="https://cdn.pixabay.com/audio/2022/07/26/audio_124bfae1e2.mp3" type="audio/mp3">
                        Penjelasan audio tidak tersedia.
                    </audio>
                    <div class="small text-muted mt-1">Audio: Penjelasan singkat tentang enkapsulasi di OOP PHP</div>
                </div>
                <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" data-type="class">
                                <pre class="mb-0">class Mahasiswa {</pre>
                            </div>
                            <div class="code-snippet card p-2 bg-light" data-correct-order="2" data-type="attribute">
                                <pre class="mb-0">private $nama;</pre>
                            </div>
                            <div class="code-snippet card p-2 bg-light" data-correct-order="3" data-type="attribute">
                                <pre class="mb-0">private $nim;</pre>
                            </div>
                            <div class="code-snippet card p-2 bg-light" data-correct-order="4" data-type="constructor">
                                <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" data-type="method">
                                <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" data-type="method">
                                <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" data-type="method">
                                <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" data-type="method">
                                <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" data-type="class">
                                <pre class="mb-0">}</pre>
                            </div>
                        </div>
                    </div>
                    <!-- Code Builder and Diagram -->
                    <div class="col-md-8">
                        <div class="row">
                            <div class="col-12 col-lg-6 mb-3 mb-lg-0">
                                <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 me-2"><i class="fas fa-check"></i> Cek Kode</button>
                                    <button id="reset-code" class="btn btn-secondary"><i class="fas fa-undo"></i> Reset</button>
                                </div>
                            </div>
                            <div class="col-12 col-lg-6">
                                <h6 class="text-center mb-3">Diagram Kelas</h6>
                                <div id="class-diagram" class="card p-3 bg-white border border-info" style="min-height: 400px;">
                                    <svg id="diagram-svg" width="100%" height="100%"></svg>
                                </div>
                                <div class="text-center mt-2">
                                    <button class="btn btn-outline-info btn-sm" data-bs-toggle="modal" data-bs-target="#videoModal">
                                        <i class="fas fa-play-circle"></i> Tonton Video Penjelasan
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- Feedback Area -->
                <div id="feedback" class="mt-3 alert d-none"></div>
            </div>
        </div>
    </div>
</div>

<!-- Modal Video Penjelasan -->
<div class="modal fade" id="videoModal" tabindex="-1" aria-labelledby="videoModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-lg modal-dialog-centered">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="videoModalLabel">Video Penjelasan Enkapsulasi</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Tutup"></button>
      </div>
      <div class="modal-body p-0">
        <div class="ratio ratio-16x9">
          <iframe src="https://www.youtube.com/embed/1uFY60CESlM" title="Penjelasan Enkapsulasi OOP PHP" allowfullscreen></iframe>
        </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-3">
                @php
                    $current = Route::currentRouteName();
                    $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' => 'edit-3',
                            'label' => 'Read/Write',
                            'btnClass' => 'btn-warning'
                        ],
                        [
                            'route' => 'materi-kinesthetic',
                            'icon' => 'activity',
                            'label' => 'Kinestetik',
                            'btnClass' => 'btn-danger'
                        ],
                        [
                            'route' => 'materi-multimodal',
                            'icon' => 'layers',
                            'label' => 'Multimodal',
                            'btnClass' => 'btn-info'
                        ],
                    ];
                @endphp
                @foreach($learningStyles as $style)
                    @if($style['route'] !== $current)
                    <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;">
                                <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: 80%; font-size: 0.95rem; padding: 4px 0;">Coba Belajar</button>
                            </div>
                        </div>
                    </a>
                    @endif
                @endforeach
            </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-3">
            @php
                $current = Route::currentRouteName();
                $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' => 'edit-3',
                        'label' => 'Read/Write',
                        'btnClass' => 'btn-warning'
                    ],
                    [
                        'route' => 'materi-kinesthetic',
                        'icon' => 'activity',
                        'label' => 'Kinestetik',
                        'btnClass' => 'btn-danger'
                    ],
                    [
                        'route' => 'materi-multimodal',
                        'icon' => 'layers',
                        'label' => 'Multimodal',
                        'btnClass' => 'btn-info'
                    ],
                ];
            @endphp
            @foreach($learningStyles as $style)
                @if($style['route'] !== $current)
                <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;">
                            <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: 80%; font-size: 0.95rem; padding: 4px 0;">Coba Belajar</button>
                        </div>
                    </div>
                </a>
                @endif
            @endforeach
        </div>
    </div>
</div>
</div>

<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>

<!-- 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;
    }
    #learningStyleSidebar .card {
        margin-bottom: 0.5rem;
    }
    #learningStyleSidebar .btn {
        min-width: 90px;
        max-width: 120px;
        padding: 4px 0;
        font-size: 0.95rem;
    }
    @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>
</style>
@section('helpInstructions')
{!! json_encode($helpInstructions) !!}
@endsection
@endsection