

<?php $__env->startSection('section'); ?>
<div class="page-body">
    <div class="container-fluid">
        <!-- Page Title & Breadcrumb -->
        <div class="row page-title">
            <div class="col-sm-6">
                <h3><?php echo e($title); ?></h3>
            </div>
            <div class="col-sm-6">
                <nav>
                    <ol class="breadcrumb justify-content-sm-end align-items-center">
                        <li class="breadcrumb-item"><a href="<?php echo e(route('dashboard')); ?>">
                                <svg class="svg-color">
                                    <use href="<?php echo e(asset('assets/svg/iconly-sprite.svg#Home')); ?>"></use>
                                </svg></a></li>
                        <li class="breadcrumb-item">Blog</li>
                        <li class="breadcrumb-item active"><?php echo e($title); ?></li>
                    </ol>
                </nav>
            </div>
        </div>

        <!-- Form Start -->
        <div class="row">
            <div class="col-sm-12">
                <div class="card">
                    <div class="card-body">

                        <!-- Validation Errors -->
                        <?php if($errors->any()): ?>
                        <div class="alert alert-danger">
                            <ul><?php $__currentLoopData = $errors->all(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $error): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><li><?php echo e($error); ?></li><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></ul>
                        </div>
                        <?php endif; ?>

                        <form action="<?php echo e(route('blog.store')); ?>" method="POST" enctype="multipart/form-data">
                            <?php echo csrf_field(); ?>
                            <div class="row">

                                <!-- Category -->
                                <div class="col-md-6 mb-3">
                                    <label for="category">Category *</label>
                                    <select class="form-select <?php $__errorArgs = ['category_id'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>" name="category_id" id="category">
                                        <option value="">Select Category</option>
                                        <?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $category): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($category->id); ?>" <?php echo e(old('category_id') == $category->id ? 'selected' : ''); ?>><?php echo e($category->name); ?></option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                    <?php $__errorArgs = ['category_id'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <p class="invalid-feedback"><?php echo e($message); ?></p> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                </div>

                                <!-- Title -->
                                <div class="col-md-6 mb-3">
                                    <label for="title">Title *</label>
                                    <input type="text" class="form-control <?php $__errorArgs = ['title'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>" name="title" id="title" value="<?php echo e(old('title')); ?>" required>
                                    <?php $__errorArgs = ['title'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <p class="invalid-feedback"><?php echo e($message); ?></p> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                </div>

                                <!-- Image Upload -->
                                <div class="col-md-6 mb-3">
                                    <label for="image">Image</label>
                                    <input type="file" class="form-control <?php $__errorArgs = ['image'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>" name="image" id="image" onchange="previewImage(event)">
                                    <?php $__errorArgs = ['image'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <p class="invalid-feedback"><?php echo e($message); ?></p> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>

                                    <!--<div class="mt-3">-->
                                    <!--    <label>Image Preview</label>-->
                                    <!--    <div class="border rounded" style="height: 200px; overflow: hidden;">-->
                                    <!--        <img id="imagePreview" src="#" style="width: 100%; height: 100%; object-fit: cover; display: none;">-->
                                    <!--    </div>-->
                                    <!--</div>-->
                                </div>

                                <!-- Tags -->
                                <div class="col-md-6 mb-3">
                                    <label for="tag_id">Tags</label>
                                    <select class="form-select <?php $__errorArgs = ['tag_id'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>" name="tag_id[]" id="tag_id" multiple>
                                        <?php $__currentLoopData = $tags; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tag): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($tag->id); ?>" <?php echo e(in_array($tag->id, old('tag_id', [])) ? 'selected' : ''); ?>><?php echo e($tag->name); ?></option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        <option value="other">Other</option>
                                    </select>
                                    <div id="manual_tag_container" class="mt-2" style="display: none;">
                                        <div class="input-group">
                                            <input type="text" class="form-control" id="manual_tag_input" placeholder="Enter new tag">
                                            <button type="button" class="btn btn-outline-primary" id="add_tag_button">Add</button>
                                        </div>
                                    </div>
                                    <?php $__errorArgs = ['tag_id'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <p class="invalid-feedback"><?php echo e($message); ?></p> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                </div>

                                <!-- Comments -->
                                <div class="col-md-6 mb-3">
                                    <label for="comments">Allow Comments</label>
                                    <select class="form-select" name="comments" id="comments">
                                        <option value="1" <?php echo e(old('comments') == '1' ? 'selected' : ''); ?>>Yes</option>
                                        <option value="0" <?php echo e(old('comments') == '0' ? 'selected' : ''); ?>>No</option>
                                    </select>
                                </div>

                                <!-- Status -->
                                <div class="col-md-6 mb-3">
                                    <label for="status">Status</label>
                                    <select class="form-select" name="status" id="status">
                                        <option value="1" <?php echo e(old('status') == '1' ? 'selected' : ''); ?>>Published</option>
                                        <option value="0" <?php echo e(old('status') == '0' ? 'selected' : ''); ?>>Draft</option>
                                    </select>
                                </div>
                                <!-- Content -->
                                <div class="col-md-12 mb-3">
                                    <label for="content">Content *</label>
                                    <textarea name="content" id="editor" class="form-control <?php $__errorArgs = ['content'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>" rows="12"><?php echo e(old('content')); ?></textarea>
                                    <?php $__errorArgs = ['content'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <p class="invalid-feedback"><?php echo e($message); ?></p> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                </div>
                                <!-- Meta -->
                                <div class="col-md-6 mb-3">
                                    <label for="meta_title">Meta Title</label>
                                    <input type="text" class="form-control" name="meta_title" id="meta_title" value="<?php echo e(old('meta_title')); ?>">
                                </div>
                                <div class="col-md-6 mb-3">
                                    <label for="meta_keywords">Meta Keywords</label>
                                    <input type="text" class="form-control" name="meta_keywords" value="<?php echo e(old('meta_keywords')); ?>">
                                </div>

                                <div class="col-md-12 mb-3">
                                    <label for="meta_description">Meta Description</label>
                                    <textarea class="form-control" name="meta_description" rows="2"><?php echo e(old('meta_description')); ?></textarea>
                                </div>

                                <!-- Submit Button -->
                                <div class="col-md-12 text-end">
                                    <button type="submit" class="btn btn-success">Publish Blog</button>
                                </div>
                            </div>
                        </form>


                        
                        <script>
                            function previewImage(event) {
                                const output = document.getElementById('imagePreview');
                                output.src = URL.createObjectURL(event.target.files[0]);
                                output.style.display = 'block';
                            }
                        </script>

                        
                        <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
                        <script>
                            $(document).ready(function() {
                                $('#tag_id').change(function() {
                                    if ($(this).val().includes('other')) {
                                        $('#manual_tag_container').show();
                                    } else {
                                        $('#manual_tag_container').hide();
                                    }
                                });

                                $('#add_tag_button').click(function() {
                                    var newTag = $('#manual_tag_input').val();
                                    if (newTag.trim()) {
                                        $.ajax({
                                            url: '<?php echo e(route('tags.store')); ?>',
                                            method: 'POST',
                                            data: {
                                                name: newTag,
                                                _token: '<?php echo e(csrf_token()); ?>'
                                            },
                                            success: function(response) {
                                                if (response.success) {
                                                    $('#tag_id').append('<option value="' + response.tag.id + '" selected>' + response.tag.name + '</option>');
                                                    $('#manual_tag_input').val('');
                                                    $('#manual_tag_container').hide();
                                                }
                                            },
                                            error: function() {
                                                alert('Failed to add tag');
                                            }
                                        });
                                    }
                                });
                            });
                        </script>

                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- CKEditor 5 CDN -->
<script src="https://cdn.ckeditor.com/ckeditor5/39.0.1/classic/ckeditor.js"></script>

<script>
    ClassicEditor
        .create(document.querySelector('#editor'), {
            toolbar: {
                items: [
                    'heading', '|',
                    'bold', 'italic', 'link', 'bulletedList', 'numberedList', '|',
                    'codeBlock', 'undo', 'redo'
                ]
            },
            codeBlock: {
                languages: [
                    { language: 'plaintext', label: 'Plain text' },
                    { language: 'javascript', label: 'JavaScript' },
                    { language: 'php', label: 'PHP' },
                    { language: 'html', label: 'HTML' },
                    { language: 'css', label: 'CSS' }
                ]
            },
            heading: {
                options: [
                    { model: 'paragraph', title: 'Paragraph', class: 'ck-heading_paragraph' },
                    { model: 'heading1', view: 'h1', title: 'Heading 1', class: 'ck-heading_heading1' },
                    { model: 'heading2', view: 'h2', title: 'Heading 2', class: 'ck-heading_heading2' },
                    { model: 'heading3', view: 'h3', title: 'Heading 3', class: 'ck-heading_heading3' }
                ]
            }
        })
        .catch(error => {
            console.error('CKEditor error:', error);
        });
</script>

<?php $__env->stopSection(); ?>
<?php echo $__env->make('admin.layouts.main', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/ewx7upyjsani/public_html/androidwale.com/resources/views/admin/blogs/create.blade.php ENDPATH**/ ?>