<style>
    
    /* Button Style */
    .open-my-modal-btn {
      padding: 10px 20px;
      font-size: 16px;
      cursor: pointer;
    }

    /* my-modal Overlay */
    .my-modal-overlay {
      display: none;
      position: fixed;
      top: 0; left: 0; right: 0; bottom: 0;
      background: rgba(0, 0, 0, 0.5);
      justify-content: center;
      align-items: center;
      z-index: 999;
    }

    /* my-modal Box */
    .my-modal {
      position: relative;
      background: white;
      padding: 10px 20px 10px 20px;
      border-radius: 8px;
      max-width: 400px;
      width: 90%;
      text-align: center;
      box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
      animation: fadeIn 0.3s ease-in-out;
    }

    @keyframes fadeIn {
      from { transform: scale(0.95); opacity: 0; }
      to { transform: scale(1); opacity: 1; }
    }

	.close-icon {
      position: absolute;
      top: 10px;
      right: 10px;
      background: transparent;
      border: none;
      font-size: 22px;
      cursor: pointer;
      color: #666;
    }

    .close-icon:hover {
      color: #000;
    }
	
    .my-modal h2 {
  margin-top: 0;
  margin-bottom: 20px;
  font-size: 24px;
  font-weight: bold;
  background: linear-gradient(to right, #4e54c8, #8f94fb);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
}

.my-modal textarea {
  width: 100%;
  min-height: 80px;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 8px;
  resize: vertical;
  font-size: 14px;
  transition: border 0.3s, box-shadow 0.3s;
}

.my-modal textarea:focus {
  outline: none;
  border-color: #6c63ff;
  box-shadow: 0 0 5px rgba(108, 99, 255, 0.4);
}

/* Save Button Styling */
.my-modal button.save-btn {
  margin-top: 15px;
  padding: 10px 18px;
  background-color: #6c63ff;
  color: white;
  font-weight: 600;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.3s ease, transform 0.2s ease;
}

.my-modal button.save-btn:hover {
  background-color: #5751d7;
  transform: scale(1.05);
}
  </style>

<?php echo $this->render_table_name(); ?>
<?php if ($this->is_create or $this->is_csv or $this->is_print){?>
        <div class="xcrud-top-actions">
            <div class="btn-group pull-right">
                <?php echo $this->print_button('btn btn-default','glyphicon glyphicon-print');
                echo $this->csv_button('btn btn-default','glyphicon glyphicon-file'); ?>
            </div>
            <?php echo $this->add_button('btn btn-success showmap','glyphicon glyphicon-plus-sign'); ?>
            <div class="clearfix"></div>
        </div>
<?php } ?>
        <div class="xcrud-list-container">
        <table class="xcrud-list table table-striped table-hover table-bordered">
            <thead>
                <?php echo $this->render_grid_head('tr', 'th'); ?>
            </thead>
            <tbody>
                <?php echo $this->render_grid_body('tr', 'td'); ?>
            </tbody>
            <tfoot>
                <?php echo $this->render_grid_footer('tr', 'td'); ?>
            </tfoot>
        </table>
        </div>
        <div class="xcrud-nav">
            <?php echo $this->render_limitlist(true); ?>
            <?php echo $this->render_pagination(); ?>
            <?php echo $this->render_search(); ?>
            <?php echo $this->render_benchmark(); ?>
        </div>

<div class="my-modal-overlay" id="taskremarkModal">
	<div class="my-modal">
		<button class="close-icon" onclick="closeMyModal()">&times;</button>
	  <h4>Task Remark</h4>
		<input type="hidden" id="hidden_task_user_id">
		<input type="hidden" id="hidden_task_status">
		<textarea placeholder="Enter you remark" id="taskremark"></textarea>
		<br>
		<button type="button" class="save-btn" onclick="saveTaskRemark()">Save</button>
	</div>
</div>

<script>
/*$(document).ready(function() {
       $('.showmap').on('click', function() {
		   $('#div_map').show();
	   });
});*/
function saveTaskRemark(){
	let user_id=document.getElementById('hidden_task_user_id').value;
	let task_status=document.getElementById('hidden_task_status').value;
	let task_remark=document.getElementById('taskremark').value;
	if(task_remark==""){
		alert('Enter remark');
	} else {
		const baseUrl = `${window.location.origin}/${window.location.pathname.split('/')[1]}`;
		const xhr = new XMLHttpRequest();
		xhr.open('POST', `${baseUrl}/ajax_data.php`, true);
		xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

		xhr.onreadystatechange = function () {
		  if (xhr.readyState === 4 && xhr.status === 200) {
			//console.log('Response:', xhr.responseText);
			closeMyModal();
		  }
		};

		const params = 'action=updateTaskRemark&id='+user_id+'&remark='+task_remark+'&status='+task_status;
		xhr.send(params);

	}
}

function openTaskremarkModal(id,status){
	document.getElementById('hidden_task_user_id').value = id;
	document.getElementById('hidden_task_status').value = status;
	document.getElementById('taskremark').value = "";
	document.getElementById('taskremarkModal').style.display = 'flex';
	
	const baseUrl = `${window.location.origin}/${window.location.pathname.split('/')[1]}`;
	const xhr = new XMLHttpRequest();
	xhr.open('POST', `${baseUrl}/ajax_data.php`, true);
	xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

	xhr.onreadystatechange = function () {
	  if (xhr.readyState === 4 && xhr.status === 200) {
		//console.log('Response:', xhr.responseText);
		value=JSON.parse(xhr.responseText);
		if(value.status=='success'){
			document.getElementById('taskremark').value = value.remark;
		}
	  }
	};

	const params = 'action=getTaskRemark&id='+id+'&status='+status;
	xhr.send(params);
}

function closeMyModal() {
	document.getElementById('taskremarkModal').style.display = 'none';
}
</script>