

<?php $__env->startSection('content'); ?>
    <!-- BEGIN: Page content-->
    <div>
        <div class="card">
            <div class="card-header d-flex justify-content-between align-items-center">
                <h5 class="box-title">Stories</h5>
                <button class="btn btn-primary btn-sm" data-toggle="modal" data-target="#addStoryModal">
                    <i class="fa fa-plus-circle mr-1"></i> Add Story
                </button>
            </div>
            <div class="card-body">
                <?php echo $__env->make('components.alert', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>

                <div class="table-responsive">
                    <table class="table table-bordered w-100" id="dt-responsive">
                        <thead class="thead-light">
                            <tr>
                                <th>SL</th>
                                <th>Year</th>
                                <th>Story</th>
                                <th>Action</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php $__empty_1 = true; $__currentLoopData = $stories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $story): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                <tr>
                                    <td><?php echo e($index + 1); ?></td>
                                    <td><?php echo e($story->year); ?></td>
                                    <td><?php echo e($story->story); ?></td>
                                    <td>
                                        <form action="<?php echo e(route('stories.destroy', $story->id)); ?>" method="POST"
                                            class="d-inline-block"
                                            onsubmit="return confirm('Are you sure you want to delete this story?')">
                                            <?php echo csrf_field(); ?>
                                            <?php echo method_field('DELETE'); ?>
                                            <button class="btn btn-sm btn-danger">Delete</button>
                                        </form>
                                    </td>
                                </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                <tr>
                                    <td colspan="4" class="text-center">No stories found.</td>
                                </tr>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>

    <!-- Add Story Modal -->
    <div class="modal fade" id="addStoryModal" tabindex="-1" role="dialog" aria-labelledby="addStoryModalLabel"
        aria-hidden="true">
        <div class="modal-dialog" role="document">
            <form id="addStoryForm" action="<?php echo e(route('stories.store')); ?>" method="POST" class="modal-content">
                <?php echo csrf_field(); ?>
                <div class="modal-header">
                    <h5 class="modal-title" id="addStoryModalLabel">Add New Story</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>

                <div class="modal-body">
                    <div class="form-group">
                        <label for="storyYear">Year</label>
                        <input type="number" name="year" id="storyYear" class="form-control" placeholder="Enter year"
                            required>
                    </div>
                    <div class="form-group">
                        <label for="storyText">Story</label>
                        <textarea name="story" id="storyText" class="form-control" rows="4" placeholder="Enter story text" required></textarea>
                    </div>
                </div>

                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
                    <button type="submit" class="btn btn-primary">Add Story</button>
                </div>
            </form>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('script'); ?>
    <script>
        $(document).ready(function() {
            $('#addStoryForm').submit(function(e) {
                e.preventDefault();

                let formdata = $(this).serialize();

                $.ajax({
                    url: $(this).attr('action'),
                    type: $(this).attr('method'),
                    data: formdata,
                    success: function(response) {
                        if (response.success) {
                            Swal.fire({
                                title: "Success",
                                text: response.message,
                                icon: "success"
                            });

                            $('#addStoryModal').modal('hide');
                            window.location.reload();
                        } else {
                            Swal.fire("Error!", response.message, "error");
                            $('#addStoryModal').modal('hide');
                        }
                    },
                    error: function(xhr) {
                        Swal.fire("Error!", "Validation failed or server error.", "error");
                    }
                });
            });
        });
    </script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('admin.masterAdmin', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\xampp\htdocs\TGP-hospital-site\resources\views/admin/stories/index.blade.php ENDPATH**/ ?>