<?= $this->extend('admin/layout/default') ?>
<?= $this->section('content') ?>

<section class="content-header">
  <div class="container-fluid">
    <div class="row mb-2">
      <div class="col-sm-6">
        <h1>Edit Service Category</h1>
      </div>
    </div>
  </div>
</section>

<section class="content">
<?php echo form_open('rewarderServiceCategories/update/'.$category->id, ['class' => 'form-validate', 'autocomplete' => 'off', 'enctype' => 'multipart/form-data']); ?>
  <div class="card">
    <div class="card-body">
      <div class="form-group">
        <label>Shop</label>
        <select name="shop_id" class="form-control select2" required>
          <?php foreach ($shops as $s): ?>
            <?php $sel = (int) $category->shop_id === (int) $s->id ? 'selected' : '' ?>
            <option value="<?php echo $s->id ?>" <?php echo $sel ?>><?php echo esc($s->name) ?></option>
          <?php endforeach ?>
        </select>
      </div>
      <div class="form-group">
        <label>Name</label>
        <input type="text" class="form-control" name="name" value="<?php echo esc($category->name) ?>" required autofocus>
      </div>
      <div class="form-group">
        <label>Status</label>
        <select name="status" class="form-control">
          <option value="1" <?php echo $category->status ? 'selected' : '' ?>>Active</option>
          <option value="0" <?php echo !$category->status ? 'selected' : '' ?>>Inactive</option>
        </select>
      </div>
      <div class="form-group">
        <label>Image</label>
        <input type="file" class="form-control" name="image" accept="image/*">
        <?php if (!empty($category->img_type)): ?>
          <div class="mt-2">
            <img src="<?php echo urlUpload('service_categories/'.$category->id.'.'.$category->img_type, true) ?>" style="max-height: 80px;">
          </div>
        <?php endif ?>
      </div>
    </div>
    <div class="card-footer">
      <div class="row">
        <div class="col"><a href="<?php echo url('rewarderServiceCategories') ?>" class="btn btn-flat btn-danger" onclick="return confirm('Leave without saving?')">Cancel</a></div>
        <div class="col text-right"><button type="submit" class="btn btn-flat btn-primary">Save</button></div>
      </div>
    </div>
  </div>
<?php echo form_close(); ?>
</section>

<?= $this->endSection() ?>
<?= $this->section('js') ?>
<script>
  $(document).ready(function() {
    $('.form-validate').validate();
    $('.select2').select2();
  });
</script>
<?= $this->endSection() ?>

