<?php
/**
 * Free-tier admin dashboard: submissions list + basic settings.
 *
 * @package Briefify
 */

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

/**
 * Class Briefify_Admin
 */
class Briefify_Admin {

	/**
	 * @var Briefify_Email
	 */
	private $email;

	/**
	 * Constructor.
	 *
	 * @param Briefify_Email $email Email handler instance (used by the "send test email" action).
	 */
	public function __construct( Briefify_Email $email ) {
		$this->email = $email;

		add_action( 'admin_menu', array( $this, 'register_menu' ) );
		add_action( 'admin_init', array( $this, 'register_settings' ) );
		add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
		add_action( 'add_meta_boxes', array( $this, 'register_meta_box' ) );
		add_action( 'wp_ajax_briefify_send_test_email', array( $this, 'handle_send_test_email' ) );
	}

	/**
	 * Register the top-level "NR Brief Builder" admin menu.
	 */
	public function register_menu() {
		add_menu_page(
			__( 'NR Brief Builder', 'nr-brief-builder' ),
			__( 'NR Brief Builder', 'nr-brief-builder' ),
			'edit_posts',
			'nr-brief-builder',
			array( $this, 'render_dashboard' ),
			'dashicons-forms',
			26
		);

		add_submenu_page(
			'nr-brief-builder',
			__( 'Dashboard', 'nr-brief-builder' ),
			__( 'Dashboard', 'nr-brief-builder' ),
			'edit_posts',
			'nr-brief-builder',
			array( $this, 'render_dashboard' )
		);

		add_submenu_page(
			'nr-brief-builder',
			__( 'Brief submissions', 'nr-brief-builder' ),
			__( 'Submissions', 'nr-brief-builder' ),
			'edit_posts',
			'edit.php?post_type=' . BRIEFIFY_CPT
		);

		add_submenu_page(
			'nr-brief-builder',
			__( 'NR Brief Builder Settings', 'nr-brief-builder' ),
			__( 'Settings', 'nr-brief-builder' ),
			'manage_options',
			'briefify-settings',
			array( $this, 'render_settings' )
		);
	}

	/**
	 * Register the settings API fields.
	 */
	public function register_settings() {
		register_setting(
			'briefify_settings_group',
			'briefify_settings',
			array( $this, 'sanitize_settings' )
		);
	}

	/**
	 * Sanitize the settings option on save.
	 *
	 * @param array $input Raw input.
	 * @return array
	 */
	public function sanitize_settings( $input ) {
		$output = array();

		$output['notification_email'] = isset( $input['notification_email'] ) && is_email( $input['notification_email'] )
			? sanitize_email( $input['notification_email'] )
			: get_option( 'admin_email' );

		$output['default_template'] = isset( $input['default_template'] ) ? sanitize_key( $input['default_template'] ) : 'web';

		// Checkbox: absent from $_POST entirely when unchecked.
		$output['send_confirmation'] = ! empty( $input['send_confirmation'] );

		$output['confirmation_subject'] = isset( $input['confirmation_subject'] )
			? sanitize_text_field( $input['confirmation_subject'] )
			: '';

		return $output;
	}

	/**
	 * Enqueue admin assets only on NR Brief Builder screens.
	 *
	 * @param string $hook Current admin page hook.
	 */
	public function enqueue_assets( $hook ) {
		$screen = get_current_screen();
		$is_briefify_screen = $screen && (
			BRIEFIFY_CPT === $screen->post_type ||
			false !== strpos( $screen->id, 'nr-brief-builder' )
		);

		if ( ! $is_briefify_screen ) {
			return;
		}

		wp_enqueue_style( 'briefify-admin', BRIEFIFY_PLUGIN_URL . 'assets/css/briefify-admin.css', array(), BRIEFIFY_VERSION );
		wp_enqueue_script( 'briefify-admin', BRIEFIFY_PLUGIN_URL . 'assets/js/briefify-admin.js', array(), BRIEFIFY_VERSION, true );

		// The settings screen's live template preview reuses the front-end
		// stepper's own CSS (type cards, tokens) so the preview is pixel-true
		// to what visitors actually see. Matched by suffix rather than the
		// full screen ID, since the parent (top-level menu) slug prefix
		// isn't a value this code should have to hardcode.
		if ( false !== strpos( $screen->id, 'briefify-settings' ) ) {
			wp_enqueue_style( 'briefify-front', BRIEFIFY_PLUGIN_URL . 'assets/css/briefify-front.css', array(), BRIEFIFY_VERSION );
		}

		wp_localize_script(
			'briefify-admin',
			'briefifyAdminData',
			array(
				'ajaxUrl' => admin_url( 'admin-ajax.php' ),
				'nonce'   => wp_create_nonce( 'briefify_admin_nonce' ),
				'i18n'    => array(
					'sending'        => __( 'Sending…', 'nr-brief-builder' ),
					'sent'           => __( 'Email sent!', 'nr-brief-builder' ),
					'error'          => __( 'Failed to send. Check the site’s mail configuration.', 'nr-brief-builder' ),
					'noEmail'        => __( 'Please set a notification email first.', 'nr-brief-builder' ),
					'sendTest'       => __( 'Send a test email', 'nr-brief-builder' ),
					'copied'         => __( 'Copied!', 'nr-brief-builder' ),
					'copiedAnnounce' => __( 'Shortcode copied to clipboard.', 'nr-brief-builder' ),
				),
			)
		);
	}

