<?php
/**
 * Starter auto-reply email templates.
 *
 * @package SubmissionInbox
 */

namespace SUBIN\AutoReplies;

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

/**
 * Provides ready-made auto-reply template layouts.
 */
class AutoReplyTemplateLibrary {
	/**
	 * Get inline HTML starter templates for the WordPress editor flow.
	 *
	 * @return array<string,array<string,string>>
	 */
	private function inline_html_templates() {
		return array(
			'simple_confirmation'           => array(
				'key'         => 'simple_confirmation',
				'name'        => __( 'Simple Confirmation', 'submission-inbox' ),
				'description' => __( 'A clean confirmation email for general contact forms.', 'submission-inbox' ),
				'subject'     => __( 'We received your message', 'submission-inbox' ),
				'preheader'   => __( 'Thank you for contacting us. We will get back to you soon.', 'submission-inbox' ),
				'html'        => $this->email_shell(
					'#f4f7fb',
					'#ffffff',
					'<h1 style="margin:0 0 18px;color:#172033;font-size:26px;line-height:1.25;">Thank you, {field:name}</h1>
					<p style="margin:0 0 18px;color:#172033;font-size:16px;line-height:1.6;">We received your message and will get back to you soon.</p>
					<div style="margin:24px 0;padding:18px;background:#f8fafc;border:1px solid #d8e2ee;border-radius:12px;">
						<strong style="display:block;margin-bottom:8px;color:#172033;">Your message:</strong>
						<p style="margin:0;color:#172033;font-size:16px;line-height:1.6;">{field:message}</p>
					</div>
					<p style="margin:0 0 18px;color:#64748b;font-size:14px;line-height:1.6;">Submitted via {form_name} on {submission_date}.</p>
					<p style="margin:0;color:#172033;font-size:16px;line-height:1.6;">Best regards,<br>{site_name}</p>'
				),
				'css'         => '',
			),
			'professional_request_received' => array(
				'key'         => 'professional_request_received',
				'name'        => __( 'Professional Request Received', 'submission-inbox' ),
				'description' => __( 'A polished reply for quote requests, support requests, and business forms.', 'submission-inbox' ),
				'subject'     => __( 'We received your request', 'submission-inbox' ),
				'preheader'   => __( 'Your request has been received and will be reviewed shortly.', 'submission-inbox' ),
				'html'        => $this->email_shell(
					'#eef3f8',
					'#ffffff',
					'<div style="display:inline-block;margin:0 0 18px;padding:7px 12px;border-radius:999px;background:#dcfce7;color:#15803d;font-size:13px;font-weight:700;">Request received</div>
					<h1 style="margin:0 0 18px;color:#172033;font-size:28px;line-height:1.25;">We received your request</h1>
					<p style="margin:0 0 16px;color:#172033;font-size:16px;line-height:1.6;">Hi {field:name},</p>
					<p style="margin:0 0 24px;color:#172033;font-size:16px;line-height:1.6;">Thank you for contacting us. Your request has been received and our team will review it shortly.</p>' .
					$this->details_table( true ) .
					'<p style="margin:28px 0 0;color:#64748b;font-size:14px;line-height:1.6;">This is an automatic confirmation from {site_name}.</p>'
				),
				'css'         => '',
			),
			'booking_inquiry_received'      => array(
				'key'         => 'booking_inquiry_received',
				'name'        => __( 'Booking Inquiry Received', 'submission-inbox' ),
				'description' => __( 'A friendly confirmation email for booking or appointment requests.', 'submission-inbox' ),
				'subject'     => __( 'We received your booking inquiry', 'submission-inbox' ),
				'preheader'   => __( 'Thank you. We will review your booking request and get back to you soon.', 'submission-inbox' ),
				'html'        => $this->email_shell(
					'#f6f8fb',
					'#ffffff',
					'<h1 style="margin:0 0 18px;color:#172033;font-size:27px;line-height:1.25;">Your booking inquiry was received</h1>
					<p style="margin:0 0 16px;color:#172033;font-size:16px;line-height:1.6;">Hi {field:name},</p>
					<p style="margin:0 0 20px;color:#172033;font-size:16px;line-height:1.6;">Thank you for your booking inquiry. We received your details and will get back to you as soon as possible.</p>
					<div style="margin:24px 0;padding:18px;background:#eff6ff;border:1px solid #bfdbfe;border-radius:14px;">
						<strong style="display:block;margin-bottom:8px;color:#1d4ed8;">What happens next?</strong>
						<p style="margin:0;color:#172033;font-size:16px;line-height:1.6;">Our team will review your request and contact you using the details you provided.</p>
					</div>
					<p style="margin:0 0 18px;color:#64748b;font-size:14px;line-height:1.6;">Submitted via {form_name} on {submission_date}.</p>
					<p style="margin:0;color:#172033;font-size:16px;line-height:1.6;">Best regards,<br>{site_name}</p>'
				),
				'css'         => '',
			),
			'modern_gradient_confirmation'  => array(
				'key'         => 'modern_gradient_confirmation',
				'name'        => __( 'Modern Gradient Confirmation', 'submission-inbox' ),
				'description' => __( 'A modern gradient confirmation email for contact and request submissions.', 'submission-inbox' ),
				'subject'     => __( 'We received your request', 'submission-inbox' ),
				'preheader'   => __( 'Your request has been received and will be reviewed shortly.', 'submission-inbox' ),
				'html'        => $this->gradient_template(),
				'css'         => '',
			),
			'premium_booking_reply'         => array(
				'key'         => 'premium_booking_reply',
				'name'        => __( 'Premium Booking Reply', 'submission-inbox' ),
				'description' => __( 'A premium booking confirmation layout for appointments and inquiries.', 'submission-inbox' ),
				'subject'     => __( 'We received your booking inquiry', 'submission-inbox' ),
				'preheader'   => __( 'Thank you. We received your booking inquiry and will get back to you soon.', 'submission-inbox' ),
				'html'        => $this->premium_booking_template(),
				'css'         => '',
			),
			'aurora_response_card'          => array(
				'key'         => 'aurora_response_card',
				'name'        => __( 'Aurora Response Card', 'submission-inbox' ),
				'description' => __( 'A soft, modern confirmation email with a polished editorial layout.', 'submission-inbox' ),
				'subject'     => __( 'Your message is safely in our inbox', 'submission-inbox' ),
				'preheader'   => __( 'We received your message and will follow up soon.', 'submission-inbox' ),
				'html'        => $this->aurora_response_template(),
				'css'         => '',
			),
			'obsidian_status_reply'         => array(
				'key'         => 'obsidian_status_reply',
				'name'        => __( 'Obsidian Status Reply', 'submission-inbox' ),
				'description' => __( 'A bold dark confirmation email with high-contrast status cards.', 'submission-inbox' ),
				'subject'     => __( 'Request received', 'submission-inbox' ),
				'preheader'   => __( 'Your request has been received and is queued for review.', 'submission-inbox' ),
				'html'        => $this->obsidian_status_template(),
				'css'         => '',
			),
		);
	}

