<?php
/**
 * Notification email sent to the site owner with the full structured brief.
 *
 * Available variables: $post_id, $data (array), $config (array).
 *
 * @package Briefify
 */

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

$edit_link = admin_url( 'post.php?post=' . (int) $post_id . '&action=edit' );

// Fields already shown separately in the header.
$skip = array( 'name', 'email', 'project_type' );

// Real, translatable labels from the template config — not a guess derived
// from the raw internal field key (e.g. "visitor_action" -> "Visitor action").
$field_labels = Briefify_Form::get_field_labels_from_config( $config );
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body style="margin:0;padding:0;background:#f4f6fa;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;">
	<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background:#f4f6fa;padding:32px 16px;">
		<tr>
			<td align="center">
				<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="max-width:560px;background:#0a1628;border-radius:16px;overflow:hidden;">
					<tr>
						<td style="background:linear-gradient(90deg,#2bd4bf,#4f7cff);padding:20px 28px;">
							<span style="color:#04111f;font-weight:700;font-size:16px;letter-spacing:0.02em;">NR Brief Builder</span>
						</td>
					</tr>
					<tr>
						<td style="padding:28px;">
							<h1 style="margin:0 0 6px;color:#f4f8ff;font-size:20px;">
								<?php esc_html_e( 'New brief submission', 'nr-brief-builder' ); ?>
							</h1>
							<p style="margin:0 0 24px;color:#b3c3d7;font-size:13px;">
								<?php echo esc_html( $config['label'] ); ?> &middot; <?php echo esc_html( isset( $data['project_type'] ) ? $data['project_type'] : '' ); ?>
							</p>

							<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background:rgba(43,212,191,0.06);border:1px solid rgba(43,212,191,0.2);border-radius:10px;margin-bottom:20px;">
								<tr>
									<td style="padding:16px 18px;">
										<p style="margin:0 0 4px;color:#b3c3d7;font-size:11px;text-transform:uppercase;letter-spacing:0.08em;"><?php esc_html_e( 'Contact', 'nr-brief-builder' ); ?></p>
										<p style="margin:0;color:#f4f8ff;font-size:14px;font-weight:600;"><?php echo esc_html( $data['name'] ); ?></p>
										<p style="margin:0;color:#f4f8ff;font-size:14px;"><a href="mailto:<?php echo esc_attr( $data['email'] ); ?>" style="color:#2bd4bf;text-decoration:none;"><?php echo esc_html( $data['email'] ); ?></a></p>
										<?php if ( ! empty( $data['company'] ) ) : ?>
											<p style="margin:4px 0 0;color:#b3c3d7;font-size:13px;"><?php echo esc_html( $data['company'] ); ?></p>
										<?php endif; ?>
									</td>
								</tr>
							</table>

							<table role="presentation" width="100%" cellpadding="0" cellspacing="0">
								<?php foreach ( $data as $key => $value ) : ?>
									<?php
									if ( in_array( $key, $skip, true ) || '' === $value || array() === $value ) {
										continue;
									}
									$label = isset( $field_labels[ $key ] ) ? $field_labels[ $key ] : ucfirst( str_replace( '_', ' ', $key ) );
									$text  = is_array( $value ) ? implode( ', ', $value ) : $value;
									?>
									<tr>
										<td style="padding:8px 0;border-bottom:1px solid rgba(255,255,255,0.06);">
											<p style="margin:0 0 2px;color:#b3c3d7;font-size:11px;text-transform:uppercase;letter-spacing:0.06em;"><?php echo esc_html( $label ); ?></p>
											<p style="margin:0;color:#f4f8ff;font-size:14px;"><?php echo nl2br( esc_html( $text ) ); ?></p>
										</td>
									</tr>
								<?php endforeach; ?>
							</table>

							<p style="margin:28px 0 0;">
								<a href="<?php echo esc_url( $edit_link ); ?>" style="display:inline-block;background:linear-gradient(90deg,#2bd4bf,#4f7cff);color:#04111f;text-decoration:none;font-weight:700;font-size:13px;padding:10px 18px;border-radius:8px;">
									<?php esc_html_e( 'View submission', 'nr-brief-builder' ); ?>
								</a>
							</p>
						</td>
					</tr>
					<tr>
						<td style="padding:16px 28px;background:rgba(255,255,255,0.03);">
							<p style="margin:0;color:#b3c3d7;font-size:11px;">
								<?php esc_html_e( 'Sent by NR Brief Builder on', 'nr-brief-builder' ); ?> <?php echo esc_html( wp_parse_url( home_url(), PHP_URL_HOST ) ); ?>
							</p>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
</body>
</html>
