<?php $__env->startSection('title', 'লাইব্রেরি ড্যাশবোর্ড'); ?>

<?php $__env->startSection('content'); ?>
<div class="container-fluid">
    <!-- Statistics Cards -->
<div class="row">
    <div class="col-lg-4 col-6">
        <div class="small-box bg-info">
            <div class="inner">
                <h3><?php echo e($stats['total_books'] ?? 0); ?></h3>
                <p>মোট বই</p>
            </div>
            <div class="icon">
                <i class="fas fa-book"></i>
            </div>
            <a href="<?php echo e(route('library.books')); ?>" class="small-box-footer">বিস্তারিত <i class="fas fa-arrow-circle-right"></i></a>
        </div>
    </div>
    
    <div class="col-lg-4 col-6">
        <div class="small-box bg-success">
            <div class="inner">
                <h3><?php echo e($stats['available_books'] ?? 0); ?></h3>
                <p>লাইব্রেরিতে আছে</p>
            </div>
            <div class="icon">
                <i class="fas fa-check-circle"></i>
            </div>
            <a href="<?php echo e(route('library.books')); ?>" class="small-box-footer">বিস্তারিত <i class="fas fa-arrow-circle-right"></i></a>
        </div>
    </div>
    
    <div class="col-lg-4 col-6">
        <div class="small-box bg-warning">
            <div class="inner">
                <h3><?php echo e($stats['issued_books'] ?? 0); ?></h3>
                <p>ইস্যুকৃত বই</p>
            </div>
            <div class="icon">
                <i class="fas fa-hand-holding"></i>
            </div>
            <a href="<?php echo e(route('library.issues')); ?>" class="small-box-footer">বিস্তারিত <i class="fas fa-arrow-circle-right"></i></a>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-lg-4 col-6">
        <div class="small-box bg-danger">
            <div class="inner">
                <h3><?php echo e($stats['overdue_books'] ?? 0); ?></h3>
                <p>মেয়াদোত্তীর্ণ</p>
            </div>
            <div class="icon">
                <i class="fas fa-exclamation-triangle"></i>
            </div>
            <a href="<?php echo e(route('library.issues', ['status' => 'overdue'])); ?>" class="small-box-footer">বিস্তারিত <i class="fas fa-arrow-circle-right"></i></a>
        </div>
    </div>
    
    <div class="col-lg-4 col-6">
        <div class="small-box bg-primary">
            <div class="inner">
                <h3><?php echo e($stats['total_categories'] ?? 0); ?></h3>
                <p>বইয়ের ক্যাটাগরি</p>
            </div>
            <div class="icon">
                <i class="fas fa-tags"></i>
            </div>
            <a href="<?php echo e(route('library.categories')); ?>" class="small-box-footer">বিস্তারিত <i class="fas fa-arrow-circle-right"></i></a>
        </div>
    </div>
    
    <div class="col-lg-4 col-6">
        <div class="small-box bg-secondary">
            <div class="inner">
                <h3><?php echo e($stats['total_students'] ?? 0); ?></h3>
                <p>মোট ছাত্র/ছাত্রী</p>
            </div>
            <div class="icon">
                <i class="fas fa-users"></i>
            </div>
            <a href="<?php echo e(route('students.index')); ?>" class="small-box-footer">বিস্তারিত <i class="fas fa-arrow-circle-right"></i></a>
        </div>
    </div>
