public function index(ClientSurvey $client_survey, DatatableSearch $request): JsonResponse 	{ 		$applicants = $client_survey 		->applicants() 		->select([ 			'id', 			'control_number', 			'answer_combination', 			'default_language', 			'filled', 			'is_offline', 			'active', 			'survey_filling_started', 			'survey_filling_finished', 		]) 		->withExists('latestMetadata');  		return DataTables::eloquent($applicants) 		->order(function ($query) use ($request) { 			$order_array = $request->get('order') ?? []; 			$columns_array = $request->columns;  			if (!empty($order_array)) { 				foreach (array_column($order_array, 'dir', 'column') as $column_index => $order_direction) { 					$query->orderBy($columns_array[$column_index]['name'], $order_direction); 				} 			} else { 				$query 				->orderBy('is_offline') 				->latest(); 			} 		}) 		->filter(function ($query) use ($request) { 			$search_term = $request->search['value'] ?? null; 			$show_not_completed = $request->boolean('show_not_completed'); 			$answer_combination = $request->answer_combination;  			if ($search_term) { 				$query->search($search_term); 			}  			$query->when(!$show_not_completed, function ($query) { 				$query->final(); 			}) 			->when($show_not_completed, function ($query) { 				$query->hasNotCompletedSurveyOrIsDraft(); 			})->when($answer_combination, function ($query) use ($answer_combination) { 				$query->where('answer_combination', $answer_combination); 			}); 		}) 		->addColumn('metadata', function (Applicant $row) { 			$applicant_metadata_modal = json_encode([ 				'api' => route('api.applicants.metadata', [$row->id]), 				'token' => auth()->user()->token(), 				'title' => __('applicants.metadata'), 			]);  			if ($row->latest_metadata_exists) { 				return '<a href="#" title="' . __('applicants.metadata') . '" data-modal-data=\'' . $applicant_metadata_modal . '\' data-toggle="modal" data-target="#applicant-metadata-modal" class="text-hover-primary"> 					<i class="fas fa-code"></i> 				</a>'; 			}  			return '-'; 		}) 		->addColumn('control_number', function (Applicant $row) { 			return '<span class="applicant-survey-code-table-cell">' . $row->control_number . '</span>'; 		}) 		->addColumn('answer_combination', function (Applicant $row) { 			return '<span class="applicant-survey-code-table-cell">' . $row->answer_combination . '</span>'; 		}) 		->addColumn('filled', function (Applicant $row) { 			$state = $row->filled ? 'success' : 'danger'; 			$label = $row->filled ? __('global.yes') : __('global.no');  			return '<span class="label label-' . $state . ' label-inline">' . $label . '</span>'; 		}) 		->addColumn('is_offline', function (Applicant $row) { 			$state = $row->is_offline ? 'success' : 'danger'; 			$label = $row->is_offline ? __('global.yes') : __('global.no');  			return '<span class="label label-' . $state . ' label-inline">' . $label . '</span>'; 		}) 		->addColumn('active', function (Applicant $row) { 			$state = $row->active ? 'success' : 'danger'; 			$label = $row->active ? __('global.yes') : __('global.no');  			return '<span class="label label-' . $state . ' label-inline">' . $label . '</span>'; 		}) 		->addColumn('edit_ordered', function (Applicant $row) { 			return '<a href="' . route('applicant-surveys-puls.edit', ['id' => $row->id]) . '" title="' . __('global.edit') . '" data-container="body" data-toggle="tooltip" data-placement="left" class="btn btn-icon btn-light btn-hover-primary btn-sm"> 				<i class="fa fa-edit text-primary"></i> 			</a>'; 		}) 		->addColumn('edit_scrambled', function (Applicant $row) { 			return '<a href="' . route('applicant-surveys-puls.edit-scrambled', ['id' => $row->id]) . '" title="' . __('global.edit') . '" data-container="body" data-toggle="tooltip" data-placement="left" class="btn btn-icon btn-light btn-hover-primary btn-sm"> 				<i class="fa fa-edit text-primary"></i> 			</a>'; 		}) 		->addColumn('survey_filling_started', function (Applicant $row) { 			return formatLocalTimestamp($row->survey_filling_started); 		}) 		->addColumn('survey_filling_finished', function (Applicant $row) { 			return formatLocalTimestamp($row->survey_filling_finished); 		}) 		->addColumn('checkbox', function (Applicant $row) { 			return '<label class="checkbox checkbox-single checkbox-primary"> 				<input type="checkbox" name="values[]" value="' . $row->id . '" class="options-form"><span></span> 			</label>'; 		}) 		->rawColumns(['metadata', 'filled', 'has_conflicting_answers', 'control_number', 'answer_combination', 'is_offline', 'active', 'edit_ordered', 'edit_scrambled', 'survey_filling_started', 'survey_filling_finished', 'checkbox']) 		->toJson(); 	}