<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
  <!-- Content Header (Page header) -->
  <section class="content-header">
    <h1>
      Gérer les
      <small>Motos</small>
    </h1>
    <ol class="breadcrumb">
      <li><a href="#"><i class="fa fa-dashboard"></i> Accueil</a></li>
      <li class="active">Motos</li>
    </ol>
  </section>

  <!-- Main content -->
  <section class="content">
    <!-- Small boxes (Stat box) -->
    <div class="row">
      <div class="col-md-12 col-xs-12">

        <div id="messages"></div>

        <?php if (session()->getFlashdata('success')): ?>
          <div class="alert alert-success alert-dismissible" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <?php echo session()->getFlashdata('success'); ?>
          </div>
        <?php elseif (session()->getFlashdata('error')): ?>
          <div class="alert alert-error alert-dismissible" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <?php echo session()->getFlashdata('error'); ?>
          </div>
        <?php endif; ?>


        <div class="box">
          <div class="box-header">
            <h3 class="box-title">Ajouter une Moto</h3>
          </div>
          <!-- /.box-header -->
          <form role="form" action="<?php base_url('create') ?>" method="post" enctype="multipart/form-data">
            <?php if (isset($validation) && $validation->getErrors()) : ?>
              <div class="alert alert-danger">
                <ul>
                  <?= $validation->listErrors() ?>
                </ul>
              </div>

            <?php endif; ?>
            <div class="box-body">

              <!-- validation -->
              <div class="form-group">

                <label for="product_image">Image</label>
                <div class="kv-avatar">
                  <div class="file-loading">
                    <input id="product_image" name="product_image" type="file" accept="image/*">
                  </div>
                </div>
              </div>

              <div class="form-group">
                <label for="product_name">Nom de Moto</label>
                <input type="text" class="form-control" id="product_name" name="nom_de_produit" placeholder="Nom de produit" autocomplete="off" />
              </div>

              <div class="form-group">
                <label for="sku">Numéro de série</label>
                <input type="text" class="form-control" id="sku" name="numero_de_serie" placeholder="Numéro de série" autocomplete="off" />
              </div>

              <div class="form-group">
                <label for="moteur">Numéro de moteur</label>
                <input type="text" class="form-control" id="moteur" name="numero_de_moteur" placeholder="Numéro de série" autocomplete="off" />
              </div>

              <div class="form-group">
                <label for="price">Prix d'Achat</label>
                <input type="text" class="form-control" id="price" name="prix" placeholder="Prix d'achat" autocomplete="off" />
              </div>
              <div class="form-group">
                <label for="price_vente">Prix de Vente</label>
                <input type="text" class="form-control" id="price_vente" name="price_vente" placeholder="Prix de vente" autocomplete="off" />
              </div>

              <div class="form-group">
                <label for="qty">Quantiter</label>
                <input type="text" class="form-control" id="qty" name="quantiter" placeholder="Quantiter" autocomplete="off" />
              </div>

              <div class="form-group">
                <label for="datea">Date d'arrivage</label>
                <input type="date" class="form-control" id="datea" name="datea" autocomplete="off" />
              </div>

              <div class="form-group">
                <label for="puissance">Puissances</label>
                <input type="text" class="form-control" id="puissance" name="puissance" placeholder="Puissances" autocomplete="off" />
              </div>

              <div class="form-group">
                <label for="cler">Clé</label>
                <input type="text" class="form-control" id="cler" name="cler" placeholder="Type de clé" autocomplete="off" />
              </div>

              <div class="form-group">
                <label for="description">Description</label>
                <textarea type="text" class="form-control" id="description" name="description" placeholder="Description" autocomplete="off">
                  </textarea>
              </div>

              <?php if ($attributes): ?>
                <?php foreach ($attributes as $k => $v): ?>
                  <div class="form-group">
                    <label for="groups"><?php echo $v['attribute_data']['name'] ?></label>
                    <select class="form-control select_group" id="attributes_value_id" name="attributes_value_id[]" multiple="multiple">
                      <?php foreach ($v['attribute_value'] as $k2 => $v2): ?>
                        <option value="<?php echo $v2['id'] ?>"><?php echo $v2['value'] ?></option>
                      <?php endforeach ?>
                    </select>
                  </div>
                <?php endforeach ?>
              <?php endif; ?>

              <div class="form-group">
                <label for="brands">Marques</label>
                <select class="form-control select_group" id="brands" name="brands[]" multiple="multiple">
                  <?php foreach ($brands as $k => $v): ?>
                    <option value="<?php echo $v['id'] ?>"><?php echo $v['name'] ?></option>
                  <?php endforeach ?>
                </select>
              </div>

              <div class="form-group">
                <label for="category">Categories</label>
                <select class="form-control select_group" id="category" name="category[]" multiple="multiple">
                  <?php foreach ($category as $k => $v): ?>
                    <option value="<?php echo $v['id'] ?>"><?php echo $v['name'] ?></option>
                  <?php endforeach ?>
                </select>
              </div>

              <div class="form-group">
                <label for="store">Magasin (lieu de réception)</label>
                <select class="form-control select_group" id="store" name="store">
                  <?php foreach ($stores as $k => $v): ?>
                    <option value="<?php echo $v['id'] ?>"><?php echo $v['name'] ?></option>
                  <?php endforeach ?>
                </select>
              </div>

              <div class="form-group">
                <label for="store">Disponibilité</label>
                <select class="form-control" id="availability" name="availability">
                  <option value="1">Oui</option>
                  <option value="2">Non</option>
                </select>
              </div>

            </div>
            <!-- /.box-body -->

            <div class="box-footer">
              <button type="submit" class="btn btn-primary">Enregistrer</button>
              <a href="<?php echo base_url('products/') ?>" class="btn btn-warning">Retour</a>
            </div>
          </form>
          <!-- /.box-body -->
        </div>
        <!-- /.box -->
      </div>
      <!-- col-md-12 -->
    </div>
    <!-- /.row -->


  </section>
  <!-- /.content -->
</div>
<!-- /.content-wrapper -->

<script type="text/javascript">
  $(document).ready(function() {
    $(".select_group").select2();
    $("#description").wysihtml5();

    $("#mainProductNav").addClass('active');
    $("#addProductNav").addClass('active');

    var btnCust = '<button type="button" class="btn btn-secondary" title="Add picture tags" ' +
      'onclick="alert(\'Call your custom code here.\')">' +
      '<i class="glyphicon glyphicon-tag"></i>' +
      '</button>';
    $("#product_image").fileinput({
      overwriteInitial: true,
      maxFileSize: 6500,
      showClose: false,
      showCaption: false,
      browseLabel: '',
      removeLabel: '',
      browseIcon: '<i class="glyphicon glyphicon-folder-open"></i>',
      removeIcon: '<i class="glyphicon glyphicon-remove"></i>',
      removeTitle: 'Cancel or reset changes',
      elErrorContainer: '#kv-avatar-errors-1',
      msgErrorClass: 'alert alert-block alert-danger',
      // defaultPreviewContent: '<img src="/uploads/default_avatar_male.jpg" alt="Your Avatar">',
      layoutTemplates: {
        main2: '{preview} ' + btnCust + ' {remove} {browse}'
      },
      allowedFileExtensions: ["jpg", "png", "gif", "jpeg"]
    });

  });
</script>