</div>

    <!-- Quick Actions -->
    <div class="row">
        <div class="col-md-12">
            <div class="card card-primary card-outline">
                <div class="card-header bg-primary text-white">
                    <h5 class="mb-0"><i class="fa fa-bolt"></i> দ্রুত অ্যাকশন</h5>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-3">
                            <button type="button" class="btn btn-success btn-block" data-toggle="modal" data-target="#addBookModal">
                                <i class="fa fa-plus-circle"></i> নতুন বই যোগ
                            </button>
                        </div>
                        <div class="col-md-3">
                            <button type="button" class="btn btn-warning btn-block" data-toggle="modal" data-target="#issueBookModal">
                                <i class="fa fa-hand-holding"></i> বই ইস্যু
                            </button>
                        </div>
                        <div class="col-md-3">
                            <a href="<?php echo e(route('library.issues')); ?>" class="btn btn-info btn-block">
                                <i class="fa fa-list"></i> ইস্যুকৃত বই
                            </a>
                        </div>
                        <div class="col-md-3">
                            <a href="<?php echo e(route('library.books.download')); ?>" class="btn btn-secondary btn-block" target="_blank">
                                <i class="fa fa-download"></i> বই তালিকা ডাউনলোড
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Recent Issues -->
<div class="row mt-4">
    <div class="col-md-12">
        <div class="card">
            <div class="card-header bg-info text-white">
                <h5 class="mb-0"><i class="fas fa-history"></i> সাম্প্রতিক ইস্যু</h5>
            </div>
            <div class="card-body p-0">
                <div class="table-responsive">
                    <table class="table table-striped table-hover mb-0">
                        <thead class="bg-secondary text-white">
                            <tr>
                                <th>বই</th>
                                <th>ইস্যুকৃত</th>
                                <th>ইস্যুর তারিখ</th>
                                <th>ফেরতের তারিখ</th>
                                <th>স্ট্যাটাস</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php $__empty_1 = true; $__currentLoopData = $recentIssues; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $issue): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <tr>
                                <td><?php echo e($issue->book->title_bn ?? $issue->book->title); ?></td>
                                <td>
                                    <?php if($issue->student): ?>
                                        <?php echo e($issue->student->name_bn); ?> (ছাত্র)
                                    <?php elseif($issue->teacher): ?>
                                        <?php echo e($issue->teacher->name_bn); ?> (শিক্ষক)
                                    <?php endif; ?>
                                </td>
                                <td><?php echo e($issue->issue_date->format('d-m-Y')); ?></td>
                                <td><?php echo e($issue->due_date->format('d-m-Y')); ?></td>
                                <td>
                                    <?php if($issue->status == 'issued'): ?>
                                        <?php if($issue->due_date < now()): ?>
                                            <span class="badge badge-danger">মেয়াদোত্তীর্ণ</span>
                                        <?php else: ?>
                                            <span class="badge badge-success">ইস্যুকৃত</span>
                                        <?php endif; ?>
                                    <?php elseif($issue->status == 'returned'): ?>
                                        <span class="badge badge-info">ফেরতকৃত</span>
                                    <?php endif; ?>
                                </td>
                            </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                            <tr>
                                <td colspan="5" class="text-center text-muted py-3">
                                    <i class="fas fa-info-circle"></i> কোনো ইস্যু নেই
                                </td>
                            </tr>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="card-footer text-right">
                <a href="<?php echo e(route('library.issues')); ?>" class="btn btn-sm btn-primary">
                    সকল ইস্যু দেখুন <i class="fas fa-arrow-right"></i>
                </a>
            </div>
        </div>
    </div>
</div>

<!-- Popular Books -->
<div class="row mt-4">
    <div class="col-md-12">
        <div class="card">
            <div class="card-header bg-success text-white">
                <h5 class="mb-0"><i class="fas fa-star"></i> জনপ্রিয় বই</h5>
            </div>
            <div class="card-body p-0">
                <div class="table-responsive">
                    <table class="table table-striped table-hover mb-0">
                        <thead class="bg-secondary text-white">
                            <tr>
                                <th>বই</th>
                                <th>লেখক</th>
                                <th>ইস্যু সংখ্যা</th>
                                <th>স্টক</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php $__empty_1 = true; $__currentLoopData = $popularBooks; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $book): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <tr>
                                <td><?php echo e($book->title_bn ?? $book->title); ?></td>
                                <td><?php echo e($book->author_bn ?? $book->author); ?></td>
                                <td><?php echo e($book->issues_count); ?></td>
                                <td><?php echo e($book->available_copies); ?>/<?php echo e($book->total_copies); ?></td>
                            </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                            <tr>
                                <td colspan="4" class="text-center text-muted py-3">
                                    <i class="fas fa-info-circle"></i> কোনো তথ্য নেই
                                </td>
                            </tr>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- Add Book Modal -->
<div class="modal fade" id="addBookModal" tabindex="-1">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header bg-success text-white">
                <h5 class="modal-title">নতুন বই যোগ করুন</h5>
                <button type="button" class="close" data-dismiss="modal">&times;</button>
            </div>
            <form action="<?php echo e(route('library.books.add')); ?>" method="POST" enctype="multipart/form-data">
                <?php echo csrf_field(); ?>
                <div class="modal-body">
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label>বইয়ের নাম (ইংরেজি) <span class="text-danger">*</span></label>
                                <input type="text" name="title" class="form-control" required>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label>বইয়ের নাম (বাংলা)</label>
                                <input type="text" name="title_bn" class="form-control">
                            </div>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label>লেখক (ইংরেজি) <span class="text-danger">*</span></label>
                                <input type="text" name="author" class="form-control" required>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label>লেখক (বাংলা)</label>
                                <input type="text" name="author_bn" class="form-control">
                            </div>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-md-4">
                            <div class="form-group">
                                <label>ISBN</label>
                                <input type="text" name="isbn" class="form-control">
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="form-group">
                                <label>প্রকাশক</label>
                                <input type="text" name="publisher" class="form-control">
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="form-group">
                                <label>প্রকাশনী বছর</label>
                                <input type="number" name="publication_year" class="form-control" min="1900" max="<?php echo e(date('Y')); ?>">
                            </div>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-md-4">
                            <div class="form-group">
                                <label>ক্যাটাগরি <span class="text-danger">*</span></label>
                                <select name="category_id" class="form-control" required>
                                    <option value="">নির্বাচন করুন</option>
                                    <?php $__currentLoopData = App\Models\BookCategory::all(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $category): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($category->id); ?>"><?php echo e($category->name_bn ?? $category->name); ?></option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="form-group">
                                <label>শেলফের অবস্থান</label>
                                <input type="text" name="shelf_location" class="form-control" placeholder="A-10">
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="form-group">
                                <label>ভাষা</label>
                                <input type="text" name="language" class="form-control" value="বাংলা">
                            </div>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-md-4">
                            <div class="form-group">
                                <label>মোট কপি <span class="text-danger">*</span></label>
                                <input type="number" name="total_copies" class="form-control" value="1" min="1" required>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="form-group">
                                <label>মূল্য (টাকা)</label>
                                <input type="number" name="price" class="form-control" step="0.01">
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="form-group">
                                <label>পৃষ্ঠা সংখ্যা</label>
                                <input type="number" name="pages" class="form-control">
                            </div>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-md-12">
                            <div class="form-group">
                                <label>বিবরণ</label>
                                <textarea name="description" class="form-control" rows="3"></textarea>
                            </div>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-md-12">
                            <div class="form-group">
                                <label>কভার ছবি</label>
                                <input type="file" name="cover_image" class="form-control" accept="image/*">
                                <small class="text-muted">সর্বোচ্চ ২MB, JPG/PNG ফরম্যাট</small>
                            </div>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-md-12">
                            <div class="form-group">
                                <label>কীওয়ার্ড (কমা দিয়ে আলাদা করুন)</label>
                                <input type="text" name="keywords" class="form-control" placeholder="উপন্যাস, রহস্য, থ্রিলার">
                            </div>
                        </div>
                    </div>
                </div>
                
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">বাতিল</button>
                    <button type="submit" class="btn btn-success">বই যোগ করুন</button>
                </div>
            </form>
        </div>
    </div>
