<?php
session_start();
require_once __DIR__ . '/../../includes/auth.php';
require_once __DIR__ . '/../../classes/Database.php';
require_once __DIR__ . '/../../classes/Payroll.php';
require_once __DIR__ . '/../../classes/Branch.php';


$database = new Database();
$conn = $database->getConnection();


$auth = new Auth($conn);


if (!isset($_SESSION['user_id'])) {
    header('Location: login.php');
    exit();
}
$auth->enforceSuperAdminPrivileges($_SESSION['user_id']);
$payroll = new Payroll($conn);
$id=$_POST['id'];
$employee = $payroll->getEmployeeById($id);

?>

<?php include __DIR__ . '/../../includes/header.php'; ?>
    <div class="container mt-5">
        <h1 class="mb-4">Add New Employee</h1>
		
        <form method="POST">
			<ul class="nav nav-tabs">
			  <li><a href="#basic_info">Basic Information</a></li>
			  <li><a href="#emergency_contacts ">Emergency Contacts</a></li>
			  <li><a href="#payroll_information">Payroll Information</a></li>
			  <li><a href="#attachments">attachments</a></li>
			</ul>
			<br>
			<h3 id="basic_info"> BASIC INFORMATION </h3>
            <div class="form-group"> 
                <label for="employee_fullname">Employee fullname </label>
                <input type="text" class="form-control" id="employee_fullname" name="employee_fullname" required>
            </div>
			<div class="form-group">
                <label for="date_of_birth">Date of birth</label>
                <input type="text" class="form-control" id="date_of_birth" name="date_of_birth" required>
            </div>
			<div class="form-group">
                <label for="employee_phone">Employee Phone number</label>
                <input type="text" class="form-control" id="employee_phone" name="employee_phone" required>
            </div>
			 <div class="form-group">
                <label for="email">Employee Email</label>
                <input type="email" class="form-control" id="email" name="email" required>
            </div>
			
			<div class="form-group">
                <label for="home_district">Home District</label>
                <input type="text" class="form-control" id="home_district" name="home_district" required>
            </div>
			<div class="form-group">
                <label for="ta">T/A</label>
                <input type="text" class="form-control" id="ta" name="ta" required>
            </div>
			<div class="form-group">
                <label for="village">Village</label>
                <input type="text" class="form-control" id="village" name="village" required>
            </div>
			<div class="form-group">
                <label for="place_of_residence">Current place of Residence</label>
                <input type="text" class="form-control" id="place_of_residence" name="place_of_residence" required>
            </div>
			<div class="form-group">
                <label for="national_id">National ID No: </label>
                <input type="text" class="form-control" id="national_id" name="national_id" required>
            </div>
			
			
			<h3 id="emergency_contacts"> EMERGENCY CONTACTS </h3>
           
			
			
			<div class="form-group">
                <label for="next_of_kin_fullname">Next of Kin (fullname) </label>
                <input type="text" class="form-control" id="next_of_kin_fullname" name="next_of_kin_fullname" required>
            </div>
			<div class="form-group">
                <label for="next_of_kin_phone">Next of Kin Phone number </label>
                <input type="text" class="form-control" id="next_of_kin_phone" name="next_of_kin_phone" required>
            </div>
			<div class="form-group">
                <label for="next_of_kin_address">Next of Kin current address </label>
                <input type="text" class="form-control" id="next_of_kin_address" name="next_of_kin_address" required>
            </div>
			
			<h3 id="payroll_information"> PAYROLL INFORMATION </h3>
			 <div class="form-group">
                <label for="branch">Branch</label>
                <select class="form-control" id="branch" name="branch" required>
                    <?php
                    $branchObj = new Branch($conn);
                    $branches = $branchObj->getAllBranches();
                    while ($branch = $branches->fetch(PDO::FETCH_ASSOC)) {
                        echo '<option value="' . htmlspecialchars($branch['branch_id']) . '">' .
                             htmlspecialchars($branch['branch_name']) . '</option>';
                    }
                    ?>
                </select>
            </div>
			 <div class="form-group">
                <label for="employee_position">Position</label>
                <select class="form-control" id="employee_position" name="employee_position" required>
                    <option value="Director">Director</option>
                    <option value="Accountant">Accountant</option>
                    <option value="Branch_Manager">Branch Manager</option>
                    <option value="Sales_Representative">Sales Representative</option>
					<option value="Shop_Assistant">Shop Assistant</option>
					<option value="Cleaner">Cleaner</option>
   			   </select>
            </div>
         
		 
           
			
			<div class="form-group">
                <label for="contract_start"> Started Working / Contract Starts </label>
                <input type="date" class="form-control" id="contract_start" name="contract_start" required>
            </div>
			<div class="form-group">
                <label for="contract_ends"> Contract ends (skip if the employee is permanent) </label>
                <input type="date" class="form-control" id="contract_ends" name="contract_ends" required>
            </div>
			 <div class="form-group">
                <label for="payment_frequency">Payment Frequency</label>
                <select class="form-control" id="payment_frequency" name="payment_frequency" required>
                    <option value="Monthly">Monthly</option>
                    <option value="Fortnight">Fortnight</option>
                    <option value="Weekly">Weekly</option>
                    <option value="Daily">Daily</option>
				 </select>
            </div>
			<div class="form-group">
                <label for="basic_salary">Basic Wage/Salary</label>
                <input type="text" class="form-control" id="basic_salary" name="basic_salary" required>
            </div>
           
			<div class="form-group">
                <label for="bank_details"> Bank details </label>
                <input type="text" class="form-control" id="bank_details" name="bank_details" required>
            </div>
          
		  	<h3 id="attachments"> ATTACHMENTS </h3>
           
			<div class="form-group">
                <label for="id_copy">National ID </label>
                <input type="file" class="form-control" id="id_copy" name="id_copy" required>
            </div>
			
			<div class="form-group">
                <label for="certificates_copy">Attach copies of certificates</label>
                <input type="file" class="form-control" id="certificates_copy" name="certificates_copy" required>
            </div>
			
			
			
			
			
            <button type="submit" class="btn btn-primary">Add Employee</button>
            <a href="employee_list.php" class="btn btn-secondary">Cancel</a>
        </form>
    </div>
<?php include __DIR__ . '/../../includes/footer.php'; ?>