<?php
/**
 * Single attendance record detail template.
 *
 * @package MerchantKits\AttendanceManager
 *
 * @var array $record Attendance row.
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( empty( $record ) ) {
	echo '<div class="wrap"><p>' . esc_html__( 'Record not found.', 'merchantkits-attendance-manager' ) . '</p></div>';
	return;
}

$employee = MKAM_Employee::get( $record['employee_id'] );
$shift    = ( $employee && $employee['shift_id'] ) ? MKAM_Shift::get( $employee['shift_id'] ) : null;

$rows = array(
	__( 'Employee', 'merchantkits-attendance-manager' )      => $employee ? MKAM_Employee::full_name( $employee ) : '—',
	__( 'Date', 'merchantkits-attendance-manager' )          => $record['date'],
	__( 'Clock In', 'merchantkits-attendance-manager' )      => $record['clock_in'] ? $record['clock_in'] : '—',
	__( 'Clock Out', 'merchantkits-attendance-manager' )     => $record['clock_out'] ? $record['clock_out'] : '—',
	__( 'Clock In IP', 'merchantkits-attendance-manager' )   => $record['clock_in_ip'] ? $record['clock_in_ip'] : '—',
	__( 'Clock Out IP', 'merchantkits-attendance-manager' )  => $record['clock_out_ip'] ? $record['clock_out_ip'] : '—',
	__( 'Clock In Location', 'merchantkits-attendance-manager' )  => $record['clock_in_location'] ? $record['clock_in_location'] : '—',
	__( 'Clock Out Location', 'merchantkits-attendance-manager' ) => $record['clock_out_location'] ? $record['clock_out_location'] : '—',
	__( 'Total Hours', 'merchantkits-attendance-manager' )   => null !== $record['total_hours'] ? $record['total_hours'] : '—',
	__( 'Overtime Hours', 'merchantkits-attendance-manager' ) => null !== $record['overtime_hours'] ? $record['overtime_hours'] : '—',
	__( 'Late (minutes)', 'merchantkits-attendance-manager' ) => $record['late_minutes'],
	__( 'Early Leave (minutes)', 'merchantkits-attendance-manager' ) => $record['early_leave_minutes'],
	__( 'Status', 'merchantkits-attendance-manager' )        => ucwords( str_replace( '_', ' ', $record['status'] ) ),
	__( 'Manual Entry', 'merchantkits-attendance-manager' )  => $record['is_manual_entry'] ? __( 'Yes', 'merchantkits-attendance-manager' ) : __( 'No', 'merchantkits-attendance-manager' ),
	__( 'Expected Shift', 'merchantkits-attendance-manager' ) => $shift ? $shift['name'] . ' (' . $shift['start_time'] . '–' . $shift['end_time'] . ')' : '—',
);
?>
<div class="wrap">
	<h1><?php esc_html_e( 'Attendance Detail', 'merchantkits-attendance-manager' ); ?></h1>
	<a class="button" href="<?php echo esc_url( admin_url( 'admin.php?page=mkam-attendance' ) ); ?>">&larr; <?php esc_html_e( 'Back to list', 'merchantkits-attendance-manager' ); ?></a>

	<table class="widefat striped" style="margin-top:1em;max-width:640px;">
		<tbody>
			<?php foreach ( $rows as $label => $val ) : ?>
				<tr>
					<th style="width:200px;"><?php echo esc_html( $label ); ?></th>
					<td><?php echo esc_html( $val ); ?></td>
				</tr>
			<?php endforeach; ?>
			<?php if ( ! empty( $record['clock_in_note'] ) ) : ?>
				<tr><th><?php esc_html_e( 'Clock In Note', 'merchantkits-attendance-manager' ); ?></th><td><?php echo esc_html( $record['clock_in_note'] ); ?></td></tr>
			<?php endif; ?>
			<?php if ( ! empty( $record['clock_out_note'] ) ) : ?>
				<tr><th><?php esc_html_e( 'Clock Out Note', 'merchantkits-attendance-manager' ); ?></th><td><?php echo esc_html( $record['clock_out_note'] ); ?></td></tr>
			<?php endif; ?>
		</tbody>
	</table>
</div>