	/**
	 * Wrap starter content in an email-safe shell.
	 *
	 * @param string $background Page background.
	 * @param string $card_background Card background.
	 * @param string $content Inner HTML.
	 * @return string
	 */
	private function email_shell( $background, $card_background, $content ) {
		return '<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="width:100%;border-collapse:collapse;background:' . esc_attr( $background ) . ';font-family:Arial,sans-serif;"><tr><td align="center" style="padding:36px 16px;"><table role="presentation" width="640" cellpadding="0" cellspacing="0" style="width:100%;max-width:640px;border-collapse:separate;background:' . esc_attr( $card_background ) . ';border:1px solid #d8e2ee;border-radius:18px;"><tr><td style="padding:34px;text-align:left;">' . $content . '</td></tr></table></td></tr></table>';
	}

	/**
	 * Details block table.
	 *
	 * @param bool $include_lead_id Include lead id row.
	 * @return string
	 */
	private function details_table( $include_lead_id = false ) {
		$lead_row = $include_lead_id ? '<tr><td style="padding:14px 16px;color:#64748b;font-size:13px;font-weight:700;border-top:1px solid #d8e2ee;background:#f8fafc;">Lead ID</td><td style="padding:14px 16px;color:#172033;font-size:15px;border-top:1px solid #d8e2ee;background:#f8fafc;">{lead_id}</td></tr>' : '';
		return '<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="width:100%;border-collapse:separate;border:1px solid #d8e2ee;border-radius:14px;background:#f8fafc;">
			<tr><td style="padding:14px 16px;color:#64748b;font-size:13px;font-weight:700;">Form</td><td style="padding:14px 16px;color:#172033;font-size:15px;">{form_name}</td></tr>' .
			$lead_row .
			'<tr><td style="padding:14px 16px;color:#64748b;font-size:13px;font-weight:700;border-top:1px solid #d8e2ee;background:#f8fafc;">Visitor email</td><td style="padding:14px 16px;color:#172033;font-size:15px;border-top:1px solid #d8e2ee;background:#f8fafc;"><a href="mailto:{visitor_email}" style="color:#2563eb;">{visitor_email}</a></td></tr>
			<tr><td style="padding:14px 16px;color:#64748b;font-size:13px;font-weight:700;border-top:1px solid #d8e2ee;background:#f8fafc;">Date</td><td style="padding:14px 16px;color:#172033;font-size:15px;border-top:1px solid #d8e2ee;background:#f8fafc;">{submission_date}</td></tr>
		</table>';
	}

