<style type="text/css">
.cursor-pointer{
	cursor: pointer;
}
</style>
<section style="padding-bottom:2rem;">
	<div class="container">
		<div class="card bg-light-transparent">
			<div class="card-body">
				<div class="card no-shadow" >
					<div class="card-body">
						
						<div class="row mb-5">
							<div class="col-12 col-lg-2">
								<label><b>Workflow Name : </b></label>
							</div>
							<div class="col-12 col-lg-10">
								<input type="text" class="form-control" id="workflow_name">
							</div>
						</div>

						<div class="row">
							<div class="col-12">
								<div class="table-responsive">
									<table class="table table-bordered">
										<thead>
											<tr>
												<th>#</th>
												<th>Action Type</th>
												<th>Employment Detail</th>
												<th>Address</th>
												<th>Family Info</th>
												<th>Academic Qualification</th>
												<th>Additional Personal Data</th>
												<th>Previous Employment Detail</th>
												<th>Professional Memberships</th>
												<th>Professional Licenses</th>
												<th>Recognition</th>
												<th>Contract Element</th>
												<th>Basic Pay</th>
												<th>Bank Details</th>
												<th>Statutory Details</th>
												<th>Recurring Pay / Deduct</th>
												<th>Third Party Payment</th>

												<th>Education in Progress</th>
												<th>Emergency Contact</th>
												<th>Professional Education</th>
												<th>Professional Certificate</th>
												<!-- <th>PCB Consideration</th> -->
											</tr>
										</thead>
										<tbody>

										</tbody>
									</table>
								</div>
							</div>
						</div>

						<div class="row">
							<div class="col-12">
								<button class="btn btn-primary" id="btn-workflow"><i class="fas fa-save"></i> Save workflow</button>
							</div>
						</div>

					</div>
				</div>
			</div>
		</div>
	</div>
