<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title><?php echo e(isset($product) ? 'Edit Product' : 'Add Product'); ?> | Admin Panel</title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
  <style>
    body { background-color: #f8f9fa; font-family: 'Poppins', sans-serif; }
    .sidebar { height: 100vh; background: #0d6efd; color: #fff; position: fixed; width: 230px; top: 0; left: 0; padding-top: 70px; }
    .sidebar a { color: #e4e4e4; display: block; padding: 12px 20px; text-decoration: none; }
    .sidebar a:hover, .sidebar a.active { background: #084298; border-left: 4px solid #ffc107; }
    .content { margin-left: 240px; padding: 30px; margin-top: 80px; }
    .navbar { background-color: #fff !important; border-bottom: 1px solid #e3e3e3; }
    .form-label { font-weight: 500; }
    .card { border-radius: 12px; box-shadow: 0 2px 6px rgba(0,0,0,0.05); border: none; }
    .product-img-preview { width: 120px; height: 120px; object-fit: cover; border-radius: 8px; }
  </style>
</head>
<body>

<nav class="navbar navbar-expand-lg fixed-top shadow-sm">
  <div class="container-fluid">
    <a class="navbar-brand fw-semibold text-primary" href="#">🛍️ Admin Panel</a>
    <div class="d-flex">
      <span class="me-3 text-muted"><?php echo e(auth()->user()->name); ?></span>
      <form method="POST" action="<?php echo e(route('admin.logout')); ?>">
        <?php echo csrf_field(); ?>
        <button type="submit" class="btn btn-outline-danger btn-sm">Logout</button>
      </form>
    </div>
  </div>
</nav>

<div class="sidebar">
  <a href="<?php echo e(route('admin.dashboard')); ?>">🏠 Dashboard</a>
  <a href="<?php echo e(route('admin.products')); ?>" class="active">📦 Products</a>
  <a href="<?php echo e(route('admin.categories')); ?>">🗂 Categories</a>
  <a href="<?php echo e(route('admin.orders')); ?>">🧾 Orders</a>
  <a href="<?php echo e(route('admin.coupons')); ?>">🏷 Coupons</a>
  <a href="<?php echo e(route('admin.settings')); ?>">⚙ Settings</a>
</div>

<div class="content">
  <div class="container-fluid">
    <div class="d-flex justify-content-between align-items-center mb-4">
      <h3 class="fw-bold mb-0"><?php echo e(isset($product) ? 'Edit Product' : 'Add Product'); ?></h3>
      <a href="<?php echo e(route('admin.products')); ?>" class="btn btn-secondary">← Back to Products</a>
    </div>

    <?php if($errors->any()): ?>
      <div class="alert alert-danger">
        <ul class="mb-0">
          <?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; ?>

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

    <div class="card p-4">
      <form 
        action="<?php echo e(isset($product) ? route('admin.product.save', $product->id) : route('admin.product.save')); ?>" 
        method="POST" 
        enctype="multipart/form-data">
        <?php echo csrf_field(); ?>

        <div class="row">
          <div class="col-md-6 mb-3">
            <label class="form-label">Product Name</label>
            <input type="text" name="name" value="<?php echo e(old('name', $product->name ?? '')); ?>" class="form-control" required>
          </div>

          <div class="col-md-6 mb-3">
            <label class="form-label">Category</label>
            <select name="category_id" class="form-select">
              <option value="">-- Select Category --</option>
              <?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $cat): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <option value="<?php echo e($cat->id); ?>" 
                  <?php echo e(old('category_id', $product->category_id ?? '') == $cat->id ? 'selected' : ''); ?>>
                  <?php echo e($cat->name); ?>

                </option>
              <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </select>
          </div>

          <div class="col-md-4 mb-3">
            <label class="form-label">Price (₹)</label>
            <input type="number" step="0.01" name="price" value="<?php echo e(old('price', $product->price ?? '')); ?>" class="form-control" required>
          </div>

          <div class="col-md-4 mb-3">
            <label class="form-label">Special Price (₹)</label>
            <input type="number" step="0.01" name="special_price" value="<?php echo e(old('special_price', $product->special_price ?? '')); ?>" class="form-control">
          </div>

          <div class="col-md-4 mb-3">
            <label class="form-label">Stock Quantity</label>
            <input type="number" name="stock" value="<?php echo e(old('stock', $product->stock ?? 0)); ?>" class="form-control" required>
          </div>

          <div class="col-md-12 mb-3">
            <label class="form-label">Short Description</label>
            <textarea name="short_description" rows="2" class="form-control"><?php echo e(old('short_description', $product->short_description ?? '')); ?></textarea>
          </div>

          <div class="col-md-12 mb-3">
            <label class="form-label">Detailed Description</label>
            <textarea name="description" rows="5" class="form-control"><?php echo e(old('description', $product->description ?? '')); ?></textarea>
          </div>

      <div class="col-md-6 mb-3">
  <label class="form-label">Main Image</label>
  <input type="file" name="image" class="form-control">

  <?php if(isset($product) && $product->image): ?>
    <div class="mt-2">
      <img src="<?php echo e(asset('storage/'.$product->image)); ?>" class="product-img-preview border" alt="Main Image">
    </div>
  <?php endif; ?>
</div>

<div class="col-md-6 mb-3">
  <label class="form-label">Gallery Images</label>
  <input type="file" name="gallery[]" class="form-control" multiple>

  <?php if(isset($product) && !empty($product->gallery)): ?>
    <div class="d-flex flex-wrap gap-3 mt-2">
      <?php $__currentLoopData = $product->gallery; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $img): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
        <img src="<?php echo e(asset('storage/'.$img)); ?>" class="product-img-preview border" alt="Gallery Image">
      <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
    </div>
  <?php endif; ?>
</div>


          <div class="col-md-6 mb-3">
            <label class="form-label">Status</label>
            <select name="is_active" class="form-select">
              <option value="1" <?php echo e(old('is_active', $product->is_active ?? 1) == 1 ? 'selected' : ''); ?>>Active</option>
              <option value="0" <?php echo e(old('is_active', $product->is_active ?? 1) == 0 ? 'selected' : ''); ?>>Inactive</option>
            </select>
          </div>
        </div>

        <div class="mt-3">
          <button type="submit" class="btn btn-success px-4">
            <?php echo e(isset($product) ? 'Update Product' : 'Add Product'); ?>

          </button>
          <a href="<?php echo e(route('admin.products')); ?>" class="btn btn-outline-secondary px-4">Cancel</a>
        </div>
      </form>
    </div>
  </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
<?php /**PATH /home2/jitrealx/public_html/track/resources/views/admin/products/form.blade.php ENDPATH**/ ?>