<?php

/**
 * The template for displaying email header
 *
 * This template can be overridden by copying it to yourtheme/movie-engine/emails/header.php.
 *
 * HOWEVER, on occasion MovieEngine will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * NOTE: Inline styles in email templates are intentional for email client compatibility.
 *
 * @note Please do not delete our CSS classes when you customize, as it may break functionality.
 * @package Movie_Engine
 * @subpackage Movie_Engine/templates
 * @version 1.0.0
 * @since 1.0.0
 */

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

$movie_engine_email_options = get_option('movie_engine_email_settings', []);

// Defaults
$movie_engine_email_defaults = [
    'logo_url'            => '',
    'primary_color'       => '#E50914',
    'btn_text_color'      => '#FFFFFF',
    'email_bg_color'      => '#0f0f0f',
    'content_bg_color'    => '#1a1a1a',
    'header_bg_color'     => '#141414',
    'content_title_color' => '#ffffff',
    'content_text_color'  => '#cccccc',
    'link_color'          => '#E50914',
    'border_color'        => '#333333',
    'logo_width'          => 150,
    'logo_height'         => 'auto',
];

$movie_engine_email_settings = wp_parse_args($movie_engine_email_options, $movie_engine_email_defaults);

$movie_engine_email_bg_color       = $movie_engine_email_settings['email_bg_color'];
$movie_engine_email_text_color     = $movie_engine_email_settings['content_text_color'];
$movie_engine_email_title_color    = $movie_engine_email_settings['content_title_color'];
$movie_engine_email_link_color     = $movie_engine_email_settings['link_color'];
$movie_engine_email_primary_color  = $movie_engine_email_settings['primary_color'];
$movie_engine_email_btn_text_color = $movie_engine_email_settings['btn_text_color'];
$movie_engine_email_logo_width     = is_numeric($movie_engine_email_settings['logo_width']) ? $movie_engine_email_settings['logo_width'] . 'px' : $movie_engine_email_settings['logo_width'];
$movie_engine_email_logo_height    = is_numeric($movie_engine_email_settings['logo_height']) ? $movie_engine_email_settings['logo_height'] . 'px' : $movie_engine_email_settings['logo_height'];
?>
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        body {
            font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-color: <?php echo esc_attr($movie_engine_email_bg_color); ?>;
            color: <?php echo esc_attr($movie_engine_email_text_color); ?>;
        }

        .wrapper {
            width: 100%;
            table-layout: fixed;
            background-color: <?php echo esc_attr($movie_engine_email_bg_color); ?>;
            padding-bottom: 40px;
        }

        .main-content {
            max-width: 600px;
            margin: 0 auto;
            background-color: <?php echo esc_attr($movie_engine_email_settings['content_bg_color']); ?>;
            border-radius: 8px;
            overflow: hidden;
            margin-top: 40px;
            border: none;
        }

        .header {
            padding: 40px 0;
            text-align: center;
            background-color: <?php echo esc_attr($movie_engine_email_settings['header_bg_color']); ?>;
        }

        .logo {
            width: <?php echo esc_attr($movie_engine_email_logo_width); ?>;
            height: <?php echo esc_attr($movie_engine_email_logo_height); ?>;
            object-fit: contain;
        }

        .content {
            padding: 40px;
            line-height: 1.6;
            color: <?php echo esc_attr($movie_engine_email_text_color); ?>;
        }

        h1,
        h2,
        h3 {
            color: <?php echo esc_attr($movie_engine_email_title_color); ?>;
            font-size: 24px;
            margin-top: 0;
        }

        p {
            color: <?php echo esc_attr($movie_engine_email_text_color); ?>;
            font-size: 16px;
            margin-bottom: 20px;
        }

        a {
            color: <?php echo esc_attr($movie_engine_email_link_color); ?> !important;
            text-decoration: underline;
        }

        .btn {
            display: inline-block;
            padding: 12px 30px;
            background-color: <?php echo esc_attr($movie_engine_email_primary_color); ?> !important;
            color: <?php echo esc_attr($movie_engine_email_btn_text_color); ?> !important;
            text-decoration: none !important;
            border-radius: 4px;
            font-weight: bold;
            margin-top: 20px;
        }

        .footer {
            padding: 40px;
            text-align: center;
            color: rgba(255, 255, 255, 0.5);
            font-size: 12px;
        }

        .divider {
            height: 1px;
            background-color: rgba(255, 255, 255, 0.1);
            margin: 20px 0;
        }

        .meta-table,
        .content table {
            width: 100%;
            border-collapse: collapse;
            margin: 20px 0;
            border: 1px solid <?php echo esc_attr($movie_engine_email_settings['border_color']); ?> !important;
        }

        .meta-table td,
        .content table td,
        .content table th {
            padding: 12px 15px;
            border: 1px solid <?php echo esc_attr($movie_engine_email_settings['border_color']); ?> !important;
        }

        .meta-table td {
            color: rgba(255, 255, 255, 0.6);
        }

        .meta-table td.val {
            text-align: right;
            color: <?php echo esc_attr($movie_engine_email_title_color); ?>;
            font-weight: bold;
        }
    </style>
</head>

<body style="margin: 0; padding: 0; background-color: <?php echo esc_attr($movie_engine_email_bg_color); ?>; color: <?php echo esc_attr($movie_engine_email_text_color); ?>; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;">
    <div class="wrapper" style="width: 100%; table-layout: fixed; background-color: <?php echo esc_attr($movie_engine_email_bg_color); ?>; padding-bottom: 40px;">
        <div class="main-content" style="max-width: 600px; margin: 0 auto; background-color: <?php echo esc_attr($movie_engine_email_settings['content_bg_color']); ?>; border-radius: 8px; overflow: hidden; margin-top: 40px; border: none;">
            <div class="header" style="padding: 40px 0; text-align: center; background-color: <?php echo esc_attr($movie_engine_email_settings['header_bg_color']); ?>;">
                <?php if (!empty($movie_engine_email_settings['logo_url'])) : ?>
                    <img src="<?php echo esc_url($movie_engine_email_settings['logo_url']); ?>" alt="<?php bloginfo('name'); ?>" class="logo" style="width: <?php echo esc_attr($movie_engine_email_logo_width); ?>; height: <?php echo esc_attr($movie_engine_email_logo_height); ?>; border: none; outline: none; text-decoration: none;">
                <?php else : ?>
                    <h2 style="margin:0; color: <?php echo esc_attr($movie_engine_email_primary_color); ?>; font-size: 30px; font-weight: 800; text-transform: uppercase;"><?php bloginfo('name'); ?></h2>
                <?php endif; ?>
            </div>
            <div class="content" style="padding: 40px; line-height: 1.6; color: <?php echo esc_attr($movie_engine_email_text_color); ?>;">