 <?php 
use App\Models\HomeModel;

 ?>

 <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <div class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1 class="m-0 text-dark">Add Banner</h1>
          </div><!-- /.col -->
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="<?php echo base_url() ?>admin/admin/dashboard">Dashboard</a></li>
              <li class="breadcrumb-item"><a href="#">Home Setting</a></li>
              <li class="breadcrumb-item active">Add Banner</li>

            </ol>
          </div><!-- /.col -->
        </div><!-- /.row -->
      </div><!-- /.container-fluid -->
    </div>
    <!-- /.content-header -->
    <!-- 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">
                 <?php 
                  $home = new HomeModel();
                  $slider = $home->get_banner_by_position('Slider');
                  $exclusive = $home->get_banner_by_position('Exclusive Products');
                  $trending = $home->get_banner_by_position('Trending Products');
                  $b_exclusive = $home->get_banner_by_position('Below Exclusive Products');
                  $b_trending = $home->get_banner_by_position('Below Trending Products');
                  $header_top = $home->get_banner_by_position('Header Top');
                  ?>
                <h3 class="card-title">Add New Banner <span style="color:red"><?php if(count($slider) == 2 && count($exclusive) == 1 && count($trending) == 1 && count($b_exclusive) == 3 && count($b_trending) == 3 && count($header_top) == 1){echo 'All Banner Add Limit Complete';} ?></span></h3>

                <div class="card-tools">
                  <a href="<?php echo base_url()?>/admin/home_setting/all_banner" class="btn btn-primary btn-sm"><i class="fa fa-eye" aria-hidden="true"></i> View Banner</a>
                </div>
              </div>
              <!-- /.card-header -->
              <?php echo form_open_multipart('admin/home_setting/add_banner'); ?>
              <div class="card-body">
                <div class="row">
                  <div class="col-md-4">
                    <div class="form-group">
                       <label for="inputEmail" class="col-sm-12 col-form-label">Image Name <span class="required">*</span></label>
                       <div class="col-sm-12">
                          <input class="form-control"  name="banner_name" placeholder="Enter Image Name" required>
                       </div>
                    </div>
                  </div>
                  <div class="col-md-4">
                    <div class="form-group">
                       <label for="inputEmail" class="col-sm-12 col-form-label">Image URL <span class="required">*</span></label>
                       <div class="col-sm-12">
                          <input class="form-control"  name="banner_url" placeholder="Enter Image URL" required value="#">
                       </div>
                    </div>
                  </div>
                  <div class="col-md-4">
                    <div class="form-group">
                       <label for="inputEmail" class="col-sm-12 col-form-label">Image Position <span class="required">*</span></label>
                       <div class="col-sm-12">
                          <select class="form-control" name="banner_position" required onchange="check_size(this)">
                           
                              <option value="">Select Position</option>
                            <?php if(count($slider) <= 1): ?>
                              <option value="Slider">Slider</option>
                            <?php endif;?>
                            <?php if(count($exclusive) <= 0): ?>
                              <option value="Exclusive Products">Exclusive Products</option>
                            <?php endif;?>
                            <?php if(count($trending) <= 0): ?>
                              <option value="Trending Products">Trending Products</option>
                            <?php endif;?>
                            <?php if(count($b_exclusive) <= 2): ?>
                              <option value="Below Exclusive Products">Below Exclusive Products</option>
                            <?php endif;?>
                            <?php if(count($b_trending) <= 2): ?>
                              <option value="Below Trending Products">Below Trending Products</option>
                            <?php endif;?>
                            <?php if(count($header_top) <= 0): ?>
                              <option value="Header Top">Header Top</option>
                            <?php endif;?>
                          </select>
                       </div>
                    </div>
                  </div>
                  <div class="col-md-12">
                    <div class="form-group">
                       <label for="inputEmail" class="col-sm-12 col-form-label">Banner Image <span class="required">*</span> <span id="size"></span></label>
                       <div class="col-sm-12">
                          <input type="file" class="form-control"  name="banner_image" required>
                       </div>
                    </div>
                  </div>

                  <div class="col-md-12">
                    <div class="form-group">
                       <button name="submit" style="float: right" type="submit" class="btn btn-success">Add</button>
                    </div>
                  </div>

                   <?php echo form_close() ?>
                   

                  <!-- /.col -->
                </div>
                <!-- /.row -->
              </div>
              <!-- /.card-body -->
            </div>
          </div>
        </div>
            <!-- /.row -->
      </div><!--/. container-fluid -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
<script type="text/javascript">
  function check_size(e) {
     var value = e.value;

     if(value == 'Slider')
     {
        $('#size').html('(Size Must Be 200px X 240px)');
     }
     else if(value == 'Exclusive Products' || value == 'Trending Products')
     {
        $('#size').html('(Size Must Be 307px X 427px)')
     }
     else if(value == 'Below Exclusive Products' || value == 'Below Trending Products')
     {
        $('#size').html('(Size Must Be 420px X 233px)')
     }
     else if(value == 'Header Top')
     {
        $('#size').html('(Size Must Be 1350px X 50px)')
     }
  }

</script>