
<?php $__env->startSection('pageTitle', isset($pageTitle) ? $pageTitle : 'Add Album'); ?>

<?php $__env->startSection('content'); ?>

<div class="page-header">
    <div class="row">
        <div class="col-md-6 col-sm-12">
            <div class="title">
                <h4>Add Album</h4>
            </div>
            <nav aria-label="breadcrumb" role="navigation">
                <ol class="breadcrumb">
                    <li class="breadcrumb-item">
                        <a href="<?php echo e(route('admin.dashboard')); ?>">Home</a>
                    </li>
                    <li class="breadcrumb-item active" aria-current="page">Add Album</li>
                </ol>
            </nav>
        </div>
        <div class="col-md-6 col-sm-12 text-right">
            <a href="<?php echo e(route('admin.album')); ?>" class="btn btn-primary">View All Albums</a>
        </div>
    </div>
</div>

<form action="<?php echo e(route('admin.create_album')); ?>" method="POST" enctype="multipart/form-data" id="addAlbumForm" autocomplete="off">
    <?php echo csrf_field(); ?>
    <div class="row">
        <div class="col-md-9">
            <div class="card card-box mb-2">
                <div class="card-body">
                    <div class="form-group">
                        <label for="title"><b>Album Title</b>:</label>
                        <input type="text" name="title" class="form-control" placeholder="Enter album title">
                        <span class="text-danger error-text title_error"></span>
                    </div>
                    <div class="form-group">
                        <label for="description"><b>Description</b>:</label>
                        <textarea name="description" class="form-control" rows="3" placeholder="Write a short description..."></textarea>
                        <span class="text-danger error-text description_error"></span>
                    </div>
                    <div class="form-check mb-3">
                        <input type="checkbox" name="is_published" class="form-check-input" id="is_published">
                        <label class="form-check-label" for="is_published">Publish this album</label>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-3">
            <div class="card card-box mb-2">
                <div class="card-body">
                    <div class="form-group">
                        <label for="cover_photo"><b>Cover Photo</b>:</label>
                        <input type="file" name="cover_photo" class="form-control-file form-control" accept="image/*">
                        <span class="text-danger error-text cover_photo_error"></span>
                    </div>
                    <div class="d-block mb-3" style="max-width:200px">
                        <img src="" alt="" class="img-thumbnail" id="album_image_preview">
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="mb-3">
        <button type="submit" class="btn btn-primary">Add Album</button>
    </div>
</form>

<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
<script>
    document.addEventListener("DOMContentLoaded", function() {
        const inputFile = document.querySelector('input[type="file"][name="cover_photo"]');
        const previewImage = document.getElementById("album_image_preview");

        inputFile.addEventListener("change", function(event) {
            const file = event.target.files[0];
            if (file) {
                const reader = new FileReader();
                reader.onload = function(e) {
                    previewImage.src = e.target.result;
                };
                reader.readAsDataURL(file);
            }
        });
    });

    $(document).ready(function () {
        $('#addAlbumForm').submit(function (e) {
            e.preventDefault();

            var form = this;
            var formData = new FormData(form);

            $.ajax({
                url: $(form).attr('action'),
                method: $(form).attr('method'),
                data: formData,
                processData: false,
                contentType: false,
                dataType: 'json',
                beforeSend: function () {
                    $(form).find('span.error-text').text('');
                },
                success: function (data) {
                    if (data.status === 1) {
                        $(form)[0].reset();
                        $('#album_image_preview').attr('src', '');
                        toastr.success(data.message);
                    } else {
                        toastr.error(data.message);
                    }
                },
                error: function (data) {
                    $.each(data.responseJSON.errors, function (prefix, val) {
                        $(form).find('span.' + prefix + '_error').text(val[0]);
                    });
                }
            });
        });
    });
</script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('back.layout.page-layout', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\xampp\htdocs\larablog\resources\views\back\pages\album\add_album.blade.php ENDPATH**/ ?>