<?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>Social Media Info</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">Social Media Info</li>
            </ol>
          </div>
        </div>
      </div><!-- /.container-fluid -->
    </section>

    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-sm-4">
            <div class="card card-default">
              <div class="card-header">
                <h4>Add New</h4>
                
              </div>
              <!-- /.card-header -->
              <?php echo form_open(base_url().'admin/frontend_setting/add_new_social_media_info'); ?>
              <div class="card-body">
                <div class="row">
                  <div class="col-md-12">
                    <div class="form-group">
                      <label>Icon<span class="required">*</span></label>
                      <select class="form-control select2 font-awsom" name="fafa_icon"  required="required">
                        <option value="">Select Icon</option>
                         <?php $this->load->view('admin/include/fafa_icon_select') ?>
                      </select>
                    </div>
                  </div>
                  <div class="col-md-12">
                    <div class="form-group">
                      <label>Title<span class="required">*</span></label>
                      <input type="text" name="title" class="form-control" placeholder="Enter Title" required="">
                    </div>
                  </div>
                  <div class="col-md-12">
                    <div class="form-group">
                      <label>Content<span class="required">*</span></label>
                      <textarea type="text" name="content" class="form-control" required=""></textarea>
                    </div>
                  </div>
                  <div class="col-md-12">
                    <div class="form-group">
                      <label>Button URL<span class="required">*</span></label>
                      <input type="text" name="button_url" class="form-control" placeholder="Enter Button URL" required="">
                    </div>
                  </div>
                  <div class="col-md-12">
                    <div class="form-group">
                       <label for="inputEmail" class="col-sm-12 col-form-label">Color</label>
                       <div class="input-group my-colorpicker2 site_color_1 colorpicker-element" data-colorpicker-id="2">
                        <input type="text" name="color" class="form-control" data-original-title="" title="">

                        <div class="input-group-append">
                          <span class="input-group-text"><i class="fas fa-square fa_1"></i></span>
                        </div>
                      </div>
                    </div>
                  </div>
                  <div class="col-md-12">
                    <div class="form-group">
                      <button class="btn btn-info" type="submit" style="float: right">Add</button>
                    </div>
                  </div>
                  <?php echo form_close(); ?>
                </div>
              </div>
            </div>
          </div>
          <script type="text/javascript">
            $(function () {
               $('.site_color_1').colorpicker()
                  $('.site_color_1').on('colorpickerChange', function(event) {
                    $('.site_color_1 .fa_1').css('color', event.color.toString());
                  });
                });
          </script>
          
          <div class="col-sm-8">
            <div class="card card-default">
              <div class="card-header">
                <h4>View All</h4>
                
              </div>
                <div class="card-body">
                  <table id="example" class="table table-bordered table-striped">
                    <thead>
                    <tr>
                      <th>id</th>
                      <th>Icon</th>
                      <th>Title</th>
                      <th>Content</th>
                      <th></th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php $i=1; foreach ($all_social_media_info as $key => $social):?>
                    <tr>
                      <td><?php echo $i ?></td>
                      <td style="color: <?php echo $social->color ?>"><i class="fa <?php echo $social->fafa_icon ?>"></i></td>
                      <td style="color: <?php echo $social->color ?>"><?php echo $social->title ?></td>
                      <td style="color: <?php echo $social->color ?>"><?php echo $social->content ?></td>
                      <td style="color: <?php echo $social->color ?>"><a href="" class="btn btn-info btn-sm" data-toggle="modal" data-target="#update-social<?php echo $social->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/frontend_setting/delete_social_media_info/<?php echo $social->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=2; foreach ($all_social_media_info as $key => $social):?>
<div class="modal fade" id="update-social<?php echo $social->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</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/frontend_setting/update_social_media_info'); ?>
          <div class="form-group">
            <label>Icon<span class="required">*</span></label>
            <select class="form-control select2 font-awsom" name="fafa_icon"  required="required">
              <option value="">Select Icon</option>
               <?php $this->load->view('admin/include/fafa_icon_select', ['icon' => $social->fafa_icon]) ?>
            </select>
          </div>
          <div class="form-group">
            <label for="recipient-name" class="col-form-label">Title:</label>
            <input type="text" name="title" class="form-control" value="<?php echo $social->title ?>" required>
          </div>
          <div class="form-group">
            <label for="message-text" class="col-form-label">Content:</label>
            <textarea type="text" name="content" class="form-control" required><?php echo $social->content ?></textarea>

            <input type="hidden" name="id" class="form-control" value="<?php echo $social->id ?>">
          </div>
          <div class="form-group">
            <label for="recipient-name" class="col-form-label">Button URL:</label>
            <input type="text" name="button_url" class="form-control" value="<?php echo $social->button_url ?>" required>
          </div>
          <div class="form-group">
             <label for="inputEmail" class="col-sm-12 col-form-label">Color</label>
             <div class="input-group my-colorpicker2 site_color_<?php echo $i ?> colorpicker-element" data-colorpicker-id="2">
              <input type="text" name="color" class="form-control" data-original-title="" title="" value="<?php echo $social->color ?>">

              <div class="input-group-append">
                <span class="input-group-text"><i style="color: <?php echo $social->color ?>" class="fas fa-square fa_<?php echo $i ?>"></i></span>
              </div>
            </div>
          </div>
      </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>
<script type="text/javascript">
  $(function () {
     $('.site_color_<?php echo $i ?>').colorpicker()
        $('.site_color_<?php echo $i ?>').on('colorpickerChange', function(event) {
          $('.site_color_<?php echo $i ?> .fa_<?php echo $i ?>').css('color', event.color.toString());
        });
      });
</script>
<?php endforeach; ?>