<?= $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</h1>
      </div>
    </div>
  </div>
</section>

<section class="content">
<?php echo form_open('rewarderServices/update/'.$service->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 id="shop_id" name="shop_id" class="form-control select2" required>
          <?php foreach ($shops as $s): ?>
            <?php $sel = (int) $service->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>Category</label>
        <select id="category_id" name="category_id" class="form-control select2">
          <option value="">None</option>
          <?php foreach ($categories as $c): ?>
            <?php $sel = (int) $service->category_id === (int) $c->id ? 'selected' : '' ?>
            <option value="<?php echo $c->id ?>" data-shop="<?php echo $c->shop_id ?>" <?php echo $sel ?>><?php echo esc($c->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($service->name) ?>" required autofocus>
      </div>
      <div class="form-group">
        <label>Image</label>
        <input type="file" class="form-control" name="image" accept="image/*">
        <?php if (!empty($service->img_type)): ?>
          <div class="mt-2">
            <img src="<?php echo urlUpload('services/'.$service->id.'.'.$service->img_type, true) ?>" style="max-height: 80px;">
          </div>
        <?php endif ?>
      </div>
      <div class="form-row">
        <div class="form-group col-md-6">
          <label>Price</label>
          <input type="number" step="0.01" class="form-control" name="price" value="<?php echo esc($service->price) ?>">
        </div>
        <div class="form-group col-md-6">
          <label>Status</label>
          <select name="status" class="form-control">
            <option value="1" <?php echo $service->status ? 'selected' : '' ?>>Active</option>
            <option value="0" <?php echo !$service->status ? 'selected' : '' ?>>Inactive</option>
          </select>
        </div>
      </div>
    </div>
    <div class="card-footer">
      <div class="row">
        <div class="col"><a href="<?php echo url('rewarderServices') ?>" 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') ?>
<?= $this->include('admin/rewarder/services/_form_js') ?>
<?= $this->endSection() ?>