	/**
	 * Find the first published page/post using the [nr_brief] shortcode, for the
	 * settings page "preview" link.
	 *
	 * @return string|null Permalink, or null if no such content exists yet.
	 */
	private function get_preview_url() {
		$query = new WP_Query(
			array(
				'post_type'      => array( 'page', 'post' ),
				'post_status'    => 'publish',
				's'              => '[nr_brief',
				'posts_per_page' => 1,
				'no_found_rows'  => true,
			)
		);

		if ( ! $query->have_posts() ) {
			return null;
		}

		return get_permalink( $query->posts[0] );
	}

	/**
	 * AJAX: send a test email to the configured notification address.
	 */
	public function handle_send_test_email() {
		check_ajax_referer( 'briefify_admin_nonce', 'nonce' );

		if ( ! current_user_can( 'manage_options' ) ) {
			wp_send_json_error( array( 'message' => __( 'This action is not allowed.', 'nr-brief-builder' ) ) );
		}

		$settings = get_option( 'briefify_settings', array() );
		$to       = ! empty( $settings['notification_email'] ) ? $settings['notification_email'] : get_option( 'admin_email' );

		if ( ! is_email( $to ) ) {
			wp_send_json_error( array( 'message' => __( 'Invalid email address.', 'nr-brief-builder' ) ) );
		}

		$sent = $this->email->send_test( $to );

		if ( $sent ) {
			// Tracked for the dashboard "getting started" checklist.
			update_option( 'briefify_test_email_sent', current_time( 'mysql' ) );

			/* translators: %s: recipient email address. */
			wp_send_json_success( array( 'message' => sprintf( __( 'Test email sent to %s.', 'nr-brief-builder' ), $to ) ) );
		}

		wp_send_json_error( array( 'message' => __( 'Sending failed. Check the site’s mail configuration (SMTP, etc.).', 'nr-brief-builder' ) ) );
	}

	/**
	 * Register a read-only meta box showing the full brief on the submission edit screen.
	 */
	public function register_meta_box() {
		add_meta_box(
			'briefify_brief_details',
			__( 'Brief details', 'nr-brief-builder' ),
			array( $this, 'render_meta_box' ),
			BRIEFIFY_CPT,
			'normal',
			'high'
		);
	}

	/**
	 * Render the brief details meta box.
	 *
	 * @param WP_Post $post Current post.
	 */
	public function render_meta_box( $post ) {
		$data = get_post_meta( $post->ID, '_briefify_data', true );

		if ( ! is_array( $data ) || empty( $data ) ) {
			echo '<p>' . esc_html__( 'No data available.', 'nr-brief-builder' ) . '</p>';
			return;
		}

		// Real, translatable labels from the template config — not a guess
		// derived from the raw internal field key. Submissions created before
		// this field was introduced fall back to the "web" template.
		$template_key = get_post_meta( $post->ID, '_briefify_template_key', true );
		$field_labels = Briefify_Form::get_field_labels( $template_key ? $template_key : 'web' );

		echo '<table class="widefat briefify-brief-table"><tbody>';
		foreach ( $data as $key => $value ) {
			$label = isset( $field_labels[ $key ] ) ? $field_labels[ $key ] : ucfirst( str_replace( '_', ' ', $key ) );
			$text  = is_array( $value ) ? implode( ', ', $value ) : $value;

			if ( '' === $text ) {
				continue;
			}

			echo '<tr>';
			echo '<th style="width:200px;">' . esc_html( $label ) . '</th>';
			echo '<td>' . nl2br( esc_html( $text ) ) . '</td>';
			echo '</tr>';
		}
		echo '</tbody></table>';

		// Pro (includes/pro/class-briefify-pro-status.php) hooks this to add
		// a status field below the read-only brief details. No-op in the
		// free version.
		do_action( 'briefify_meta_box_after_details', $post );
	}