	/**
	 * Modern gradient starter.
	 *
	 * @return string
	 */
	private function gradient_template() {
		return '<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="width:100%;border-collapse:collapse;background:#eef3f8;font-family:Arial,sans-serif;"><tr><td align="center" style="padding:40px 16px;"><table role="presentation" width="660" cellpadding="0" cellspacing="0" style="width:100%;max-width:660px;border-collapse:separate;background:#ffffff;border:1px solid #d8e2ee;border-radius:22px;"><tr><td style="padding:36px 34px;background:linear-gradient(135deg,#2563eb 0%,#7c3aed 58%,#db2777 100%);color:#ffffff;text-align:left;"><div style="margin-bottom:22px;"><span style="display:inline-block;width:42px;height:42px;margin-right:10px;border-radius:14px;background:rgba(255,255,255,.18);color:#ffffff;font-size:12px;font-weight:800;line-height:42px;text-align:center;">OK</span><span style="display:inline-block;padding:9px 13px;border-radius:999px;background:rgba(255,255,255,.18);color:#ffffff;font-size:13px;font-weight:700;">Request received</span></div><h1 style="margin:0 0 16px;color:#ffffff;font-size:30px;line-height:1.2;">We received your request</h1><p style="margin:0 0 16px;color:#eef6ff;font-size:16px;line-height:1.6;">Hi {field:name},</p><p style="margin:0;color:#eef6ff;font-size:16px;line-height:1.6;">Thank you for contacting us. Your request has been received and our team will review it shortly.</p></td></tr><tr><td style="padding:28px 32px 0;"><div style="padding:20px;border:1px solid #dbeafe;border-radius:18px;background:#f8fbff;"><span style="display:inline-block;width:34px;height:34px;margin-right:12px;border-radius:12px;background:#dbeafe;color:#1d4ed8;font-size:15px;font-weight:800;line-height:34px;text-align:center;">1</span><div style="display:inline-block;width:82%;vertical-align:top;"><strong style="display:block;margin-bottom:6px;color:#172033;font-size:16px;">What happens next?</strong><p style="margin:0;color:#475569;font-size:16px;line-height:1.6;">Our team will review your message and respond using the details you provided.</p></div></div></td></tr><tr><td style="padding:22px 32px 0;">' . $this->details_table( false ) . '</td></tr><tr><td style="padding:24px 32px 32px;color:#64748b;font-size:14px;">This is an automatic confirmation from {site_name}.</td></tr></table></td></tr></table>';
	}

