<?php

if (!defined('ABSPATH')) {
	exit; // Exit if accessed directly
}

use DebugLogViewer\Admin\Controllers\LogController;

$dbg_lv_log_controller = new LogController();
$dbg_lv_path           = $dbg_lv_log_controller->getLogFilePath();
$dbg_lv_current_tab    = isset($_GET['tab']) ? sanitize_text_field(wp_unslash($_GET['tab'])) : 'log-view';
?>

<div class="log-path-display ph-no-capture">
	<div class="log-path-text">
		<span>
			<?php echo esc_html($dbg_lv_path); ?>
		</span>
	</div>

	<div class="log-path-icons">
		<!-- Popover triggers will be generated by JavaScript -->
	</div>
</div>

<div class="table-wrapper">
	<div class="right-subheader">
		<div class="togglers-group mt-3 mb-4">
			<!-- Debug Mode -->
			<div class="log-info-block form-switch">
				<input
					id="dbg_lv_toggle_debug_mode"
					type="checkbox"
					<?php checked(WP_DEBUG, true); ?>
					name="debug_mode"
					class="form-check-input" />
				<label class="form-check-label" for="dbg_lv_toggle_debug_mode"><?php esc_html_e('Debug mode', 'debug-log-viewer'); ?></label>
			</div>

			<!-- Debug Scripts -->
			<div class="log-info-block form-switch">
				<input
					id="dbg_lv_toggle_debug_scripts"
					type="checkbox"
					<?php checked(SCRIPT_DEBUG, true); ?>
					name="debug_scripts"
					class="form-check-input" />
				<label class="form-check-label" for="dbg_lv_toggle_debug_scripts"><?php esc_html_e('Debug scripts', 'debug-log-viewer'); ?></label>
			</div>

			<!-- Log in File -->
			<div class="log-info-block form-switch">
				<?php
				$dbg_lv_is_custom_path = LogController::isCustomLoggingPath();
				$dbg_lv_is_disabled    = $dbg_lv_is_custom_path;
				$dbg_lv_is_checked     = $dbg_lv_is_custom_path || in_array(WP_DEBUG_LOG, [1, true, '1', 'true'], true) ? 'checked' : '';
				?>
				<input
					id="dbg_lv_toggle_log_in_file"
					<?php disabled($dbg_lv_is_disabled); ?>
					type="checkbox"
					<?php echo esc_attr($dbg_lv_is_checked); ?>
					name="log_in_file"
					class="form-check-input" />
				<label class="form-check-label" for="dbg_lv_toggle_log_in_file"><?php esc_html_e('Log in file', 'debug-log-viewer'); ?></label>
			</div>

			<!-- Display Errors -->
			<div class="log-info-block form-switch">
				<input
					id="dbg_lv_toggle_display_errors"
					type="checkbox"
					<?php checked(WP_DEBUG_DISPLAY, true); ?>
					name="display_errors"
					class="form-check-input" />
				<label class="form-check-label" for="dbg_lv_toggle_display_errors"><?php esc_html_e('Display errors', 'debug-log-viewer'); ?></label>
			</div>
		</div>
		<div class="search-input-wrapper">
			<i class="fa-solid fa-magnifying-glass search-icon"></i>
			<input type="search" placeholder="<?php esc_attr_e('Search in log...', 'debug-log-viewer') ?>" class="text-input search-input">
		</div>
	</div>

	<div id="dbg_lv_log-table_wrapper">
		<div class="modal" tabindex="-1">
			<div class="modal-dialog modal-lg modal-dialog-centered">
				<div class="modal-content">
					<div class="modal-body"></div>
				</div>
			</div>
		</div>
		<table id="dbg_lv_log-table" class="display striped" style="width:100%">
			<thead>
				<tr>
					<th><?php esc_html_e('Timestamp', 'debug-log-viewer'); ?></th>
					<th><?php esc_html_e('Type', 'debug-log-viewer'); ?></th>
					<th><?php esc_html_e('Datetime', 'debug-log-viewer'); ?></th>
					<th><?php esc_html_e('Description', 'debug-log-viewer'); ?></th>
					<th><?php esc_html_e('File', 'debug-log-viewer'); ?></th>
					<th><?php esc_html_e('Line', 'debug-log-viewer'); ?></th>
				</tr>
			</thead>
		</table>

	</div>
</div>
