<?php
/**
 * @package     Reporter for VirtueMart
 * 
 * @copyright   Copyright (C) 2012-2021 VirtuePlanet Services LLP. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 * @author      Abhishek Das <info@virtueplanet.com> - https://www.virtueplanet.com
 */

defined('_JEXEC') or die;

use Joomla\Registry\Registry;

$template = isset($displayData['template']) ? $displayData['template'] : null;
$items    = isset($displayData['items']) ? $displayData['items'] : array();
$emails   = isset($displayData['emails']) ? $displayData['emails'] : array();
$siteName = isset($displayData['siteName']) ? $displayData['siteName'] : '';
$siteUrl  = isset($displayData['siteUrl']) ? $displayData['siteUrl'] : '';
$params   = isset($displayData['params']) ? $displayData['params'] : new Registry;
$data     = isset($displayData['data']) ? $displayData['data'] : array();
$mailData = isset($displayData['mailData']) ? $displayData['mailData'] : array();
$currency = isset($displayData['currency']) ? $displayData['currency'] : null;
$siteUrl  = '<a href="' . htmlspecialchars($siteUrl) . '" target="_blank">' . $siteUrl . '</a>';
$addTexts = '';

if(!empty($mailData))
{
	$addTexts = array();
	
	foreach($mailData as $item)
	{
		$addText = '';
		
		if(!empty($item->label))
		{
			$addText .= $item->label . ': ';
		}
		
		if(!empty($item->value))
		{
			$addText .= !empty($item->isCurrency) ? $currency->priceDisplay($item->value) : $item->value;
		}
		
		$addTexts[] = $addText;
	}
	
	$addTexts = '<br/><br/>' . implode('<br/>', $addTexts);
}

if($params->get('report_as_attachment', 1))
{
	$texts = JText::sprintf('COM_VMREPORTER_MAIL_BODY_WITH_ATTACHMENT', $siteName, $siteName, $siteUrl, $addTexts);
}
else
{
	$texts = JText::sprintf('COM_VMREPORTER_MAIL_BODY_WITHOUT_ATTACHMENT', $siteName, $siteName, $siteUrl, $addTexts);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <style type="text/css">
    /* CLIENT-SPECIFIC STYLES */
    /* Force Outlook to provide a "view in browser" message */
    #outlook a {
      padding:0;
    } 
    .ReadMsgBody {
      width:100%;
    }
    /* Force Hotmail to display emails at full width */
    .ExternalClass {
      width:100%;
    }
    /* Force Hotmail to display normal line spacing */
    .ExternalClass,
    .ExternalClass p,
    .ExternalClass span,
    .ExternalClass font,
    .ExternalClass td,
    .ExternalClass div {
      line-height: 100%;
    }
    /* Prevent WebKit and Windows mobile changing default text sizes */
    body, table, td, a{
      -webkit-text-size-adjust:100%;
      -ms-text-size-adjust:100%;
    }
    /* Remove spacing between tables in Outlook 2007 and up */
    table, td {
      mso-table-lspace:0pt;
      mso-table-rspace:0pt;
    }
    /* Allow smoother rendering of resized image in Internet Explorer */
    img {
      -ms-interpolation-mode:bicubic;
    }

    /* RESET STYLES */
    body {
      margin:0;
      padding:0;
    }
    img {
      border:0;
      height:auto;
      line-height:100%;
      outline:none;
      text-decoration:none;
    }
    table {
      border-collapse:collapse !important;
    }
    body {
      height:100% !important;
      margin:0;
      padding:0;
      width:100% !important;
    }

    /* iOS BLUE LINKS */
    .appleBody a {
      color:#68440a;
      text-decoration: none;
    }
    .appleFooter a {
      color:#999999;
      text-decoration: none;
    }

    /* MOBILE STYLES */
    @media screen and (max-width: 525px) {
        /* ALLOWS FOR FLUID TABLES */
        table[class="wrapper"] {
          width:100% !important;
        }

        /* ADJUSTS LAYOUT OF LOGO IMAGE */
        td[class="logo"] {
          text-align: left;
          padding: 20px 0 20px 0 !important;
        }
        td[class="logo"] img {
          margin:0 auto!important;
        }

        /* USE THESE CLASSES TO HIDE CONTENT ON MOBILE */
        td[class="mobile-hide"] {
          display:none;
        }
        img[class="mobile-hide"] {
          display: none !important;
        }
        img[class="img-max"] {
          max-width: 100% !important;
          width: 100% !important;
          height:auto !important;
        }

        /* FULL-WIDTH TABLES */
        table[class="responsive-table"] {
          width:100%!important;
        }

        /* UTILITY CLASSES FOR ADJUSTING PADDING ON MOBILE */
        td[class="padding"] {
          padding: 10px 5% 15px 5% !important;
        }
        td[class="padding-copy"] {
          padding: 10px 5% 10px 5% !important;
          text-align: left;
        }
        td[class="padding-meta"] {
          padding: 30px 5% 0px 5% !important;
          text-align: center;
        }
        td[class="no-pad"] {
          padding: 0 0 20px 0 !important;
        }
        td[class="no-padding"] {
          padding: 0 !important;
        }
        td[class="section-padding"] {
          padding: 50px 15px 50px 15px !important;
        }
        td[class="section-padding-bottom-image"] {
          padding: 50px 15px 0 15px !important;
        }

        /* ADJUST BUTTONS ON MOBILE */
        td[class="mobile-wrapper"] {
            padding: 10px 5% 15px 5% !important;
        }
        table[class="mobile-button-container"] {
            margin:0 auto;
            width:100% !important;
        }
        a[class="mobile-button"] {
            width:80% !important;
            padding: 15px !important;
            border: 0 !important;
            font-size: 16px !important;
        }
    }
  </style>