	/**
	 * Render the dashboard page: quick stats, recent submissions, a getting
	 * started checklist, and the shortcode helper.
	 */
	public function render_dashboard() {
		$counts   = wp_count_posts( BRIEFIFY_CPT );
		$total    = isset( $counts->publish ) ? (int) $counts->publish : 0;
		$settings = get_option( 'briefify_settings', array() );

		$recent = new WP_Query(
			array(
				'post_type'      => BRIEFIFY_CPT,
				'post_status'    => 'publish',
				'posts_per_page' => 5,
				'orderby'        => 'date',
				'order'          => 'DESC',
				'no_found_rows'  => true,
			)
		);

		$checklist = array(
			array(
				'label' => __( 'Add the [nr_brief] shortcode to a published page', 'nr-brief-builder' ),
				'done'  => (bool) $this->get_preview_url(),
			),
			array(
				'label' => __( 'Set a notification email', 'nr-brief-builder' ),
				'done'  => ! empty( $settings['notification_email'] ) && is_email( $settings['notification_email'] ),
			),
			array(
				'label' => __( 'Send a test email', 'nr-brief-builder' ),
				'done'  => (bool) get_option( 'briefify_test_email_sent' ),
			),
		);
		?>
		<div class="wrap briefify-admin-wrap">
			<div class="screen-reader-text" aria-live="polite" aria-atomic="true" data-briefify-live-region></div>

			<div class="briefify-admin-header">
				<h1><?php esc_html_e( 'NR Brief Builder', 'nr-brief-builder' ); ?></h1>
				<p><?php esc_html_e( 'Smart client brief builder', 'nr-brief-builder' ); ?></p>
			</div>

			<div class="briefify-admin-cards">
				<div class="briefify-admin-card">
					<span class="briefify-admin-card-icon">
						<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="22 12 16 12 14 15 10 15 8 12 2 12"/><path d="M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11Z"/></svg>
					</span>
					<span class="briefify-admin-card-value"><?php echo esc_html( $total ); ?></span>
					<span class="briefify-admin-card-label"><?php esc_html_e( 'Submissions received', 'nr-brief-builder' ); ?></span>
				</div>
				<div class="briefify-admin-card">
					<span class="briefify-admin-card-icon"><?php echo Briefify_Form::icon( 'layers' ); // phpcs:ignore WordPress.Security.EscapeOutput -- static SVG, not user input. ?></span>
					<span class="briefify-admin-card-value">3</span>
					<span class="briefify-admin-card-label"><?php esc_html_e( 'Available templates', 'nr-brief-builder' ); ?></span>
				</div>
			</div>

			<?php
			// Pro (includes/pro/class-briefify-pro-status.php) hooks this to
			// add a status-breakdown panel here. No-op in the free version.
			do_action( 'briefify_dashboard_after_cards' );
			?>

			<div class="briefify-admin-row">
				<div class="briefify-admin-panel briefify-admin-panel--recent">
					<div class="briefify-panel-body">
						<h2><?php esc_html_e( 'Recent submissions', 'nr-brief-builder' ); ?></h2>
						<?php if ( $recent->have_posts() ) : ?>
							<ul class="briefify-admin-recent-list">
								<?php
								foreach ( $recent->posts as $submission ) :
									$data           = get_post_meta( $submission->ID, '_briefify_data', true );
									$client_name    = ( is_array( $data ) && ! empty( $data['name'] ) ) ? $data['name'] : $submission->post_title;
									$template_label = get_post_meta( $submission->ID, '_briefify_template', true );
									?>
									<li class="briefify-admin-recent-item">
										<a href="<?php echo esc_url( get_edit_post_link( $submission->ID ) ); ?>">
											<span class="briefify-admin-recent-name"><?php echo esc_html( $client_name ); ?></span>
											<?php if ( $template_label ) : ?>
												<span class="briefify-admin-recent-template"><?php echo esc_html( $template_label ); ?></span>
											<?php endif; ?>
											<span class="briefify-admin-recent-date"><?php echo esc_html( get_the_date( '', $submission ) ); ?></span>
										</a>
									</li>
								<?php endforeach; ?>
							</ul>
						<?php else : ?>
							<p class="description"><?php esc_html_e( 'No submissions yet.', 'nr-brief-builder' ); ?></p>
							<p><?php esc_html_e( 'Add the shortcode to a page to start receiving briefs — it only takes a minute.', 'nr-brief-builder' ); ?></p>
						<?php endif; ?>
					</div>
					<div class="briefify-panel-footer">
						<?php if ( $recent->have_posts() ) : ?>
							<a href="<?php echo esc_url( admin_url( 'edit.php?post_type=' . BRIEFIFY_CPT ) ); ?>"><?php esc_html_e( 'View all submissions →', 'nr-brief-builder' ); ?></a>
						<?php else : ?>
							<a class="button button-primary" href="<?php echo esc_url( admin_url( 'admin.php?page=briefify-settings#briefify-shortcode-generator' ) ); ?>"><?php esc_html_e( 'Get your shortcode →', 'nr-brief-builder' ); ?></a>
						<?php endif; ?>
					</div>
				</div>

				<div class="briefify-admin-panel briefify-admin-panel--checklist">
					<div class="briefify-panel-body">
						<h2><?php esc_html_e( 'Getting started', 'nr-brief-builder' ); ?></h2>
						<ul class="briefify-admin-checklist">
							<?php foreach ( $checklist as $item ) : ?>
								<li class="<?php echo $item['done'] ? 'is-done' : ''; ?>">
									<span class="briefify-checklist-dot" aria-hidden="true"><?php echo $item['done'] ? '✓' : ''; ?></span>
									<?php echo esc_html( $item['label'] ); ?>
								</li>
							<?php endforeach; ?>
						</ul>
					</div>
				</div>
			</div>

			<div class="briefify-admin-panel">
				<h2><?php esc_html_e( 'Using the form', 'nr-brief-builder' ); ?></h2>
				<p><?php esc_html_e( 'Add this shortcode to any page or widget to display the form:', 'nr-brief-builder' ); ?></p>
				<p class="briefify-admin-hint"><?php esc_html_e( 'A shortcode is a small piece of code you paste into a page — no coding needed, just copy and paste.', 'nr-brief-builder' ); ?></p>
				<button type="button" class="briefify-admin-shortcode" data-briefify-copy>[nr_brief template="web"]</button>
				<p class="briefify-admin-hint"><?php esc_html_e( 'Available templates: web, graphisme, coaching.', 'nr-brief-builder' ); ?></p>
			</div>

			<p>
				<a class="button button-primary" href="<?php echo esc_url( admin_url( 'edit.php?post_type=' . BRIEFIFY_CPT ) ); ?>"><?php esc_html_e( 'View submissions', 'nr-brief-builder' ); ?></a>
				<a class="button" href="<?php echo esc_url( admin_url( 'admin.php?page=briefify-settings' ) ); ?>"><?php esc_html_e( 'Settings', 'nr-brief-builder' ); ?></a>
			</p>
		</div>
		<?php
	}

