<?php
    $errors = $this->session->userdata('errors');
    if (isset($errors)) {
        ?>
        <script>
            swal ( "Oops" ,  "<?php echo $errors ?>" ,  "error" )
        </script>
        <?php echo $errors ?>
        <?php
        $this->session->unset_userdata('errors');
    }
    $error = $this->session->userdata('error');
    if (isset($error)) {
        ?>
         <script>
            swal ( "Oops" ,  "<?php echo $error ?>" ,  "error" )
        </script>
        <?php
        $this->session->unset_userdata('error');
    }
    $success = $this->session->userdata('success');
    if (isset($success)) {
        ?>
         <script>
            swal({
          title: "Done!",
          text: "<?php echo $success ?>",
          icon: "success",
        });
        </script>
        <?php
        $this->session->unset_userdata('success');
    }
    ?>
  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1>Slider</h1>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="<?php echo admin_url() ?>admin">Home</a></li>
              <li class="breadcrumb-item active">Slider</li>
            </ol>
          </div>
        </div>
      </div><!-- /.container-fluid -->
    </section>

    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <div class="row">

          <div class="col-sm-12">
            <div class="card card-default">
              <div class="card-header">
                <h4>View All Widget</h4>
                
              </div>
                <div class="card-body">
                  <table id="example" class="table table-bordered table-striped">
                    <thead>
                    <tr>
                      <th>id</th>
                      <th>Title</th>
                      <th>Order</th>
                      <th>Showing</th>
                      <th></th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php $i=1; foreach ($get_all_widget as $key => $widget):?>
                    <tr>
                      <td><?php echo $i ?></td>
                      <td><?php echo $widget->title ?></td>
                      <td><?php echo $widget->order_by ?></td>
                      <td><?php if($widget->showing == 1){echo 'Top';}else{echo 'Bottom';}  ?></td>
                      <td><a href="" class="btn btn-info btn-sm" data-toggle="modal" data-target="#update-widget<?php echo $widget->id ?>"><i class="fa fa-edit" aria-hidden="true"></i></a>
                        <a class="btn btn-danger btn-sm" onclick="return confirm('Are you sure?')" href="<?php echo base_url() ?>admin/widget/delete_widget/<?php echo $widget->id ?>"><i class="fa fa-trash" aria-hidden="true"></i></a></td>
                    </tr>
                    <?php $i++; ?>
                    <?php endforeach; ?>
                    </tbody>
                    
                  </table>
                </div>
              </div>
            </div>
          </div>
      </div>
    </section>
    <!-- /.content -->
  </div>
<?php $i=1; foreach ($get_all_widget as $key => $widget):?>
<div class="modal fade" id="update-widget<?php echo $widget->id ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Update Widget</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <?php echo form_open(base_url().'admin/widget/update_widget'); ?>
          
          <div class="col-md-12">
            <div class="form-group">
              <label>Widget Title <span class="required">*</span></label>
              <input type="text" name="title" class="form-control" placeholder="Enter Widget Title" required="" value="<?php echo $widget->title ?>">
            </div>
          </div>
          <div class="col-md-12">
            <div class="form-group">
              <label>Widget Content <span class="required">*</span></label>
              <textarea type="text" name="content" class="text-editor" placeholder="Enter Widget Title" required=""><?php echo $widget->content ?></textarea>
            </div>
          </div>
          <div class="col-md-12">
            <div class="form-group">
              <label>Widget Order <span class="required">*</span></label>
              <input type="text" name="order_by" class="form-control" placeholder="Enter Widget Order" required="" value="<?php echo $widget->order_by ?>">
            </div>
          </div>
          <div class="col-md-12">
            <div class="form-group">
              <label>Widget Position <span class="required">*</span></label>
              <select type="text" name="showing" class="form-control" placeholder="Enter Widget Order" required="">
                <option <?php if($widget->showing == 1){echo 'selected';} ?> value="1">Buttom</option>
                <option <?php if($widget->showing == 2){echo 'selected';} ?> value="2">Top</option>
              </select>
            </div>
          </div>
        <input type="hidden" name="id" class="form-control" value="<?php echo $widget->id ?>">
          
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="submit" class="btn btn-primary">Update</button>
      </div>
      <?php echo form_close(); ?>
    </div>
  </div>
</div>
<?php endforeach; ?>