	/**
	 * Premium booking starter.
	 *
	 * @return string
	 */
	private function premium_booking_template() {
		return '<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="width:100%;border-collapse:collapse;background:#101827;font-family:Arial,sans-serif;"><tr><td align="center" style="padding:42px 16px;"><table role="presentation" width="660" cellpadding="0" cellspacing="0" style="width:100%;max-width:660px;border-collapse:separate;background:#ffffff;border-radius:24px;"><tr><td style="padding:38px 34px 42px;background:linear-gradient(135deg,#0f766e 0%,#2563eb 54%,#8b5cf6 100%);color:#ffffff;text-align:left;"><span style="display:inline-block;width:48px;height:48px;margin-right:12px;border-radius:16px;background:rgba(255,255,255,.16);color:#ffffff;font-size:13px;font-weight:800;line-height:48px;text-align:center;">BK</span><span style="display:inline-block;padding:9px 14px;border-radius:999px;background:rgba(255,255,255,.16);color:#ffffff;font-size:13px;font-weight:700;">Booking inquiry received</span><h1 style="margin:24px 0 16px;color:#ffffff;font-size:31px;line-height:1.2;">Your booking inquiry was received</h1><p style="margin:0 0 16px;color:#e7f7ff;font-size:16px;line-height:1.6;">Hi {field:name},</p><p style="margin:0;color:#e7f7ff;font-size:16px;line-height:1.6;">Thank you. We received your booking inquiry and will get back to you soon.</p></td></tr><tr><td style="padding:30px 32px 0;"><div style="padding:22px;border:1px solid #c7d2fe;border-radius:20px;background:#eef2ff;"><strong style="display:block;margin-bottom:8px;color:#172033;font-size:16px;">What happens next?</strong><p style="margin:0;color:#475569;font-size:16px;line-height:1.6;">Our team will review your request and contact you using the details you provided.</p></div></td></tr><tr><td style="padding:24px 32px 0;">' . $this->details_table( false ) . '</td></tr><tr><td style="padding:24px 32px 34px;color:#64748b;font-size:14px;">We appreciate your interest in {site_name}.</td></tr></table></td></tr></table>';
	}

	/**
	 * Aurora response starter.
	 *
	 * @return string
	 */
	private function aurora_response_template() {
		return '<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="width:100%;border-collapse:collapse;background:linear-gradient(135deg,#f0fdfa 0%,#eef2ff 48%,#fff7ed 100%);font-family:Arial,sans-serif;"><tr><td align="center" style="padding:44px 16px;"><table role="presentation" width="680" cellpadding="0" cellspacing="0" style="width:100%;max-width:680px;border-collapse:separate;background:#ffffff;border:1px solid #dbe7f3;border-radius:28px;"><tr><td style="padding:18px 18px 0;"><div style="height:10px;border-radius:999px;background:linear-gradient(90deg,#14b8a6 0%,#6366f1 52%,#f97316 100%);line-height:10px;font-size:1px;">&nbsp;</div></td></tr><tr><td style="padding:34px 38px 10px;text-align:left;"><span style="display:inline-block;padding:8px 12px;border-radius:999px;background:#ecfeff;color:#0f766e;font-size:12px;font-weight:800;letter-spacing:.08em;text-transform:uppercase;">Message received</span><h1 style="margin:22px 0 14px;color:#0f172a;font-size:34px;line-height:1.14;letter-spacing:-.03em;">Your note is safely in our inbox.</h1><p style="margin:0 0 24px;color:#475569;font-size:17px;line-height:1.65;">Hi {field:name}, thanks for reaching out. We received your message and our team will review it with care.</p><table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="width:100%;border-collapse:separate;background:#f8fafc;border:1px solid #e2e8f0;border-radius:20px;"><tr><td style="padding:20px;"><strong style="display:block;margin-bottom:8px;color:#0f172a;font-size:16px;">What happens next?</strong><p style="margin:0;color:#475569;font-size:15px;line-height:1.6;">We will respond using the contact details you provided. If anything urgent changes, you can reply directly to this confirmation.</p></td></tr></table></td></tr><tr><td style="padding:18px 38px 0;">' . $this->details_table( false ) . '</td></tr><tr><td style="padding:24px 38px 38px;color:#64748b;font-size:14px;line-height:1.6;">Sent automatically by {site_name}.</td></tr></table></td></tr></table>';
	}

