<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 Member</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="#">Member</a></li>
                 <li class="breadcrumb-item active">Edit Member</li>
              </ol>
           </div>
        </div>
     </div>
  </div>

   <section class="content">
      <div class="container">
         <div class="row"> 
            <div class="col-md-12 col-lg-12">
               <div class="container-fluid">
                  
                  <div class="card card-default">
                     <div class="card-header">
                        <h3 class="card-title">Edit New Member</h3>
                        <div class="float-right">
                           <a href="<?php echo base_url() ?>/admin/member/view_all_member" class="btn btn-success btn-sm">View All Member</a>
                        </div>
                     </div>
                     <?php echo form_open_multipart('admin/member/update_member/'.$member->user_rand_code); ?>
                     <div class="card-body">
                        <div class="row">
                           <div class="col-sm-8">
                              <div class="form-group row">
                                 <label for="inputName" class="col-sm-12 col-form-label">Member Name (सदस्य का नाम)<span style="color:red">*</span></label>
                                 <div class="col-sm-12">
                                    <input type="text" name="user_name" class="form-control" placeholder="Enter Member Name" required="required" value="<?php echo $member->user_name; ?>">
                                 </div>
                              </div>
                           </div>
                           <div class="col-sm-4">
                              <div class="form-group row">
                                 <label for="inputName" class="col-sm-12 col-form-label">Member Designation (सदस्य पदनाम)<span style="color:red">*</span></label>
                                 <div class="col-sm-12">
                                    <select type="text" name="user_designation" class="form-control" placeholder="Enter Member Designation" required="required">
                                       <option value="">Select</option>
                                       <?php foreach ($role_permission as $key => $designation):?>
                                          <option <?php if($designation->role_name == $member->user_designation){echo 'selected';}?> value="<?php echo $designation->role_name; ?>"><?php echo $designation->role_name; ?></option>
                                       <?php endforeach; ?>
                                    </select>
                                 </div>
                              </div>
                           </div>
                           <div class="col-sm-6">
                              <div class="form-group row">
                                 <label for="inputName" class="col-sm-12 col-form-label">Member Mobile No. (सदस्य मोबाइल नं.)<span style="color:red">*</span></label>
                                 <div class="col-sm-12">
                                    <input type="number" name="user_mobile" class="form-control" placeholder="Enter Member Mobile No" required="required" value="<?php echo $member->user_mobile; ?>" pattern="[1-9]{1}[0-9]{9}">
                                 </div>
                              </div>
                           </div>
                           <div class="col-sm-6">
                              <div class="form-group row">
                                 <label for="inputName" class="col-sm-12 col-form-label">Member Email ID (सदस्य ईमेल आईडी)</label>
                                 <div class="col-sm-12">
                                    <input type="email" name="user_email" class="form-control" placeholder="Enter Member Email ID"  value="<?php echo $member->user_email; ?>" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$">
                                 </div>
                              </div>
                           </div>
                           <div class="col-sm-4">
                              <div class="form-group row">
                                 <label for="inputName" class="col-sm-12 col-form-label">Member Gender (सदस्य लिंग)<span style="color:red">*</span></label>
                                 <div class="col-sm-12">
                                    <select type="text" name="user_gender" class="form-control" required>
                                       <option <?php if($member->user_gender == 'Male'){echo 'selected';}?> value="Male">Male</option>
                                       <option <?php if($member->user_gender == 'Female'){echo 'selected';}?> value="Female">Female</option>
                                       <option <?php if($member->user_gender == 'Transgender'){echo 'selected';}?> value="Transgender">Transgender</option>
                                    </select>
                                 </div>
                              </div>
                           </div>
                           <div class="col-sm-4">
                              <div class="form-group row">
                                 <label for="inputName" class="col-sm-12 col-form-label">Member date of Birth (सदस्य जन्म तिथि)<span style="color:red">*</span></label>
                                 <div class="col-sm-12">
                                    <input type="date" name="user_dob" class="form-control" placeholder="Enter Email ID"  value="<?php echo $member->user_dob; ?>" required> 
                                 </div>
                              </div>
                           </div>
                           <div class="col-sm-4">
                              <div class="form-group row">
                                 <label for="inputName" class="col-sm-12 col-form-label">Highest Education (उच्चतम शिक्षा)<span style="color:red">*</span></label>
                                 <div class="col-sm-12">
                                    <input type="text" name="user_education" class="form-control" placeholder="Enter Memeber Highest Education" value="<?php echo $member->user_education; ?>" required>
                                 </div>
                              </div>
                           </div>
                           <div class="col-sm-6">
                              <div class="form-group row">
                                 <label for="inputName" class="col-sm-12 col-form-label">Nature of Employment (रोज़गार की प्रकृति)<span style="color:red">*</span></label>
                                 <div class="col-sm-12">
                                    <input type="text" name="user_employment" class="form-control" placeholder="Enter Memeber Nature of Employment" value="<?php echo $member->user_employment; ?>" required>
                                 </div>
                              </div>
                           </div>
                           <div class="col-sm-6">
                              <div class="form-group row">
                                 <label for="inputName" class="col-sm-12 col-form-label">Member Pin Code (सदस्य पिन कोड)<span style="color:red">*</span></label>
                                 <div class="col-sm-12">
                                    <input type="number" name="user_pin_code" id="pin_code" class="form-control" placeholder="Enter Member Pin Code" value="<?php echo $member->user_pin_code; ?>" required>
                                 </div>
                              </div>
                           </div>
                           <div class="col-sm-12">
                              <div class="form-group row">
                                 <label for="inputName" class="col-sm-12 col-form-label">Member Address (सदस्य का पता)<span style="color:red">*</span></label>
                                 <div class="col-sm-12">
                                    <textarea type="text" name="user_address" class="form-control" placeholder="Enter Member Address" required><?php echo $member->user_address; ?></textarea>
                                 </div>
                              </div>
                           </div>
                           <div class="col-sm-4">
                              <div class="form-group row">
                                 <label for="inputName" class="col-sm-12 col-form-label">Member Post Office (सदस्य का डाकघर)<span style="color:red">*</span></label>
                                 <div class="col-sm-12">
                                    <select name="user_post" id="area" class="form-control" required>
                                       <option value="">Enter Pin Code First</option>
                                    </select>
                                 </div>
                              </div>
                           </div>
                           <div class="col-sm-4">
                              <div class="form-group row">
                                 <label for="inputName" class="col-sm-12 col-form-label">Member Dist (सदस्‍य का जिला)<span style="color:red">*</span></label>
                                 <div class="col-sm-12">
                                    <input type="text" name="user_dist" id="city" class="form-control" placeholder="Member Dist"  readonly="" required>
                                 </div>
                              </div>
                           </div>
                           <div class="col-sm-4">
                              <div class="form-group row">
                                 <label for="inputName" class="col-sm-12 col-form-label">Member State (सदस्‍य का राज्य)<span style="color:red">*</span></label>
                                 <div class="col-sm-12">
                                    <input type="text" name="user_state" id="state" class="form-control" placeholder="Member State" readonly="" required>
                                 </div>
                              </div>
                           </div>
                           <div class="col-sm-4">
                              <div class="form-group row">
                                 <label for="inputName" class="col-sm-12 col-form-label">Member Nature of Employment (सदस्य रोजगार की प्रकृति)<span style="color:red">*</span></label>
                                 <div class="col-sm-12">
                                    <select type="text" name="user_employment_nature" onchange="check_nature_employment(this.value)" class="form-control" placeholder="Member State"  required>
                                       <option value="">Select</option>
                                       <option <?php if($member->user_employment_nature == 'Employed'){echo 'selected';}?> value="Employed">Employed</option>
                                       <option <?php if($member->user_employment_nature == 'Self Employed'){echo 'selected';}?> value="Self Employed">Self Employed</option>
                                    </select>
                                 </div>
                              </div>
                           </div>
                           <div class="col-sm-4" id="name_of_company">
                              <div class="form-group row">
                                 <label for="inputName" class="col-sm-12 col-form-label">Company Name (कंपनी का नाम)<span style="color:red">*</span></label>
                                 <div class="col-sm-12">
                                    <input type="text" name="user_empoyed_company_name" class="form-control" placeholder="Member Company Name" id="company_name" value="<?php echo $member->user_empoyed_company_name; ?>">
                                 </div>
                              </div>
                           </div>
                           <div class="col-sm-4" id="work_nature">
                              <div class="form-group row">
                                 <label for="inputName" class="col-sm-12 col-form-label">Nature of Work (कार्य की प्रकृति)<span style="color:red">*</span></label>
                                 <div class="col-sm-12">
                                    <input type="text" name="user_work_nature" class="form-control" placeholder="Member Company Name" id="nature_work" value="<?php echo $member->user_work_nature; ?>">
                                 </div>
                              </div>
                           </div>
                           <div class="col-sm-8 hide_1"></div>
                           <div class="col-sm-4 hide_2"></div>
                           <div class="col-sm-4">
                              <div class="form-group row">
                                 <label for="inputName" class="col-sm-12 col-form-label">Member Availability (सदस्य उपलब्धता)<span style="color:red">*</span></label>
                                 
                              </div>
                           </div>
                           <div class="col-sm-8"></div>
                           <?php
                              $days = array(
                                  'mon' => 'Monday',
                                  'tue' => 'Tuesday',
                                  'wed' => 'Wednesday',
                                  'thu' => 'Thursday',
                                  'fri' => 'Friday',
                                  'sat' => 'Saturday',
                                  'sun' => 'Sunday'
                              );

                              $dataArray = json_decode($member->user_availability, true);
                           ?>
                           <div class="col-md-4">
                              <table width="100%">
                                 <?php foreach ($days as $dayKey => $dayName): ?>
                                    <tr>
                                        <td>
                                            <label><input type="checkbox" id="<?php echo $dayKey; ?>-checkbox" onclick="toggleWorkingHours('<?php echo $dayKey; ?>')" <?php echo !empty($dataArray[$dayName]['start']) ? 'checked' : ''; ?>>&nbsp;&nbsp;<?php echo $dayName; ?></label>
                                        </td>
                                        <td>
                                            <select class="form-control" name="<?php echo $dayKey; ?>-start" id="<?php echo $dayKey; ?>-start" <?php echo empty($dataArray[$dayName]['start']) ? 'disabled' : ''; ?>> 
                                                <option value="">Select</option>
                                                <option <?php if($dataArray[$dayName]['start'] == '2-4'){echo 'selected';} ?> value="2-4">2-4 Hrs.</option>
                                                <option <?php if($dataArray[$dayName]['start'] == '5-8'){echo 'selected';} ?> value="5-8">5-8 Hrs.</option>
                                                <option <?php if($dataArray[$dayName]['start'] == '9-12'){echo 'selected';} ?> value="9-12">9-12 Hrs.</option>
                                            </select>
                                        </td>
                                    </tr>
                                 <?php endforeach; ?>
                              </table>
                           </div>
                           <div class="col-sm-8"></div>
                           <div class="col-sm-4">
                              <div class="form-group row">
                                 <label for="inputName" class="col-sm-12 col-form-label">Member Image (सदस्य का छवि)</label>
                                 <div class="col-sm-12">
                                    <input type="file" name="user_image" class="form-control" placeholder="Member State" >
                                 </div>
                              </div>
                           </div>
                           <div class="col-sm-4">
                              <div class="form-group row">
                                 <label for="inputName" class="col-sm-12 col-form-label">Is Teacher ? (शिक्षक है ?) <span style="color:red">*</span></label>
                                 <div class="col-sm-12">
                                    <select name="user_is_teacher" class="form-control" placeholder="Member State" required>
                                       <option value="">Select</option>
                                       <option <?php if($member->user_is_teacher == 1){echo 'selected';}?> value="1">Yes</option>
                                       <option <?php if($member->user_is_teacher == 0){echo 'selected';}?> value="0">No</option>
                                    </select>
                                 </div>
                              </div>
                           </div>
                           <div class="col-sm-4">
                              <div class="form-group row">
                                 <label for="inputName" class="col-sm-12 col-form-label">Associated with any other social welfare organisation? Enter Name</label>
                                 <div class="col-sm-12">
                                    <input type="text" name="user_other_organisation" class="form-control" placeholder="Member Other Organisation Name" value="<?php echo $member->user_other_organisation; ?>">
                                 </div>
                              </div>
                           </div>
                           <div class="col-sm-4">
                              <div class="form-group row">
                                 <label for="inputName" class="col-sm-12 col-form-label">Preview Image </label>
                                 <div class="col-sm-12">
                                    <img src="<?php echo base_url(); ?><?php echo $member->user_image; ?>" width="100px">
                                 </div>
                              </div>
                           </div>
                        </div>
                        <div class="form-group row" >
                           <div class="offset-sm-0 col-sm-10">
                              <button onclick="return confirm('Are You Sure ? You Want to Add Member.')"  type="submit" class="btn btn-success setting-submit" name="submit">Save</button>
                           </div>
                        </div>   
                       
                     </div>
                     <?php echo form_close(); ?>
                  </div>
               </div>
            </div>
          </div>
         </div>
      </div>
   </div>