</head>
<body style="margin: 0; padding: 0; background-color: #f2f2f2;" bgcolor=" #f2f2f2">

    <!-- HEADER -->
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
        <tr>
            <td bgcolor="#FFFFFF" style="border-bottom: 1px solid #e2e5e8;">
                <div align="center" style="padding: 0px 15px 0px 15px;">
                    <table border="0" cellpadding="0" cellspacing="0" width="600" class="wrapper">
                        <!-- LOGO/PREHEADER TEXT -->
                        <tr>
                            <td style="padding: 25px 0px 25px 0px;" class="logo">
                                <table border="0" cellpadding="0" cellspacing="0" width="100%">
                                    <tr>
                                        <td bgcolor="#FFFFFF" width="300" align="left">
                                            <!--SITE LOGO / SITE NAME-->
                                            <a href="<?php echo htmlspecialchars($siteUrl); ?>" target="_blank" style="text-decoration: none; color: #666666;">
                                              <h1 style="font-family: Helvetica, Arial, sans-serif; color: #333333; font-size: 32px; font-weight: bold; line-height: 1; margin: 0; padding: 0;"><?php echo $siteName; ?></h1>
                                            </a>
                                        </td>
                                        <td bgcolor="#FFFFFF" width="300" align="right" class="mobile-hide">
                                            <table border="0" cellpadding="0" cellspacing="0">
                                                <tr>
                                                    <td align="right" style="padding: 5px 0 0 0; font-size: 14px; font-family: Arial, sans-serif; color: #666666; text-decoration: none;">
                                                      <!--ANY OTHER CONTENTS THAT YOU WANT TO SHOW AT RIGHT SIDE IN THE HEADER SECTION-->
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table>
                </div>
            </td>
        </tr>
    </table>

    <!-- MAIN CONTENTS SECTION -->
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
        <tr>
            <td bgcolor="#f2f2f2" align="center" style="padding: 40px 15px 40px 15px;" class="section-padding">
                <table border="0" cellpadding="0" cellspacing="0" width="600" class="responsive-table">
                    <tr>
                        <td bgcolor="#ffffff" style="background-color: #ffffff; border-bottom: 2px solid #e2e5e8;">
                            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td bgcolor="#ffffff" style="padding: 35px 25px; background-color: #ffffff;">
                                        <!-- MAIN CONTENTS -->
                                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                            <tr>
                                                <td align="left" style="font-size: 14px; line-height: 22px; font-family: Helvetica, Arial, sans-serif; color: #555555;" class="padding-copy">
                                                    <div mc:edit="main_content" style="text-align: left; font-size: 14px; line-height: 22px; font-family: Helvetica, Arial, sans-serif; color: #555555;">
                                                        <!-- MAIL CONTENTS GOES HERE -->
                                                        <?php echo str_replace("\n", '<br/>', $texts); ?>
                                                    </div>
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>

    <!-- FOOTER -->
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
        <tr>
            <td bgcolor="#f2f2f2" align="center" style="padding: 10px 0px 20px 0px;">
                <!-- UNSUBSCRIBE COPY -->
                <table width="600" border="0" cellspacing="0" cellpadding="0" align="center" class="responsive-table">
                    <tr>
                        <td align="left" style="font-size: 13px; line-height: 18px; font-family: Helvetica, Arial, sans-serif; color:#aaaaaa;" class="padding">
                            <!--DISCLAIMER-->
                            <?php echo JText::_('COM_VMREPORTER_MAIL_DISCLAIMER'); ?>
                        </td>
                    </tr>
                    <tr>
                        <td align="left" style="font-size: 11px; line-height: 18px; font-family: Helvetica, Arial, sans-serif; color:#aaaaaa; padding-top: 15px;" class="padding">
                            <!--SITE NAME AND OTHER CONTACT DETAILS-->
                            <span class="appleFooter" style="color:#aaaaaa;"><?php echo $siteName; ?></span>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>

</body>
</html>