	/**
	 * Render a compact, non-interactive preview of one template's first
	 * step (its type grid), used side-by-side with the shortcode generator.
	 *
	 * @param array $templates Full template configs, keyed by template key.
	 */
	private function render_template_previews( $templates ) {
		$first = true;
		?>
		<div class="briefify-admin-preview-tabs" role="tablist" aria-label="<?php esc_attr_e( 'Template preview', 'nr-brief-builder' ); ?>" data-briefify-preview-tabs>
			<?php foreach ( $templates as $key => $template ) : ?>
				<button
					type="button"
					role="tab"
					id="briefify-tab-<?php echo esc_attr( $key ); ?>"
					aria-selected="<?php echo $first ? 'true' : 'false'; ?>"
					aria-controls="briefify-tabpanel-<?php echo esc_attr( $key ); ?>"
					tabindex="<?php echo $first ? '0' : '-1'; ?>"
					class="briefify-admin-preview-tab<?php echo $first ? ' is-active' : ''; ?>"
					data-briefify-preview-tab="<?php echo esc_attr( $key ); ?>"
				><?php echo esc_html( $template['label'] ); ?></button>
				<?php $first = false; ?>
			<?php endforeach; ?>
		</div>
		<?php
		$first = true;
		foreach ( $templates as $key => $template ) :
			$type_field = $template['steps']['type']['fields'][0];
			$options    = array_slice( $type_field['options'], 0, 3 );
			?>
			<div
				class="briefify-wrap briefify-admin-preview-instance<?php echo $first ? ' is-active' : ''; ?>"
				id="briefify-tabpanel-<?php echo esc_attr( $key ); ?>"
				role="tabpanel"
				aria-labelledby="briefify-tab-<?php echo esc_attr( $key ); ?>"
				tabindex="0"
				data-briefify-preview-instance="<?php echo esc_attr( $key ); ?>"
				<?php echo $first ? '' : 'hidden'; ?>
			>
				<p class="briefify-admin-preview-title"><?php echo esc_html( $template['steps']['type']['title'] ); ?></p>
				<div class="briefify-type-grid briefify-admin-preview-grid">
					<?php foreach ( $options as $option ) : ?>
						<div class="briefify-type-card briefify-admin-preview-card">
							<span class="briefify-type-icon"><?php echo Briefify_Form::icon( $option['icon'] ); // phpcs:ignore WordPress.Security.EscapeOutput -- static SVG, not user input. ?></span>
							<span class="briefify-type-label"><?php echo esc_html( $option['label'] ); ?></span>
							<span class="briefify-type-sub"><?php echo esc_html( $option['sub'] ); ?></span>
						</div>
					<?php endforeach; ?>
				</div>
			</div>
			<?php
			$first = false;
		endforeach;
	}