</div>

<!-- Issue Book Modal -->
<div class="modal fade" id="issueBookModal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header bg-warning">
                <h5 class="modal-title">বই ইস্যু করুন</h5>
                <button type="button" class="close" data-dismiss="modal">&times;</button>
            </div>
            <form action="<?php echo e(route('library.issue')); ?>" method="POST">
                <?php echo csrf_field(); ?>
                <div class="modal-body">
                    <div class="form-group">
                        <label>বই নির্বাচন করুন <span class="text-danger">*</span></label>
                        <select name="book_id" class="form-control book-select" required>
                            <option value="">বই খুঁজুন...</option>
                            <?php $__currentLoopData = App\Models\Book::where('available_copies', '>', 0)->limit(20)->get(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $book): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($book->id); ?>"><?php echo e($book->title_bn ?? $book->title); ?> (<?php echo e($book->available_copies); ?> copy available)</option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    </div>

                    <div class="form-group">
                        <label>ছাত্র নির্বাচন করুন</label>
                        <select name="student_id" class="form-control student-select">
                            <option value="">ছাত্র খুঁজুন...</option>
                            <?php $__currentLoopData = App\Models\Student::limit(20)->get(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $student): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($student->id); ?>"><?php echo e($student->name_bn); ?> (<?php echo e($student->student_id); ?>)</option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    </div>

                    <div class="form-group">
                        <label>অথবা শিক্ষক নির্বাচন করুন</label>
                        <select name="teacher_id" class="form-control teacher-select">
                            <option value="">শিক্ষক খুঁজুন...</option>
                            <?php $__currentLoopData = App\Models\Teacher::limit(20)->get(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $teacher): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($teacher->id); ?>"><?php echo e($teacher->name_bn); ?> (<?php echo e($teacher->teacher_id); ?>)</option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    </div>

                    <div class="form-group">
                        <label>ফেরতের তারিখ <span class="text-danger">*</span></label>
                        <input type="date" name="due_date" class="form-control" value="<?php echo e(date('Y-m-d', strtotime('+15 days'))); ?>" required>
                        <small class="text-muted">ছাত্রদের জন্য ১৫ দিন, শিক্ষকদের জন্য ৩০ দিন</small>
                    </div>
                </div>
                
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">বাতিল</button>
                    <button type="submit" class="btn btn-warning">বই ইস্যু করুন</button>
                </div>
            </form>
        </div>
    </div>
</div>

<?php $__env->startSection('scripts'); ?>
<script>
    $(document).ready(function() {
        // Initialize select2
        $('.book-select, .student-select, .teacher-select').select2({
            width: '100%',
            dropdownParent: $('#issueBookModal')
        });

        // Disable teacher select if student is selected and vice versa
        $('.student-select').change(function() {
            if ($(this).val()) {
                $('.teacher-select').prop('disabled', true);
            } else {
                $('.teacher-select').prop('disabled', false);
            }
        });

        $('.teacher-select').change(function() {
            if ($(this).val()) {
                $('.student-select').prop('disabled', true);
            } else {
                $('.student-select').prop('disabled', false);
            }
        });

        // Adjust due date based on selection
        $('.student-select, .teacher-select').change(function() {
            if ($('.student-select').val()) {
                $('input[name="due_date"]').val('<?php echo e(date("Y-m-d", strtotime("+15 days"))); ?>');
            } else if ($('.teacher-select').val()) {
                $('input[name="due_date"]').val('<?php echo e(date("Y-m-d", strtotime("+30 days"))); ?>');
            }
        });
    });
</script>
<?php $__env->stopSection(); ?>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/naowarin/school.naowarinternational.my.id/resources/views/library/index.blade.php ENDPATH**/ ?>