<?php $__env->startSection('header', 'Create Blog Post'); ?>
<?php $__env->startSection('content'); ?>
<div class="bg-white rounded shadow p-6">
    <form action="<?php echo e(route('admin.blogs.store')); ?>" method="POST" enctype="multipart/form-data">
        <?php echo csrf_field(); ?>
        <div class="grid grid-cols-1 gap-6">
            <div>
                <label class="block text-sm font-medium text-gray-700">Title</label>
                <input type="text" name="title" value="<?php echo e(old('title')); ?>" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-teal-500 focus:ring-teal-500" required>
            </div>
            
            <div>
                <label class="block text-sm font-medium text-gray-700">Slug (Optional - will be generated from title if left blank)</label>
                <input type="text" name="slug" value="<?php echo e(old('slug')); ?>" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-teal-500 focus:ring-teal-500">
            </div>

            <div>
                <label class="block text-sm font-medium text-gray-700">Meta Description (For SEO)</label>
                <textarea name="meta_description" rows="2" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-teal-500 focus:ring-teal-500" placeholder="A short description for search engines..."><?php echo e(old('meta_description')); ?></textarea>
            </div>

            <div>
                <label class="block text-sm font-medium text-gray-700">Featured Image</label>
                <input type="file" name="image" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-teal-500 focus:ring-teal-500">
            </div>

            <div>
                <label class="block text-sm font-medium text-gray-700 mb-2">Content</label>
                <textarea name="content" id="blog-content" rows="15" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-teal-500 focus:ring-teal-500"><?php echo e(old('content')); ?></textarea>
            </div>

            <div class="flex items-center mt-2">
                <input type="checkbox" name="is_published" id="is_published" value="1" class="rounded border-gray-300 text-teal-600 shadow-sm focus:border-teal-300 focus:ring focus:ring-teal-200 focus:ring-opacity-50" <?php echo e(old('is_published', true) ? 'checked' : ''); ?>>
                <label for="is_published" class="ml-2 block text-sm text-gray-900">Publish immediately</label>
            </div>
        </div>
        
        <div class="mt-6 flex justify-end">
            <a href="<?php echo e(route('admin.blogs.index')); ?>" class="bg-gray-200 text-gray-700 px-4 py-2 rounded mr-2">Cancel</a>
            <button type="submit" class="bg-teal-600 text-white px-4 py-2 rounded shadow">Save Blog Post</button>
        </div>
    </form>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tinymce/6.8.3/tinymce.min.js" referrerpolicy="origin"></script>
<script>
    tinymce.init({
        selector: '#blog-content',
        plugins: 'anchor autolink charmap codesample emoticons image link lists media searchreplace table visualblocks wordcount',
        toolbar: 'undo redo | blocks fontfamily fontsize | bold italic underline strikethrough | link image media table | align lineheight | numlist bullist indent outdent | emoticons charmap | removeformat',
        menubar: false,
        height: 500,
        image_title: true,
        automatic_uploads: true,
        file_picker_types: 'image',
        file_picker_callback: (cb, value, meta) => {
            const input = document.createElement('input');
            input.setAttribute('type', 'file');
            input.setAttribute('accept', 'image/*');
            input.addEventListener('change', (e) => {
                const file = e.target.files[0];
                const reader = new FileReader();
                reader.addEventListener('load', () => {
                    const id = 'blobid' + (new Date()).getTime();
                    const blobCache =  tinymce.activeEditor.editorUpload.blobCache;
                    const base64 = reader.result.split(',')[1];
                    const blobInfo = blobCache.create(id, file, base64);
                    blobCache.add(blobInfo);
                    cb(blobInfo.blobUri(), { title: file.name });
                });
                reader.readAsDataURL(file);
            });
            input.click();
        },
        images_upload_handler: (blobInfo, progress) => new Promise((resolve, reject) => {
            const formData = new FormData();
            formData.append('file', blobInfo.blob(), blobInfo.filename());
            
            fetch('<?php echo e(route('admin.upload.image')); ?>', {
                method: 'POST',
                headers: {
                    'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').getAttribute('content')
                },
                body: formData
            })
            .then(response => {
                if (!response.ok) throw new Error('HTTP Error: ' + response.status);
                return response.json();
            })
            .then(json => {
                if (!json || typeof json.location != 'string') throw new Error('Invalid JSON');
                resolve(json.location);
            })
            .catch(error => reject(error.message));
        })
    });
</script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('layouts.admin', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /Users/sumankc/Desktop/ Websites/Dr Rajan/resources/views/admin/blogs/create.blade.php ENDPATH**/ ?>