<?php echo view ('common/top_header_backdesk.php') ?>
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
</head>

<?php $session = session(); ?>


<body>
   
    <div class="container-scroller">
        
        <!--Top navbar-->
      <?= view('common/top_navbar') ?>
      <!-- partial -->
      <div class="container-fluid page-body-wrapper">
        
        <!--sidenavbar starts-->
        <?= view('common/side_navbar') ?>  
        <!--sidenavbar ends-->
        
        <div class="main-panel">
           <div class="content-wrapper">
                    <div class="card">
                        <form id="profile_update_form"
                            method="post" class="card-body" enctype="multipart/form-data">
                            <h4 class="card-title">Profile Details
                                <hr>
                            </h4>
                            <input type="hidden" name="user_id" id="user_id" value="<?php echo $apiData['user_id']?>">
                            <div class="row">
                                
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label class="w-100 font-weight-bold" for="name">
                                            Name</label>
                                        <input type="text" id="name" name="name"
                                            class="form-control" required value="<?php echo $apiData['name']?>">
                                    </div>
                                </div>
                               
                            </div>

                            <div class="row mt-3">
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label class="w-100 font-weight-bold" for="reference_number">Email</label>
                                        <input type="email" id="email" name="email"
                                            class="form-control" required value="<?php echo $apiData['email']?>">
                                    </div>
                                </div>
                               
                                
                            </div>
                            <div class="row mt-3">
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label class="w-100 font-weight-bold" for="reference_number">Mobile No</label>
                                        <input type="number" id="mobile_no" name="mobile_no"
                                            class="form-control" required value="<?php echo $apiData['mobile']?>">
                                    </div>
                                </div>
                               
                                
                            </div>
                          

                            <div class="row mt-3">
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label class="w-100 font-weight-bold" for="reference_number">Password</label>
                                        <input type="password" id="password" name="password"
                                            class="form-control" minlength="8" value="">
                                    </div>
                                </div>
                               
                                
                            </div>
                          
                          
                            <button type="submit" name="author_add" class="btn btn-success btn-sm mt-3">
                                <i class="mdi mdi-table-row-plus-after"></i>&nbsp;&nbsp;Update
                            </button>
                        </form>
                    </div>
                    
                    <!-- partial -->
                </div>
          <!-- content-wrapper ends -->
          <!-- partial:../../partials/_footer.html -->
          <footer class="footer">
            <div class="d-sm-flex justify-content-center justify-content-sm-between">
              <span class="text-muted text-center text-sm-left d-block d-sm-inline-block">Copyright © <?=date('Y') . ' ' . COMPANY_FULL_NAME?> . All rights reserved.</span>
              <span class="float-none float-sm-right d-block mt-1 mt-sm-0 text-center">With gratitude from || <i class="mdi mdi-heart text-danger"></i><a href="<?=CREDIT_LINK?>" target="_blank"><?=CREDIT_TITLE?></a></span>
            </div>
          </footer>
          <!-- partial -->
        </div>
        <!-- main-panel ends -->
      </div>
      <!-- page-body-wrapper ends -->
    </div>
    <!-- container-scroller -->
    <?php echo view ('common/footer_backdesk.php') ?>
 
   
    <script>
    $(document).ready(function () {
        $('#profile_update_form').on('submit', function (e) {
            const csrfTokenName = '<?= csrf_token() ?>';
            const csrfTokenValue = '<?= csrf_hash() ?>';
            e.preventDefault();

            // Get JWT token from local storage, cookie, or any other place
            const jwtToken = localStorage.getItem('jwt_token'); // or wherever you store it

            // Prepare form data
            var formData = new FormData(this);

            formData.append(csrfTokenName, csrfTokenValue);

            $.ajax({
                url: '<?php echo base_url()?>api/user/updateuser', // Change to your real endpoint
                method: 'POST',
                data: formData,
                processData: false,
                contentType: false,
                headers: {
                    'Authorization': 'Bearer ' + jwtToken
                },
                success: function (response) {
                    if(response.status){
                        toast('success', response.message || 'Profile updated successfully!');
                    }else{
                        toast('danger', response.message || 'Something went wrong!');
                    }
                }
                
            });
        });
    });
    </script>
   
</body>

</html>