</section>
<script type="text/javascript">
	
	var actionTypeList = [
	'Hiring',
	'Re-entry into company',
	'Promotion',
	'Change of pay',
	'Change of grade',
	'Secondment',
	'Transfer interdepartmental',
	'Transfer intradepartmental',
	'Long term absence',
	'Resume work',
	'Suspension',
	'Renewal contract',
	'Resignation',
	'Termination',
	'Retirement'];

	var tableList = [];

	$(document).ready(function(){

		for (var i = 0; i < 15; i++) {
			var obj = {
				bil:i+1,
				action_type:actionTypeList[i],
				joining_group:false,
				address:false,
				family_info:false,
				academic_qualification:false,
				additional_personal_data:false,
				previous_employment_detail:false,
				professional_membership:false,
				professional_license:false,
				recognition:false,
				contract_element:false,
				basic_pay:false,
				bank_detail:false,
				statutory_detail:false,
				recurring:false,
				third_party:false,

				education_in_progress:false,
				emergency_contact:false,
				professional_education:false,
				professional_certificate:false,
				// pcb_consideration:false,
			}
			tableList.push(obj);
		};

		createTable();

		$('#btn-workflow').click(function(){
			
			data = {
				token : '<?php echo $_SESSION['token']; ?>',
				name : $('#workflow_name').val(),
				workflow: tableList,
			};

			ajxRequest('<?php echo base_url('/hr/api/staffprofiling/create_workflow'); ?>', 'POST', data, '<?php echo base_url('/hr/StaffProfile/'); ?>');
		});
	});

	function clickICON(elem){
		var infotype 	= $(elem).data('infotype');
		var actiontype  = $(elem).data('actiontype');

		tableList.forEach((row,index) => {

			if(row.bil == actiontype){
				
				if (infotype == 'joining_group') {
					var boolVal = row.joining_group;
					if(boolVal){
						tableList[index].joining_group = false;
					}else{
						tableList[index].joining_group = true;
					}
				};

				if (infotype == 'address') {
					var boolVal = row.address;
					if(boolVal){
						tableList[index].address = false;
					}else{
						tableList[index].address = true;
					}
				};

				if (infotype == 'family_info') {
					var boolVal = row.family_info;
					if(boolVal){
						tableList[index].family_info = false;
					}else{
						tableList[index].family_info = true;
					}
				};

				if (infotype == 'academic_qualification') {
					var boolVal = row.academic_qualification;
					if(boolVal){
						tableList[index].academic_qualification = false;
					}else{
						tableList[index].academic_qualification = true;
					}
				};

				if (infotype == 'additional_personal_data') {
					var boolVal = row.additional_personal_data;
					if(boolVal){
						tableList[index].additional_personal_data = false;
					}else{
						tableList[index].additional_personal_data = true;
					}
				};

				if (infotype == 'previous_employment_detail') {
					var boolVal = row.previous_employment_detail;
					if(boolVal){
						tableList[index].previous_employment_detail = false;
					}else{
						tableList[index].previous_employment_detail = true;
					}
				};

				if (infotype == 'professional_membership') {
					var boolVal = row.professional_membership;
					if(boolVal){
						tableList[index].professional_membership = false;
					}else{
						tableList[index].professional_membership = true;
					}
				};

				if (infotype == 'professional_license') {
					var boolVal = row.professional_license;
					if(boolVal){
						tableList[index].professional_license = false;
					}else{
						tableList[index].professional_license = true;
					}
				};

				if (infotype == 'recognition') {
					var boolVal = row.recognition;
					if(boolVal){
						tableList[index].recognition = false;
					}else{
						tableList[index].recognition = true;
					}
				};

				if (infotype == 'contract_element') {
					var boolVal = row.contract_element;
					if(boolVal){
						tableList[index].contract_element = false;
					}else{
						tableList[index].contract_element = true;
					}
				};

				if (infotype == 'basic_pay') {
					var boolVal = row.basic_pay;
					if(boolVal){
						tableList[index].basic_pay = false;
					}else{
						tableList[index].basic_pay = true;
					}
				};

				if (infotype == 'bank_detail') {
					var boolVal = row.bank_detail;
					if(boolVal){
						tableList[index].bank_detail = false;
					}else{
						tableList[index].bank_detail = true;
					}
				};

				if (infotype == 'statutory_detail') {
					var boolVal = row.statutory_detail;
					if(boolVal){
						tableList[index].statutory_detail = false;
					}else{
						tableList[index].statutory_detail = true;
					}
				};

				if (infotype == 'recurring') {
					var boolVal = row.recurring;
					if(boolVal){
						tableList[index].recurring = false;
					}else{
						tableList[index].recurring = true;
					}
				};

				if (infotype == 'third_party') {
					var boolVal = row.third_party;
					if(boolVal){
						tableList[index].third_party = false;
					}else{
						tableList[index].third_party = true;
					}
				};

				if (infotype == 'education_in_progress') {
					var boolVal = row.education_in_progress;
					if(boolVal){
						tableList[index].education_in_progress = false;
					}else{
						tableList[index].education_in_progress = true;
					}
				};

				if (infotype == 'emergency_contact') {
					var boolVal = row.emergency_contact;
					if(boolVal){
						tableList[index].emergency_contact = false;
					}else{
						tableList[index].emergency_contact = true;
					}
				};

				if (infotype == 'professional_education') {
					var boolVal = row.professional_education;
					if(boolVal){
						tableList[index].professional_education = false;
					}else{
						tableList[index].professional_education = true;
					}
				};

				if (infotype == 'professional_certificate') {
					var boolVal = row.professional_certificate;
					if(boolVal){
						tableList[index].professional_certificate = false;
					}else{
						tableList[index].professional_certificate = true;
					}
				};

				// if (infotype == 'pcb_consideration') {
				// 	var boolVal = row.pcb_consideration;
				// 	if(boolVal){
				// 		tableList[index].pcb_consideration = false;
				// 	}else{
				// 		tableList[index].pcb_consideration = true;
				// 	}
				// };
				createTable();
			}
		});
	}

	function createTable(){
		var table = $('.table').DataTable().clear();

		tableList.forEach((actionType,index)=>{
		
			//------------
			// THERE SHOULD BE ANOTHER WAY OF WRITING THIS -S-T-U-P-I-D- STATEMENT
			//------------
				//---- INFO TYPE 0 : JOINING GROUP
				if (actionType.joining_group) {
					join_group_dom = '<div class="text-success w-100 text-center"><span class="text-success"><i class="fas fa-check cursor-pointer" data-infotype="joining_group" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}else{
					join_group_dom = '<div class="text-danger w-100 text-center"><span class="text-danger"><i class="fa fa-times cursor-pointer" data-infotype="joining_group" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}

				//---- INFO TYPE 1 : ADDRESS
				if (actionType.address) {
					address_dom = '<div class="text-success w-100 text-center"><span class="text-success"><i class="fas fa-check cursor-pointer" data-infotype="address" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}else{
					address_dom = '<div class="text-danger w-100 text-center"><span class="text-danger"><i class="fa fa-times cursor-pointer" data-infotype="address" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}

				//---- INFO TYPE 2: FAMILY INFO
				if (actionType.family_info) {
					family_info_dom = '<div class="text-success w-100 text-center"><span class="text-success"><i class="fas fa-check cursor-pointer" data-infotype="family_info" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}else{
					family_info_dom = '<div class="text-danger w-100 text-center"><span class="text-danger"><i class="fa fa-times cursor-pointer" data-infotype="family_info" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}

				//---- INFO TYPE 3: ACADEMIC QUALIFICATION
				if (actionType.academic_qualification) {
					academic_dom = '<div class="text-success w-100 text-center"><span class="text-success"><i class="fas fa-check cursor-pointer" data-infotype="academic_qualification" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}else{
					academic_dom = '<div class="text-danger w-100 text-center"><span class="text-danger"><i class="fa fa-times cursor-pointer" data-infotype="academic_qualification" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}

				//---- INFO TYPE 4: ADDITIONAL PERSONAL DATA
				if (actionType.additional_personal_data) {
					additional_dom = '<div class="text-success w-100 text-center"><span class="text-success"><i class="fas fa-check cursor-pointer" data-infotype="additional_personal_data" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}else{
					additional_dom = '<div class="text-danger w-100 text-center"><span class="text-danger"><i class="fa fa-times cursor-pointer" data-infotype="additional_personal_data" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}

				//---- INFO TYPE 5: PREVIOUS EMPLOYMENT DETAIL
				if (actionType.previous_employment_detail) {
					prev_emp_dom = '<div class="text-success w-100 text-center"><span class="text-success"><i class="fas fa-check cursor-pointer" data-infotype="previous_employment_detail" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}else{
					prev_emp_dom = '<div class="text-danger w-100 text-center"><span class="text-danger"><i class="fa fa-times cursor-pointer" data-infotype="previous_employment_detail" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}

				//---- INFO TYPE 6: PROFESSIONAL MEMBERSHIP
				if (actionType.professional_membership) {
					prof_membership_dom = '<div class="text-success w-100 text-center"><span class="text-success"><i class="fas fa-check cursor-pointer" data-infotype="professional_membership" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}else{
					prof_membership_dom = '<div class="text-danger w-100 text-center"><span class="text-danger"><i class="fa fa-times cursor-pointer" data-infotype="professional_membership" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}

				//---- INFO TYPE 7: PROFESSIONAL LICENSE
				if (actionType.professional_license) {
					license_dom = '<div class="text-success w-100 text-center"><span class="text-success"><i class="fas fa-check cursor-pointer" data-infotype="professional_license" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}else{
					license_dom = '<div class="text-danger w-100 text-center"><span class="text-danger"><i class="fa fa-times cursor-pointer" data-infotype="professional_license" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}

				//---- INFO TYPE 8: RECOGNITION
				if (actionType.recognition) {
					recognition_dom = '<div class="text-success w-100 text-center"><span class="text-success"><i class="fas fa-check cursor-pointer" data-infotype="recognition" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}else{
					recognition_dom = '<div class="text-danger w-100 text-center"><span class="text-danger"><i class="fa fa-times cursor-pointer" data-infotype="recognition" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}

				//---- INFO TYPE 9: CONTRACT ELEMENT
				if (actionType.contract_element) {
					contract_dom = '<div class="text-success w-100 text-center"><span class="text-success"><i class="fas fa-check cursor-pointer" data-infotype="contract_element" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}else{
					contract_dom = '<div class="text-danger w-100 text-center"><span class="text-danger"><i class="fa fa-times cursor-pointer" data-infotype="contract_element" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}

				//---- INFO TYPE 10:BASIC PAY
				if (actionType.basic_pay) {
					basic_pay_dom = '<div class="text-success w-100 text-center"><span class="text-success"><i class="fas fa-check cursor-pointer" data-infotype="basic_pay" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}else{
					basic_pay_dom = '<div class="text-danger w-100 text-center"><span class="text-danger"><i class="fa fa-times cursor-pointer" data-infotype="basic_pay" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}

				//---- INFO TYPE 11:BANK DETAIL
				if (actionType.bank_detail) {
					bank_detail_dom = '<div class="text-success w-100 text-center"><span class="text-success"><i class="fas fa-check cursor-pointer" data-infotype="bank_detail" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}else{
					bank_detail_dom = '<div class="text-danger w-100 text-center"><span class="text-danger"><i class="fa fa-times cursor-pointer" data-infotype="bank_detail" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}

				//---- INFO TYPE 12:STATUTORY DETAIL
				if (actionType.statutory_detail) {
					stat_dom = '<div class="text-success w-100 text-center"><span class="text-success"><i class="fas fa-check cursor-pointer" data-infotype="statutory_detail" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}else{
					stat_dom = '<div class="text-danger w-100 text-center"><span class="text-danger"><i class="fa fa-times cursor-pointer" data-infotype="statutory_detail" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}

				//---- INFO TYPE 13:RECURRING 
				if (actionType.recurring) {
					recurring_dom = '<div class="text-success w-100 text-center"><span class="text-success"><i class="fas fa-check cursor-pointer" data-infotype="recurring" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}else{
					recurring_dom = '<div class="text-danger w-100 text-center"><span class="text-danger"><i class="fa fa-times cursor-pointer" data-infotype="recurring" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}

				//---- INFO TYPE 14:THIRD PARTY
				if (actionType.third_party) {
					third_party_dom = '<div class="text-success w-100 text-center"><span class="text-success"><i class="fas fa-check cursor-pointer" data-infotype="third_party" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}else{
					third_party_dom = '<div class="text-danger w-100 text-center"><span class="text-danger"><i class="fa fa-times cursor-pointer" data-infotype="third_party" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}


				//---- INFO TYPE 15:EDUCATION IN PROGRESS
				if (actionType.education_in_progress) {
					education_in_progress_dom = '<div class="text-success w-100 text-center"><span class="text-success"><i class="fas fa-check cursor-pointer" data-infotype="education_in_progress" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}else{
					education_in_progress_dom = '<div class="text-danger w-100 text-center"><span class="text-danger"><i class="fa fa-times cursor-pointer" data-infotype="education_in_progress" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}

				//---- INFO TYPE 16:EMERGENCY CONTACT
				if (actionType.emergency_contact) {
					emergency_contact_dom = '<div class="text-success w-100 text-center"><span class="text-success"><i class="fas fa-check cursor-pointer" data-infotype="emergency_contact" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}else{
					emergency_contact_dom = '<div class="text-danger w-100 text-center"><span class="text-danger"><i class="fa fa-times cursor-pointer" data-infotype="emergency_contact" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}

				//---- INFO TYPE 17:PROFESSIONAL EDUCATION
				if (actionType.professional_education) {
					professional_education_dom = '<div class="text-success w-100 text-center"><span class="text-success"><i class="fas fa-check cursor-pointer" data-infotype="professional_education" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}else{
					professional_education_dom = '<div class="text-danger w-100 text-center"><span class="text-danger"><i class="fa fa-times cursor-pointer" data-infotype="professional_education" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}

				//---- INFO TYPE 18:PROFESSIONAL CERTIFICATE
				if (actionType.professional_certificate) {
					professional_certificate_dom = '<div class="text-success w-100 text-center"><span class="text-success"><i class="fas fa-check cursor-pointer" data-infotype="professional_certificate" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}else{
					professional_certificate_dom = '<div class="text-danger w-100 text-center"><span class="text-danger"><i class="fa fa-times cursor-pointer" data-infotype="professional_certificate" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				}

				//---- INFO TYPE 15:PCB CONSIDERATION
				// if (actionType.pcb_consideration) {
				// 	pcb_dom = '<div class="text-success w-100 text-center"><span class="text-success"><i class="fas fa-check cursor-pointer" data-infotype="pcb_consideration" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				// }else{
				// 	pcb_dom = '<div class="text-danger w-100 text-center"><span class="text-danger"><i class="fa fa-times cursor-pointer" data-infotype="pcb_consideration" data-actiontype="'+actionType.bil+'" onclick="clickICON(this)" ></i></span></div>';
				// }

			//------------
			
			table.row.add([
				actionType.bil,
				'<label><b>'+actionType.action_type+'</b></label>',
				join_group_dom,
				address_dom,
				family_info_dom,
				academic_dom,
				additional_dom,
				prev_emp_dom,
				prof_membership_dom,
				license_dom,
				recognition_dom,
				contract_dom,
				basic_pay_dom,
				bank_detail_dom,
				stat_dom,
				recurring_dom,
				third_party_dom,
				education_in_progress_dom,
				emergency_contact_dom,
				professional_education_dom,
				professional_certificate_dom
				// pcb_dom,
			]).draw();

		});

		
	}
</script>