<div class="col-lg-12">
    <div class="card">
        
            <div class="card-body">
                <div class="row justify-content-between">
                    <div class="col-auto"><h4 class="card-title">Person's Details</h4></div>
                    <div class="col-auto"><?php echo isset($customer['cid'])?"<span class='font-weight-bold text-bg-warning p-1'>Customer ID: CUST-".str_pad($customer['cid'],5,0,STR_PAD_LEFT)."</span>":""?></div>
                </div>
                <?php if(session()->getFlashdata('success')) : ?>
                  
                  <div class="alert alert-success">
                  <?= session()->getFlashdata('success') ?>
                  </div>
                  
                  <?php endif; ?>
                  
                  <?php if(session()->getFlashdata('error')) : ?>
                    
                    <div class="alert alert-danger">
                    <?= session()->getFlashdata('error') ?>
                    </div>
                    
                    <?php endif; ?>
                    <!-- <p class="card-description">  </p> -->
                    <form method="post" class="forms-sample" action="<?php echo isset($customer['cid'])?site_url('admin/updatecustomer/save/'.$customer['cid']):site_url('admin/addcustomer/save'); ?>"" id="myForm">
                    <?= csrf_field() ?>  
                    <?php echo isset($customer['cid'])?
                    '<input type="hidden" name="cid" value="'.$customer['cid'].'">
                    <input type="hidden" name="cd" value="'.$customer['c_date_creation'].'">
                    '
                    :""?>
                    <div class="form-group row">
                        <label for="firstname" class="col-sm-2 col-form-label">First Name</label>
                        <div class="col-sm-4">
                          <input type="text" class="form-control" name="fn" id="firstname"  placeholder="First Name" value="<?php echo isset($customer['c_fname'])?esc($customer['c_fname']):""?>" >
                        </div>
                        <label for="lastname" class="col-sm-2 col-form-label">Last Name</label>
                        <div class="col-sm-4">
                          <input type="text" class="form-control" name="ln" id="lastname" placeholder="Last Name" value="<?php echo isset($customer['c_lname'])?esc($customer['c_lname']):""?>" >
                        </div>
                      </div>
                    <div class="form-group row">
                        <label for="email" class="col-sm-2 col-form-label">email</label>
                        <div class="col-sm-4">
                        <input type="text" class="form-control" name="e" id="email" placeholder="email" value="<?php echo isset($customer['c_email'])?esc($customer['c_email']):""?>" >
                        </div>
                        <label for="mobile" class="col-sm-2 col-form-label">Mobile Number</label>
                        <div class="col-sm-4">
                        <input type="text" class="form-control" name="m" id="mobile" placeholder="0590000000" value="<?php echo isset($customer['c_mobile'])?esc($customer['c_mobile']):""?>" >
                        </div>
                    </div>
                    <div class="row">
                        <h4>Company Details</h4>
                    </div>
                    <div class="form-group row">
                        <label for="companyname" class="col-sm-2 col-form-label">Company Name</label>
                        <div class="col-sm-4">
                        <input type="text" class="form-control" name="cn" id="companyname" placeholder="Company Name" value="<?php echo isset($customer['c_cname'])?esc($customer['c_cname']):""?>" >
                        </div>
                        <label for="crnumber" class="col-sm-2 col-form-label">CR Number</label>
                        <div class="col-sm-4">
                        <input type="text" class="form-control" name="cr"  id="crnumber" placeholder="210890000" value="<?php echo isset($customer['c_ccr'])?esc($customer['c_ccr']):""?>" >
                        </div>
                    </div>
                    <div class="form-group row">
                        <label for="vatnumer" class="col-sm-2 col-form-label">VAT Number</label>
                        <div class="col-sm-4">
                        <input type="text" class="form-control" name="vat" id="vatnumer" placeholder="VAT Number" value="<?php echo isset($customer['c_cvat'])?esc($customer['c_cvat']):""?>"  >
                        </div>
                        <label for="city" class="col-sm-2 col-form-label">City</label>
                        <div class="col-sm-4">
                        <select name="city" class="form-select" id="city">
                            <option value="Dammam" <?php echo isset($customer['c_ccity'])?  ($customer['c_ccity']=="dammam")?"Selected":"":""?> >Dammam</option>
                            <option value="Khobar" <?php echo isset($customer['c_ccity'])?  ($customer['c_ccity']=="Khobar")?"Selected":"":""?>>Khobar</option>
                            <option value="Jubail" <?php echo isset($customer['c_ccity'])?  ($customer['c_ccity']=="Jubail")?"Selected":"":""?>>Jubail</option>
                            <option value="Riyadh" <?php echo isset($customer['c_ccity'])?  ($customer['c_ccity']=="Riyadh")?"Selected":"":""?>>Riyadh</option>
                            
                        </select>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label for="nataddress" class="col-sm-2 col-form-label">National Address</label>
                        <div class="col-sm-10">
                        <textarea class="form-control" id="nataddress" name="na" placeholder="National Address"><?php echo isset($customer['c_cna'])?esc($customer['c_cna']):""?></textarea>
                        </div>                        
                    </div>
                    <div class="row">
                        <h4>Finance </h4>
                    </div>
                    <div class="form-group row">
                          <label for="limit" class="col-sm-2 col-form-label">Credit Limit</label>
                      <div class="col-sm-4">
                         <input type="text" class="form-control" name="cl" id="limit" placeholder="50,000" value="<?php echo isset($customer['c_ccrlimit'])?esc($customer['c_ccrlimit']):""?>">
                      </div>                        
                          <label for="duration" class="col-sm-2 col-form-label">Credit duration</label>
                      <div class="col-sm-4">
                          <select name="duration" id="duration" class="form-select">
                              <option value="15" <?php echo isset($customer['c_ccrduration'])?  ($customer['c_ccrduration']=="15")?"Selected":"":""?>>15</option>
                              <option value="30" <?php echo isset($customer['c_ccrduration'])?  ($customer['c_ccrduration']=="30")?"Selected":"":""?>>30</option>
                              <option value="45" <?php echo isset($customer['c_ccrduration'])?  ($customer['c_ccrduration']=="45")?"Selected":"":""?>>45</option>
                              <option value="60" <?php echo isset($customer['c_ccrduration'])?  ($customer['c_ccrduration']=="60")?"Selected":"":""?>>60</option>
                              
                          </select>
                      </div>
                    </div>
                    <?php if(isset($customer['c_status'])):?>
                    <div class="form-group row">
                      <h4>Status</h4>
                      <label for="customerstatus" class="col-sm-2">Status</label>
                      <div class="col-sm-4">
                        <select name="customerstatus" id="customerstatus" class="form-select">
                          <option value="active" <?php echo isset($customer['c_status'])?($customer['c_status']=="active")?"Selected":"":""?>>Active</option>
                          <option value="hold" <?php echo isset($customer['c_status'])?($customer['c_status']=="hold")?"Selected":"":""?>>Hold</option>
                          <option value="block" <?php echo isset($customer['c_status'])?($customer['c_status']=="block")?"Selected":"":""?>>Block</option>
                        </select>
                      </div>
                    </div>
                    <?php endif;?>

                     
                      <button type="submit" class="btn btn-gradient-primary me-2"><?php echo isset($customer['cid'])?"Update Customer":"<i class='mdi mdi-plus'></i>Add Customer";?></button>
                      <button class="btn btn-light">Cancel</button>
                    </form>
                  </div>
        
    </div>
</div>

<!-- <script>
  const form = document.querySelector('#myForm');

form.addEventListener('submit', (event) => {
    // 1. Prevent the default form submission (page refresh)
    event.preventDefault();

    // 2. Create a FormData object from the form
    const formData = new FormData(form);

    // 3. Get individual values by the "name" attribute
    const name = formData.get('username');
    console.log(name);

    // 4. Convert all data to a simple object (common for JSON APIs)
    const data = Object.fromEntries(formData.entries());
    console.log(data); // { username: "...", email: "..." }
});
</script> -->