	/**
	 * Render the settings page.
	 */
	public function render_settings() {
		$settings = wp_parse_args(
			get_option( 'briefify_settings', array() ),
			array(
				'notification_email'   => get_option( 'admin_email' ),
				'default_template'     => 'web',
				'send_confirmation'    => true,
				'confirmation_subject' => '',
			)
		);

		$preview_url = $this->get_preview_url();
		$templates   = Briefify_Form::get_templates();
		?>
		<div class="wrap briefify-admin-wrap">
			<div class="screen-reader-text" aria-live="polite" aria-atomic="true" data-briefify-live-region></div>

			<div class="briefify-admin-header">
				<h1><?php esc_html_e( 'NR Brief Builder Settings', 'nr-brief-builder' ); ?></h1>
			</div>

			<div class="briefify-admin-panel">
				<h2><?php esc_html_e( 'Form preview', 'nr-brief-builder' ); ?></h2>
				<?php if ( $preview_url ) : ?>
					<p><?php esc_html_e( 'Open a page containing the [nr_brief] shortcode the way a visitor would see it.', 'nr-brief-builder' ); ?></p>
					<p><a class="button button-primary" href="<?php echo esc_url( $preview_url ); ?>" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'Preview the form ↗', 'nr-brief-builder' ); ?></a></p>
				<?php else : ?>
					<p class="description"><?php esc_html_e( 'No published page contains the [nr_brief] shortcode yet. Add it to a page to enable the preview.', 'nr-brief-builder' ); ?></p>
				<?php endif; ?>
			</div>

			<div class="briefify-admin-row">
				<div class="briefify-admin-panel briefify-admin-panel--shortcode" id="briefify-shortcode-generator">
					<div class="briefify-panel-body">
						<h2><?php esc_html_e( 'Shortcode generator', 'nr-brief-builder' ); ?></h2>
						<p class="briefify-admin-hint"><?php esc_html_e( 'A shortcode is a small piece of code you paste into a page to display the form. Just copy it below — no coding needed.', 'nr-brief-builder' ); ?></p>
						<p>
							<label for="briefify_shortcode_template"><?php esc_html_e( 'Template', 'nr-brief-builder' ); ?></label><br>
							<select id="briefify_shortcode_template" data-briefify-shortcode-select>
								<?php foreach ( $templates as $key => $template ) : ?>
									<option value="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $template['label'] ); ?></option>
								<?php endforeach; ?>
							</select>
						</p>
						<p class="briefify-admin-hint"><?php esc_html_e( 'A template is a ready-made set of questions — pick the one that matches your business.', 'nr-brief-builder' ); ?></p>
						<p>
							<button type="button" class="briefify-admin-shortcode" data-briefify-copy data-briefify-shortcode-output>[nr_brief template="web"]</button>
						</p>
						<p class="briefify-admin-hint"><?php esc_html_e( 'Click the shortcode to copy it.', 'nr-brief-builder' ); ?></p>
					</div>
					<div class="briefify-panel-footer">
						<p class="briefify-admin-hint">
							<?php
							$default_key   = isset( $templates[ $settings['default_template'] ] ) ? $settings['default_template'] : 'web';
							$default_label = $templates[ $default_key ]['label'];
							/* translators: %s: name of the default template configured below, under Notifications. */
							printf( esc_html__( 'Without a template attribute, [nr_brief] uses your default template — currently “%s”.', 'nr-brief-builder' ), esc_html( $default_label ) );
							?>
						</p>
					</div>
				</div>

