<?= $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 State</h1>
      </div>
      <div class="col-sm-6">
        <ol class="breadcrumb float-sm-right">
          <li class="breadcrumb-item"><a href="<?php echo url('/') ?>">Home</a></li>
          <li class="breadcrumb-item"><a href="<?php echo url('states') ?>">States</a></li>
          <li class="breadcrumb-item active">Edit</li>
        </ol>
      </div>
    </div>
  </div>
</section>

<section class="content">
<?php echo form_open('states/update/'.$state->id, ['class' => 'form-validate', 'autocomplete' => 'off']); ?>
  <div class="card">
    <div class="card-body">
      <div class="form-group">
        <label>Country</label>
        <select class="form-control select2" name="country_id" required>
          <option value="">Select</option>
          <?php foreach ($countries as $c): ?>
            <?php $sel = (int) $state->country_id === (int) $c->id ? 'selected' : '' ?>
            <option value="<?php echo $c->id ?>" <?php echo $sel ?>><?php echo esc($c->name) ?></option>
          <?php endforeach ?>
        </select>
      </div>
      <div class="form-row">
        <div class="form-group col-md-6">
          <label>Name</label>
          <input type="text" class="form-control" name="name" value="<?php echo esc($state->name) ?>" required>
        </div>
        <div class="form-group col-md-6">
          <label>Status</label>
          <select class="form-control" name="status">
            <option value="1" <?php echo $state->status ? 'selected' : '' ?>>Active</option>
            <option value="0" <?php echo !$state->status ? 'selected' : '' ?>>Inactive</option>
          </select>
        </div>
      </div>
    </div>
    <div class="card-footer">
      <div class="row">
        <div class="col"><a href="<?php echo url('states') ?>" 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() ?>