</section>
  
</div>
<style type="text/css">
   #name_of_company, #work_nature, .hide_2
   {
      display: none;
   }
</style>
 <script>
    $( document ).ready(function() {
          check_nature_employment("<?php echo $member->user_employment_nature; ?>")
      });
   function check_nature_employment(e) 
   {
      if(e == 'Employed')
      {
         $('#name_of_company').show();
         $('#work_nature').show();
         $('#company_name').attr('required', true);
         $('#nature_work').attr('required', true);
         $('.hide_1').hide();
         $('.hide_2').hide();
      }
      else if(e == 'Self Employed')
      {
         $('#name_of_company').hide();
         $('#work_nature').show();
         $('#company_name').attr('required', false);
         $('#nature_work').attr('required', true);
         $('.hide_2').show();
         $('.hide_1').hide();
      }
   }
   function toggleWorkingHours(day) {
      var startInput = document.getElementById(day + '-start');
      var checkbox = document.getElementById(day + '-checkbox');
        
      startInput.disabled = !checkbox.checked;
        
      if (checkbox.checked) {
          startInput.setAttribute('required', 'required');
      } else {
          startInput.removeAttribute('required');
      }
   }
   $('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($member->user_pin_code): ?>
      $( document ).ready(function() {
          get_address("<?php echo $member->user_pin_code; ?>", "<?php echo $member->user_post; ?>")
      });

      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>