<div class="content-wrapper">
   <div class="content-header">
      <div class="container-fluid">
         <div class="row mb-2">
            <div class="col-sm-6">
               <h1 class="m-0 text-dark">Edit Camp</h1>
            </div>
            <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="#">Sharnarthi</a></li>
                  <li class="breadcrumb-item active">Edit Camp </li>
               </ol>
            </div>
         </div>
      </div>
   </div>
   <section class="content">
      <div class="container-fluid">
         <div class="card card-default">
            <div class="card-header">
               <h3 class="card-title">Edit Camp</h3>
               <div class="card-tools">
                  <a href="<?php echo base_url()?>/admin/sharnarthi/view_all_camp" class="btn btn-success btn-sm"><i class="fa fa-eye" aria-hidden="true"></i> View All Camp</a>
               </div>
            </div>
            <?php echo form_open_multipart('admin/sharnarthi/update_camp/'.$camp->camp_id); ?>
            <div class="card-body">
               <div class="row">
                  <div class="col-md-6">
                     <div class="form-group">
                        <label for="inputEmail" class="col-sm-12 col-form-label">Camp Name (शिविर का नाम)<span class="required">*</span></label>
                        <div class="col-sm-12">
                           <input type="text" class="form-control" name="camp_name" placeholder="Enter Camp Name" required="required" value="<?php echo $camp->camp_name; ?>">
                        </div>
                     </div>
                  </div>
                  <div class="col-md-6">
                     <div class="form-group">
                        <label for="inputEmail" class="col-sm-12 col-form-label">Camp Head Name (शिविर प्रमुख का नाम)<span class="required">*</span></label>
                        <div class="col-sm-12">
                           <input type="text" class="form-control" name="camp_head_name" placeholder="Enter Camp Head Name" required="required" value="<?php echo $camp->camp_head_name; ?>">
                        </div>
                     </div>
                  </div>
                  
                  <div class="col-sm-12">
                     <div class="form-group">
                        <label for="inputName" class="col-sm-12 col-form-label">Camp Address (शिविर का पता)<span class="required">*</span></label>
                        <div class="col-sm-12">
                           <textarea type="text" name="camp_address" class="form-control" placeholder="Enter Camp Address" required><?php echo $camp->camp_address; ?></textarea>
                        </div>
                     </div>
                  </div>
                  <div class="col-sm-3">
                     <div class="form-group">
                        <label for="inputName" class="col-sm-12 col-form-label">Camp Pin Code (शिविर पिन कोड)<span class="required">*</span></label>
                        <div class="col-sm-12">
                           <input type="number" required name="camp_pin_code" id="pin_code" class="form-control" placeholder="Enter Camp Pin Code" value="<?php echo $camp->camp_pin_code; ?>">
                        </div>
                     </div>
                  </div>
                  <div class="col-sm-3">
                     <div class="form-group">
                        <label for="inputName" class="col-sm-12 col-form-label">Camp Post Office (शिविर का डाकघर)<span class="required">*</span></label>
                        <div class="col-sm-12">
                           <select name="camp_post_office" required id="area" class="form-control">
                              <option value="">Enter Pin Code First</option>
                           </select>
                        </div>
                     </div>
                  </div>
                  <div class="col-sm-3">
                     <div class="form-group">
                        <label for="inputName" class="col-sm-12 col-form-label">Camp Dist (शिविर का जिला)<span class="required">*</span></label>
                        <div class="col-sm-12">
                           <input type="text" name="camp_dist" required id="city" class="form-control" placeholder="Camp Dist"  readonly="">
                        </div>
                     </div>
                  </div>
                  <div class="col-sm-3">
                     <div class="form-group">
                        <label for="inputName" class="col-sm-12 col-form-label">Camp State (शिविर का राज्य)<span class="required">*</span></label>
                        <div class="col-sm-12">
                           <input type="text" name="camp_state" id="state" class="form-control" placeholder="Camp State" readonly="" 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">Update</button>
                     </div>
                  </div>
                  <?php echo form_close() ?>
               </div>
            </div>
         </div>
      </div>
   </section>
</div>

<script type="text/javascript">
   $('body').on('change', '#pin_code', function () {
       let pin_code = $('#pin_code').val();
       if (pin_code == 0) {
               swal ( "Oops" ,  "Please Enter Pin Code!" ,  "warning" );
           return false;
       }
       $.ajax({
         beforeSend: function() {
            $(".loader").show();
         },
         type: "GET",
         dataType:"JSON",
         async: true,
         url: '<?php echo base_url(); ?>/admin/admin/get_aadress_detaile_by_pin_code/'+pin_code,
         success: function (data) 
         {
             $('#area').html(data.area);
             $('#city').val(data.city);
             $('#state').val(data.state);
             $(".loader").hide();
         },
         error: function () {
           $(".loader").hide();
         }
       });
   });
   <?php if($camp->camp_pin_code): ?>
      $( document ).ready(function() {
          get_address("<?php echo $camp->camp_pin_code; ?>", "<?php echo $camp->camp_post_office; ?>")
      });

      function get_address(id, post) {
         $.ajax({
            beforeSend: function() {
               $(".loader").show();
            },
            type: "GET",
            dataType:"JSON",
            async: true,
            url: '<?php echo base_url(); ?>/admin/admin/get_aadress_detaile_by_pin_code_for_update/'+id+'/'+post,
            success: function (data) 
            {
                $('#area').html(data.area);
                $('#city').val(data.city);
                $('#state').val(data.state);
                $(".loader").hide();
            },
            error: function (e) {
               console.log(e.responseText)
              $(".loader").hide();
            }
          });
      }
   <?php endif;?>
</script>