				<div class="briefify-admin-panel briefify-admin-panel--preview">
					<div class="briefify-panel-body">
						<h2><?php esc_html_e( 'Template preview', 'nr-brief-builder' ); ?></h2>
						<?php $this->render_template_previews( $templates ); ?>
					</div>
				</div>
			</div>

			<form method="post" action="options.php" class="briefify-admin-panel">
				<?php settings_fields( 'briefify_settings_group' ); ?>

				<h2><?php esc_html_e( 'Notifications', 'nr-brief-builder' ); ?></h2>

				<table class="form-table" role="presentation">
					<tr>
						<th scope="row"><label for="briefify_notification_email"><?php esc_html_e( 'Notification email', 'nr-brief-builder' ); ?></label></th>
						<td>
							<input type="email" id="briefify_notification_email" name="briefify_settings[notification_email]" value="<?php echo esc_attr( $settings['notification_email'] ); ?>" class="regular-text">
							<p class="description"><?php esc_html_e( 'Address that receives incoming briefs.', 'nr-brief-builder' ); ?></p>
							<p>
								<button type="button" class="button" data-briefify-send-test><?php esc_html_e( 'Send a test email', 'nr-brief-builder' ); ?></button>
								<span class="briefify-admin-test-result" data-briefify-send-test-result></span>
							</p>
						</td>
					</tr>
					<tr>
						<th scope="row"><label for="briefify_default_template"><?php esc_html_e( 'Default template', 'nr-brief-builder' ); ?></label></th>
						<td>
							<select id="briefify_default_template" name="briefify_settings[default_template]">
								<?php foreach ( $templates as $key => $template ) : ?>
									<option value="<?php echo esc_attr( $key ); ?>" <?php selected( $settings['default_template'], $key ); ?>><?php echo esc_html( $template['label'] ); ?></option>
								<?php endforeach; ?>
							</select>
						</td>
					</tr>
					<tr>
						<th scope="row"><?php esc_html_e( 'Prospect confirmation email', 'nr-brief-builder' ); ?></th>
						<td>
							<label for="briefify_send_confirmation">
								<input type="checkbox" id="briefify_send_confirmation" name="briefify_settings[send_confirmation]" value="1" <?php checked( $settings['send_confirmation'] ); ?>>
								<?php esc_html_e( 'Send an automatic confirmation email to the prospect after submission', 'nr-brief-builder' ); ?>
							</label>
						</td>
					</tr>
					<tr>
						<th scope="row"><label for="briefify_confirmation_subject"><?php esc_html_e( 'Confirmation email subject', 'nr-brief-builder' ); ?></label></th>
						<td>
							<input type="text" id="briefify_confirmation_subject" name="briefify_settings[confirmation_subject]" value="<?php echo esc_attr( $settings['confirmation_subject'] ); ?>" class="regular-text" placeholder="<?php esc_attr_e( 'Your brief has been received', 'nr-brief-builder' ); ?>">
							<p class="description"><?php esc_html_e( 'Leave blank to use the default subject.', 'nr-brief-builder' ); ?></p>
						</td>
					</tr>
				</table>

				<?php submit_button(); ?>
			</form>

			<?php
			// Pro (includes/pro/class-briefify-pro-branding.php) hooks this to
			// add its own "Branding" panel + form below. No-op in the free
			// version.
			do_action( 'briefify_settings_after_notifications' );
			?>
		</div>
		<?php
	}
}
