<?php $__env->startSection('title', 'Upload Media'); ?>

<?php $__env->startSection('content'); ?>
<div class="max-w-2xl mx-auto">
    <div class="flex items-center gap-3 mb-6">
        <a href="<?php echo e(route('admin.media.index', ['mediable_type' => request('mediable_type'), 'mediable_id' => request('mediable_id')])); ?>" class="text-gray-400 hover:text-gray-600 transition">
            <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18"/></svg>
        </a>
        <div>
            <h1 class="text-2xl font-bold text-gray-900">Upload Media</h1>
            <p class="text-sm text-gray-500">Add files to your media library</p>
        </div>
    </div>

    <div class="bg-white border rounded-xl shadow-sm">
        <form method="POST" action="<?php echo e(route('admin.media.store')); ?>" enctype="multipart/form-data" id="uploadForm">
            <?php echo csrf_field(); ?>

            <?php if($mediable): ?>
                <input type="hidden" name="mediable_type" value="<?php echo e($mediableType); ?>">
                <input type="hidden" name="mediable_id" value="<?php echo e($mediableId); ?>">
                <div class="px-6 pt-5">
                    <div class="flex items-center gap-2 px-4 py-3 bg-blue-50 border border-blue-200 rounded-lg text-sm text-blue-700">
                        <svg class="w-4 h-4 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>
                        Attaching to <strong><?php echo e(class_basename($mediableType)); ?></strong>: <?php echo e(method_exists($mediable, 'name') ? $mediable->name : "#{$mediable->id}"); ?>

                    </div>
                </div>
            <?php endif; ?>

            <div class="p-6 space-y-6">
                <?php if(!$mediable): ?>
                    <div class="grid grid-cols-2 gap-4">
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-1.5">Attach To</label>
                            <select name="mediable_type" id="mediable_type" required onchange="toggleEntityId()"
                                class="w-full border border-gray-300 rounded-lg px-3 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
                                <option value="">Select entity type</option>
                                <option value="Modules\Product\Models\Product" <?php echo e(old('mediable_type') === 'Modules\Product\Models\Product' ? 'selected' : ''); ?>>Product</option>
                                <option value="Modules\Category\Models\Category" <?php echo e(old('mediable_type') === 'Modules\Category\Models\Category' ? 'selected' : ''); ?>>Category</option>
                                <option value="Modules\Section\Models\Section" <?php echo e(old('mediable_type') === 'Modules\Section\Models\Section' ? 'selected' : ''); ?>>Section</option>
                            </select>
                            <?php $__errorArgs = ['mediable_type'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <p class="text-red-500 text-sm mt-1"><?php echo e($message); ?></p> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                        </div>
                        <div>
                            <label for="mediable_id" class="block text-sm font-medium text-gray-700 mb-1.5">Entity ID</label>
                            <input type="number" name="mediable_id" id="mediable_id" value="<?php echo e(old('mediable_id')); ?>" required
                                class="w-full border border-gray-300 rounded-lg px-3 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
                            <?php $__errorArgs = ['mediable_id'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <p class="text-red-500 text-sm mt-1"><?php echo e($message); ?></p> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                        </div>
                    </div>
                <?php endif; ?>

                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1.5">File Type</label>
                    <div class="grid grid-cols-3 gap-3" id="typeSelector">
                        <label class="relative">
                            <input type="radio" name="type" value="image" <?php echo e(old('type', 'image') === 'image' ? 'checked' : ''); ?> class="sr-only peer">
                            <div class="flex flex-col items-center gap-2 p-4 border-2 rounded-xl cursor-pointer peer-checked:border-blue-500 peer-checked:bg-blue-50 border-gray-200 hover:border-gray-300 transition">
                                <svg class="w-8 h-8 text-blue-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"/></svg>
                                <span class="text-sm font-medium text-gray-700">Image</span>
                            </div>
                        </label>
                        <label class="relative">
                            <input type="radio" name="type" value="video" <?php echo e(old('type') === 'video' ? 'checked' : ''); ?> class="sr-only peer">
                            <div class="flex flex-col items-center gap-2 p-4 border-2 rounded-xl cursor-pointer peer-checked:border-purple-500 peer-checked:bg-purple-50 border-gray-200 hover:border-gray-300 transition">
                                <svg class="w-8 h-8 text-purple-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664zM21 12a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>
                                <span class="text-sm font-medium text-gray-700">Video</span>
                            </div>
                        </label>
                        <label class="relative">
                            <input type="radio" name="type" value="file" <?php echo e(old('type') === 'file' ? 'checked' : ''); ?> class="sr-only peer">
                            <div class="flex flex-col items-center gap-2 p-4 border-2 rounded-xl cursor-pointer peer-checked:border-gray-500 peer-checked:bg-gray-50 border-gray-200 hover:border-gray-300 transition">
                                <svg class="w-8 h-8 text-gray-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z"/></svg>
                                <span class="text-sm font-medium text-gray-700">File</span>
                            </div>
                        </label>
                    </div>
                    <?php $__errorArgs = ['type'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <p class="text-red-500 text-sm mt-1"><?php echo e($message); ?></p> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                </div>

                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1.5">Choose File</label>
                    <div id="dropZone" class="relative border-2 border-dashed border-gray-300 rounded-xl p-10 text-center hover:border-blue-400 hover:bg-blue-50/30 transition cursor-pointer">
                        <input type="file" name="file" id="fileInput" required class="absolute inset-0 w-full h-full opacity-0 cursor-pointer">
                        <div id="dropContent">
                            <svg class="w-12 h-12 mx-auto text-gray-300" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12"/></svg>
                            <p class="mt-3 text-sm text-gray-600"><span class="font-medium text-blue-600">Click to upload</span> or drag and drop</p>
                            <p class="text-xs text-gray-400 mt-1">Max file size: 100MB</p>
                            <p id="fileSelected" class="mt-3 text-sm text-green-600 font-medium hidden"></p>
                        </div>
                    </div>
                    <?php $__errorArgs = ['file'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <p class="text-red-500 text-sm mt-1"><?php echo e($message); ?></p> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                </div>
            </div>

            <div class="px-6 py-4 border-t bg-gray-50 rounded-b-xl flex items-center justify-between">
                <p class="text-xs text-gray-400">Supported formats depend on file type selection</p>
                <div class="flex gap-3">
                    <a href="<?php echo e(route('admin.media.index', ['mediable_type' => request('mediable_type'), 'mediable_id' => request('mediable_id')])); ?>" class="px-5 py-2.5 border border-gray-300 rounded-lg text-sm font-medium text-gray-700 hover:bg-gray-50 transition">Cancel</a>
                    <button type="submit" class="px-5 py-2.5 bg-blue-600 text-white rounded-lg text-sm font-medium hover:bg-blue-700 transition shadow-sm">Upload</button>
                </div>
            </div>
        </form>
    </div>
</div>

<script>
function toggleEntityId() {
    const t = document.getElementById('mediable_type');
    const id = document.getElementById('mediable_id');
    id.disabled = !t.value;
    if (!t.value) id.value = '';
}

const dropZone = document.getElementById('dropZone');
const fileInput = document.getElementById('fileInput');
const fileSelected = document.getElementById('fileSelected');
const dropContent = document.getElementById('dropContent');

['dragenter', 'dragover'].forEach(e => {
    dropZone.addEventListener(e, (ev) => {
        ev.preventDefault();
        dropZone.classList.add('border-blue-500', 'bg-blue-50');
    });
});
['dragleave', 'drop'].forEach(e => {
    dropZone.addEventListener(e, (ev) => {
        ev.preventDefault();
        dropZone.classList.remove('border-blue-500', 'bg-blue-50');
    });
});
dropZone.addEventListener('drop', (ev) => {
    if (ev.dataTransfer.files.length) {
        fileInput.files = ev.dataTransfer.files;
        showFile(ev.dataTransfer.files[0]);
    }
});
fileInput.addEventListener('change', () => {
    if (fileInput.files.length) showFile(fileInput.files[0]);
});
function showFile(f) {
    fileSelected.classList.remove('hidden');
    fileSelected.textContent = 'Selected: ' + f.name + ' (' + (f.size / 1024).toFixed(1) + ' KB)';
    document.querySelector('#dropContent svg').outerHTML = '<svg class="w-12 h-12 mx-auto text-green-400" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>';
}
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('admin::layouts.master', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH G:\abo bilal nuisan\bernie_store\bernie-backend\Modules/Admin\resources/views/media/create.blade.php ENDPATH**/ ?>