	/**
	 * Obsidian status starter.
	 *
	 * @return string
	 */
	private function obsidian_status_template() {
		return '<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="width:100%;border-collapse:collapse;background:#020617;font-family:Arial,sans-serif;"><tr><td align="center" style="padding:44px 16px;"><table role="presentation" width="680" cellpadding="0" cellspacing="0" style="width:100%;max-width:680px;border-collapse:separate;background:#0f172a;border:1px solid #334155;border-radius:26px;"><tr><td style="padding:36px 36px 10px;text-align:left;"><span style="display:inline-block;width:46px;height:46px;margin-right:12px;border-radius:16px;background:#22c55e;color:#052e16;font-size:14px;font-weight:900;line-height:46px;text-align:center;">OK</span><span style="display:inline-block;padding:9px 14px;border-radius:999px;background:#1e293b;color:#cbd5e1;font-size:13px;font-weight:700;">Queued for review</span><h1 style="margin:28px 0 14px;color:#f8fafc;font-size:33px;line-height:1.16;letter-spacing:-.03em;">We received your request.</h1><p style="margin:0 0 26px;color:#cbd5e1;font-size:16px;line-height:1.65;">Hi {field:name}, your request has been captured and is now waiting for our team to review it.</p><table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="width:100%;border-collapse:separate;background:#111c2f;border:1px solid #334155;border-radius:18px;"><tr><td style="padding:18px 20px;border-bottom:1px solid #334155;"><strong style="display:block;color:#f8fafc;font-size:15px;">Status</strong><span style="color:#93c5fd;font-size:14px;">Received and logged</span></td></tr><tr><td style="padding:18px 20px;"><strong style="display:block;color:#f8fafc;font-size:15px;">Next step</strong><span style="color:#cbd5e1;font-size:14px;line-height:1.6;">We will review the details and respond as soon as possible.</span></td></tr></table></td></tr><tr><td style="padding:24px 36px 0;"><table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="width:100%;border-collapse:separate;border:1px solid #334155;border-radius:16px;background:#111827;"><tr><td style="padding:14px 16px;color:#94a3b8;font-size:13px;font-weight:700;">Form</td><td style="padding:14px 16px;color:#f8fafc;font-size:15px;">{form_name}</td></tr><tr><td style="padding:14px 16px;color:#94a3b8;font-size:13px;font-weight:700;border-top:1px solid #334155;">Visitor email</td><td style="padding:14px 16px;color:#f8fafc;font-size:15px;border-top:1px solid #334155;"><a href="mailto:{visitor_email}" style="color:#60a5fa;">{visitor_email}</a></td></tr><tr><td style="padding:14px 16px;color:#94a3b8;font-size:13px;font-weight:700;border-top:1px solid #334155;">Date</td><td style="padding:14px 16px;color:#f8fafc;font-size:15px;border-top:1px solid #334155;">{submission_date}</td></tr></table></td></tr><tr><td style="padding:24px 36px 36px;color:#94a3b8;font-size:14px;line-height:1.6;">This is an automatic confirmation from {site_name}.</td></tr></table></td></tr></table>';
	}

	/**
	 * Get all starter templates.
	 *
	 * @return array<string,array<string,string>>
	 */
	public function all() {
		return $this->inline_html_templates();
	}

	/**
	 * Get one starter template.
	 *
	 * @param string $key Template key.
	 * @return array<string,string>|null
	 */
	public function get( $key ) {
		$key       = sanitize_key( $key );
		$templates = $this->all();

		return isset( $templates[ $key ] ) ? $templates[ $key ] : null;
	}
}
