
<?php $__env->startSection('title', $mode === 'create' ? 'Add Banner' : 'Edit Banner #'.$banner->id); ?>

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

<link rel="stylesheet"
      href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css"
      integrity="sha512-DTOQO9RWCH3ppGqcWaEA1BIZOC6xxalwEsw9c2QQeAIftl+Vegovlnee1c9QX4TctnWMn13TZye+giMm8e2LwA=="
      crossorigin="anonymous" referrerpolicy="no-referrer" />

<style>
    :root{--bg:#f5f5f5;--ink:#111827;--muted:#6b7280;}
    body{background:var(--bg);}
    .page-wrap{max-width:800px;margin:20px auto 60px;padding:0 12px;}
    .card-main{
        background:#fff;border-radius:18px;padding:16px 16px 20px;
        box-shadow:0 12px 32px rgba(15,23,42,.10);border:1px solid #e5e7eb;
    }
    .title{font-size:18px;font-weight:700;color:var(--ink);}
    .subtitle{font-size:13px;color:var(--muted);}
    .banner-preview{
        width:100%;max-height:180px;border-radius:10px;overflow:hidden;
        background:#f3f4f6;display:flex;align-items:center;justify-content:center;
        margin-top:8px;border:1px dashed #e5e7eb;
    }
    .banner-preview img{width:100%;height:100%;object-fit:cover;}
</style>

<div class="page-wrap">
    <div class="mb-2">
        <a href="<?php echo e(route('admin.banners.index')); ?>" class="btn btn-sm btn-outline-secondary">
            <i class="fa-solid fa-arrow-left"></i> Back to banners
        </a>
    </div>

    <?php if(session('success')): ?>
        <div class="alert alert-success py-2"><?php echo e(session('success')); ?></div>
    <?php endif; ?>

    <div class="card-main">
        <div class="mb-3">
            <div class="title">
                <i class="fa-solid fa-image"></i>
                <?php echo e($mode === 'create' ? 'Add New Banner' : 'Edit Banner #'.$banner->id); ?>

            </div>
            <div class="subtitle">
                Banner image, title, button text/url, order এবং status manage করতে পারবেন।
            </div>
        </div>

        <form
            action="<?php echo e($mode === 'create'
                        ? route('admin.banners.store')
                        : route('admin.banners.update', $banner)); ?>"
            method="POST"
            enctype="multipart/form-data">
            <?php echo csrf_field(); ?>
            <?php if($mode === 'edit'): ?>
                <?php echo method_field('PUT'); ?>
            <?php endif; ?>

            <div class="mb-3">
                <label class="form-label">Title (optional)</label>
                <input type="text"
                       name="title"
                       value="<?php echo e(old('title', $banner->title)); ?>"
                       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); ?>">
                <?php $__errorArgs = ['title'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?><div class="invalid-feedback"><?php echo e($message); ?></div><?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
            </div>

            
            <div class="mb-3">
                <label class="form-label">Banner Image <?php if($mode === 'create'): ?> * <?php endif; ?></label>
                <input type="file"
                       name="image"
                       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); ?>"
                       accept="image/*"
                       <?php if($mode==='create'): ?> required <?php endif; ?>>
                <?php $__errorArgs = ['image'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?><div class="invalid-feedback"><?php echo e($message); ?></div><?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                <div class="form-text">Recommended: 1200×400px (or similar ratio)</div>

                <div class="banner-preview" id="bannerPreview">
                    <?php if($banner->image): ?>
                        <img src="<?php echo e(asset('storage/'.$banner->image)); ?>" alt="">
                    <?php else: ?>
                        <span style="font-size:12px;color:#9ca3af;">No image selected</span>
                    <?php endif; ?>
                </div>
            </div>

            
            <div class="row g-3">
                <div class="col-md-4">
                    <label class="form-label">Button text</label>
                    <input type="text"
                           name="button_text"
                           value="<?php echo e(old('button_text', $banner->button_text)); ?>"
                           class="form-control <?php $__errorArgs = ['button_text'];
$__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); ?>">
                    <?php $__errorArgs = ['button_text'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?><div class="invalid-feedback"><?php echo e($message); ?></div><?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    <div class="form-text"> যেমন: "Apply Now"</div>
                </div>
                <div class="col-md-8">
                    <label class="form-label">Button URL</label>
                    <input type="text"
                           name="button_url"
                           value="<?php echo e(old('button_url', $banner->button_url)); ?>"
                           class="form-control <?php $__errorArgs = ['button_url'];
$__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); ?>">
                    <?php $__errorArgs = ['button_url'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?><div class="invalid-feedback"><?php echo e($message); ?></div><?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    <div class="form-text">Optional link (যদি banner এ ক্লিক করলে কোথাও যেতে চাও)</div>
                </div>
            </div>

            
            <div class="row g-3 mt-2">
                <div class="col-md-4">
                    <label class="form-label">Sort order</label>
                    <input type="number"
                           name="sort_order"
                           value="<?php echo e(old('sort_order', $banner->sort_order ?? 0)); ?>"
                           class="form-control <?php $__errorArgs = ['sort_order'];
$__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); ?>">
                    <?php $__errorArgs = ['sort_order'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?><div class="invalid-feedback"><?php echo e($message); ?></div><?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    <div class="form-text">নাম্বার যত ছোট হবে, তত আগে দেখাবে।</div>
                </div>
                <div class="col-md-4 d-flex align-items-end">
                    <div class="form-check">
                        <input type="checkbox"
                               name="status"
                               value="1"
                               id="statusCheck"
                               class="form-check-input"
                               <?php echo e(old('status', $banner->status ?? true) ? 'checked' : ''); ?>>
                        <label class="form-check-label" for="statusCheck">
                            Active (show on site)
                        </label>
                    </div>
                </div>
            </div>

            <div class="mt-3">
                <button class="btn btn-primary" type="submit">
                    <i class="fa-solid fa-floppy-disk"></i>
                    <?php echo e($mode === 'create' ? 'Create Banner' : 'Save changes'); ?>

                </button>
            </div>
        </form>
    </div>
</div>

<script>
    // ছোট preview JS
    document.querySelector('input[name="image"]')?.addEventListener('change', function(e){
        const file = e.target.files[0];
        if(!file) return;
        const reader = new FileReader();
        reader.onload = function(ev){
            const wrap = document.getElementById('bannerPreview');
            if(!wrap) return;
            wrap.innerHTML = '';
            const img = document.createElement('img');
            img.src = ev.target.result;
            wrap.appendChild(img);
        };
        reader.readAsDataURL(file);
    });
</script>

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

<?php echo $__env->make('backend.master', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/ecareba2/loan.rkmotorsbike.top/resources/views/backend/banners/form.blade.php ENDPATH**/ ?>