<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
@php
    use App\Facades\Settings;
    use Mtc\MercuryDataModels\Dealership;
    if (isset($reservation)) {
        $location = $reservation->vehicle?->dealership;
    }

    // Search for "Select Branch" question dynamically
    $branchId = null;

    if (isset($enquiry)) {
        if ($enquiry?->reason_type == 'reservation') {
            $location = $enquiry->reason?->vehicle?->dealership;
        } elseif ($enquiry?->reason_type === 'vehicle') {
            $location = $enquiry->reason?->dealership;
        } elseif ($enquiry?->reason_type === 'offer') {
            $location = $enquiry->reason?->dealership;
        } elseif ($enquiry?->reason_type === 'dealership') {
            $location = $enquiry->reason;
        } elseif ($enquiry?->reason_type === 'new-car') {
            $location = $enquiry->reason->franchise?->dealerships()->first();
        }

        foreach ($enquiry?->details as $question) {
            if ($question['question'] === "Select Branch" && !empty($question['answer'])) {
                $branchId = (int)$question['answer'];
                break;
            }
        }
    }

    if (empty($branchId) && isset($reservation)) {
        $branchId = $reservation->vehicle?->dealership?->id;
    }

    // Fetch the dealership using the found branch ID
    if (!empty($branchId)) {
        $location = Dealership::find($branchId);
    }

    if (!empty($location)) {
        $phone_number = $location->contact_no;
        $phone_number_formatted = match (Settings::get('app-phone-number-format')) {
            '3-3-4' => substr($phone_number, 0, 3) . ' ' . substr($phone_number, 3, 3) . ' ' . substr($phone_number, 6),
            '4-3-3' => substr($phone_number, 0, 4) . ' ' . substr($phone_number, 4, 3) . ' ' . substr($phone_number, 7),
            '5-3-3' => substr($phone_number, 0, 5) . ' ' . substr($phone_number, 5, 3) . ' ' . substr($phone_number, 8),
            '5-6' => substr($phone_number, 0, 5) . ' ' . substr($phone_number, 5),
            default => $phone_number
        };
    }
@endphp
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>Your Message Subject or Title</title>
    <style type="text/css">

        /***********
        Originally based on The MailChimp Reset from Fabio Carneiro, MailChimp User Experience Design
        More info and templates on Github: https://github.com/mailchimp/Email-Blueprints
        http://www.mailchimp.com &amp; http://www.fabio-carneiro.com

        INLINE: No.
        ***********/
        /* Client-specific Styles */
        #outlook a {
            padding: 0;
        }

        /* Force Outlook to provide a "view in browser" menu link. */
        body {
            width: 100% !important;
            height: 100% !important;
            -webkit-text-size-adjust: 100%;
            -ms-text-size-adjust: 100%;
            margin: 0;
            padding: 0;
        }

        /* Prevent Webkit and Windows Mobile platforms from changing default font sizes, while not breaking desktop design. */
        .ExternalClass {
            width: 100%;
        }

        /* Force Hotmail to display emails at full width */
        .ExternalClass, .ExternalClass p, .ExternalClass span, .ExternalClass font, .ExternalClass td, .ExternalClass div {
            line-height: 100%;
        }

        /* Force Hotmail to display normal line spacing. */
        #backgroundTable {
            margin: 0;
            padding: 0;
            width: 100% !important;
            height: 100% !important;
            line-height: 100% !important;
        }

        /* End reset */

        /* Some sensible defaults for images
        1. "-ms-interpolation-mode: bicubic" works to help ie properly resize images in IE. (if you are resizing them using the width and height attributes)
        2. "border:none" removes border when linking images.
        3. Updated the common Gmail/Hotmail image display fix: Gmail and Hotmail unwantedly adds in an extra space below images when using non IE browsers. You may not always want all of your images to be block elements. Apply the "imageFix" class to any image you need to fix.

        Bring inline: Yes.
        */
        img {
            outline: none;
            text-decoration: none;
            -ms-interpolation-mode: bicubic;
        }

        a img {
            border: none;
        }

        .imageFix {
            display: block;
        }

        /** Yahoo paragraph fix: removes the proper spacing or the paragraph (p) tag. To correct we set the top/bottom margin to 1em in the head of the document. Simple fix with little effect on other styling. NOTE: It is also common to use two breaks instead of the paragraph tag but I think this way is cleaner and more semantic. NOTE: This example recommends 1em. More info on setting web defaults: http://www.w3.org/TR/CSS21/sample.html or http://meiert.com/en/blog/20070922/user-agent-style-sheets/

        Bring inline: Yes.
        **/
        p {
            margin: 0 0 1em 0;
        }

        /** Hotmail header color reset: Hotmail replaces your header color styles with a green color on H2, H3, H4, H5, and H6 tags. In this example, the color is reset to black for a non-linked header, blue for a linked header, red for an active header (limited support), and purple for a visited header (limited support).  Replace with your choice of color. The !important is really what is overriding Hotmail's styling. Hotmail also sets the H1 and H2 tags to the same size.

        Bring inline: Yes.
        **/
        h1, h2, h3, h4, h5, h6 {
            color: #000E26 !important;
        }

        h1 a, h2 a, h3 a, h4 a, h5 a, h6 a {
            color: #000E26 !important;
        }

        h1 a:active, h2 a:active, h3 a:active, h4 a:active, h5 a:active, h6 a:active {
            color: #000E26 !important; /* Preferably not the same color as the normal header link color.  There is limited support for psuedo classes in email clients, this was added just for good measure. */
        }

        h1 a:visited, h2 a:visited, h3 a:visited, h4 a:visited, h5 a:visited, h6 a:visited {
            color: #000E26 !important; /* Preferably not the same color as the normal header link color. There is limited support for psuedo classes in email clients, this was added just for good measure. */
        }

        /** Outlook 07, 10 Padding issue: These "newer" versions of Outlook add some padding around table cells potentially throwing off your perfectly pixeled table.  The issue can cause added space and also throw off borders completely.  Use this fix in your header or inline to safely fix your table woes.

        More info: http://www.ianhoar.com/2008/04/29/outlook-2007-borders-and-1px-padding-on-table-cells/
        http://www.campaignmonitor.com/blog/post/3392/1px-borders-padding-on-table-cells-in-outlook-07/

        H/T @edmelly

        Bring inline: No.
        **/
        table td {
            border-collapse: collapse;
        }

        /** Remove spacing around Outlook 07, 10 tables

        More info : http://www.campaignmonitor.com/blog/post/3694/removing-spacing-from-around-tables-in-outlook-2007-and-2010/

        Bring inline: Yes
        **/
        table {
            border-collapse: collapse;
            mso-table-lspace: 0pt;
            mso-table-rspace: 0pt;
        }

        /* Styling your links has become much simpler with the new Yahoo.  In fact, it falls in line with the main credo of styling in email, bring your styles inline.  Your link colors will be uniform across clients when brought inline.

        Bring inline: Yes. */
        a {
            color: #000E26;
        }

        /* Or to go the gold star route...
        a:link { color: orange; }
        a:visited { color: blue; }
        a:hover { color: green; }
        */

        /***************************************************
        ****************************************************
        MOBILE TARGETING

        Use @media queries with care.  You should not bring these styles inline -- so it's recommended to apply them AFTER you bring the other stlying inline.

        Note: test carefully with Yahoo.
        Note 2: Don't bring anything below this line inline.
        ****************************************************
        ***************************************************/

        /* NOTE: To properly use @media queries and play nice with yahoo mail, use attribute selectors in place of class, id declarations.
        table[class=classname]
        Read more: http://www.campaignmonitor.com/blog/post/3457/media-query-issues-in-yahoo-mail-mobile-email/
        */
        @media only screen and (max-device-width: 700px) {

            /* A nice and clean way to target phone numbers you want clickable and avoid a mobile phone from linking other numbers that look like, but are not phone numbers.  Use these two blocks of code to "unstyle" any numbers that may be linked.  The second block gives you a class to apply with a span tag to the numbers you would like linked and styled.

            Inspired by Campaign Monitor's article on using phone numbers in email: http://www.campaignmonitor.com/blog/post/3571/using-phone-numbers-in-html-email/.

            Step 1 (Step 2: line 224)
            */
            a[href^="tel"], a[href^="sms"] {
                text-decoration: none;
                color: #000E26; /* or whatever your want */
                pointer-events: none;
                cursor: default;
            }

            .mobileLink a[href^="tel"], .mobileLink a[href^="sms"] {
                text-decoration: default;
                color: #000E26 !important; /* or whatever your want */
                pointer-events: auto;
                cursor: default;
            }
        }

        /* More Specific Targeting */

        @media only screen and (min-device-width: 768px) and (max-device-width: 1024px) {
            /* You guessed it, ipad (tablets, smaller screens, etc) */
            /* Step 1a: Repeating for the iPad */
            a[href^="tel"], a[href^="sms"] {
                text-decoration: none;
                color: #000E26; /* or whatever your want */
                pointer-events: none;
                cursor: default;
            }

            .mobileLink a[href^="tel"], .mobileLink a[href^="sms"] {
                text-decoration: default;
                color: #000E26 !important;
                pointer-events: auto;
                cursor: default;
            }
        }
    </style>

    <!-- ***********************************************
    ****************************************************
    END MOBILE TARGETING
    ****************************************************
    ************************************************ -->

    <!--[if gte mso 9]>
    <style>
        /* Target Outlook 2007 and 2010 */
    </style>
    <![endif]-->
</head>
<body>
<!-- Wrapper/Container Table: Use a wrapper table to control the width and the background color consistently of your email. Use this approach instead of setting attributes on the body tag. -->
<table cellpadding="0" cellspacing="0" border="0" id="backgroundTable" bgcolor="#F0F1F3"
       style="background-color:#F0F1F3 !important;">
    <tr>
        <td valign="top" height="80"></td>
    </tr>
    <tr>
        <td>
            <!-- INNER WRAPPER START -->
            <table cellpadding="0" cellspacing="0" border="0" align="center" width="940" bgcolor="#FFFFFF"
                   style="background-color:#FFFFFF;border-radius:20px;">
                <!-- HEADER START -->
                <tr>
                    <td valign="top" height="40"></td>
                </tr>
                <tr>
                    <td valign="top">
                        <table cellpadding="0" cellspacing="0" border="0" align="center" width="100%">
                            <tr>
                                <td valign="top" width="50"></td>
                                <td valign="middle" align="left">

                                    <a href="{{ $site_url }}" target="_blank" title="{{ $site_name }}" style="text-decoration: none;">
                                        <img class="imageFix"
                                             src="{{ config('app.url') . '/api/assets/vw-group-internal/vw-group-internal-logo.png'}}"
                                             alt="Logo" title="{{ $site_name }}" width="256" height="40"
                                             style="display:block; outline:none; text-decoration:none; -ms-interpolation-mode: bicubic; border:none;"/>
                                    </a>
                                </td>
                                <td align="right">
                                    @if(false)
                                    <table cellpadding="0" cellspacing="0" border="0" align="right" width="100%">
                                        <tr>
                                            <td valign="top" align="right">
                                                <p style="color:#008C82; margin:0; font-size:18px; font-weight:700; letter-spacing:-0.36px; font-family: -apple-system, BlinkMacSystemFont, avenir next, avenir, segoe ui, helvetica neue, helvetica, Cantarell, Ubuntu, roboto, noto, arial, sans-serif;">
                                                    Speak to the team</p>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td valign="top" align="right" height="8"></td>
                                        </tr>
                                        <tr>
                                            <td valign="top" align="right">
                                                @if(false)
                                                <table cellpadding="0" cellspacing="0" border="0" align="right">
                                                    <tr>
                                                        <td align="right">
                                                            <img class="imageFix"
                                                                 src="{{ config('app.url') . '/api/assets/vw-group-internal/icons/phone.png'}}"
                                                                 alt="Logo" title="Phone Us" width="24" height="24"
                                                                 style="display:block; outline:none; text-decoration:none; -ms-interpolation-mode: bicubic; border:none;"/>
                                                        </td>
                                                        <td align="right" width="8"></td>
                                                        <td align="right">
                                                            <span>
                                                                <a href="tel:{{ $phone_number }}" target="_blank"
                                                                   style="color:#000E26; margin:0; font-size:30px; font-weight:700; letter-spacing:-0.6px; font-family: -apple-system, BlinkMacSystemFont, avenir next, avenir, segoe ui, helvetica neue, helvetica, Cantarell, Ubuntu, roboto, noto, arial, sans-serif; text-decoration: none;">{{ $phone_number_formatted }}</a>
                                                            </span>
                                                        </td>
                                                    </tr>
                                                </table>
                                                @endif
                                            </td>
                                        </tr>
                                        <tr>
                                            <td valign="top" align="right" height="3"></td>
                                        </tr>
                                    </table>
                                    @endif
                                </td>
                                <td valign="top" width="50"></td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td valign="top" height="30"></td>
                </tr>
                <!-- HEADER END -->
                @yield('content')
                <!-- BUTTONS -->

                <!-- END OF BUTTONS -->
            </table>
            <!-- END OF INNER WRAPPER -->
        </td>
    </tr>
    <!-- START OF FOOTER -->
    <tr>
        <td valign="top" height="50"></td>
    </tr>
    <tr>
        <td valign="top">
            <table cellpadding="0" cellspacing="0" border="0" align="center" width="100%">
                <tr>
                    <td valign="top">
                        <table cellpadding="0" cellspacing="0" border="0" align="center" width="940">
                            <tr>
                                <td valign="top" width="65"></td>
                                <td valign="top">
                                    <table cellpadding="0" cellspacing="0" border="0" align="center" width="100%">
                                        <tr>
                                            <td valign="middle" align="left">
                                                @if(!empty($location?->address1))
                                                <a href="/" target="_blank" title="{{ $site_name }}"
                                                   style="text-decoration: none;">
                                                    <img class="imageFix"
                                                          src="{{ config('app.url') . '/api/assets/vw-group-internal/vw-group-internal-logo.png'}}"
                                             alt="Logo" title="{{ $site_name }}" width="256" height="40"
                                                         style="display:block; outline:none; text-decoration:none; -ms-interpolation-mode: bicubic; border:none;"/>
                                                </a>
                                                @endif
                                            </td>
                                            <td valign="top" align="right">
                                                <table cellpadding="0" cellspacing="0" border="0" align="right">
                                                    <tr>
                                                        @if($socials->where('key', 'facebook')->isNotEmpty())
                                                            <td valign="top" align="right" width="60">
                                                                <a href="{{ $socials->where('key', 'facebook')->first()['url'] }}"
                                                                   target="_blank" title="Facebook"
                                                                   style="text-decoration: none;">
                                                                    <img class="imageFix"
                                                                         src="{{ config('app.url') . '/api/assets/vw-group-internal/social/facebook-logo.png'}}"
                                                                         alt="Facebook" title="Facebook" width="40"
                                                                         height="40"
                                                                         style="display:block; outline:none; text-decoration:none; -ms-interpolation-mode: bicubic; border:none;"/>
                                                                </a>
                                                            </td>
                                                        @endif

                                                        @if($socials->where('key', 'twitter')->isNotEmpty())
                                                            <td valign="top" align="right" width="8"></td>

                                                            <td valign="top" align="right" width="60">
                                                                <a href="{{ $socials->where('key', 'twitter')->first()['url'] }}"
                                                                   target="_blank" title="X"
                                                                   style="text-decoration: none;">
                                                                    <img class="imageFix"
                                                                         src="{{ config('app.url') . '/api/assets/vw-group-internal/social/x-twitter-logo.png'}}"
                                                                         alt="X" title="X" width="40" height="40"
                                                                         style="display:block; outline:none; text-decoration:none; -ms-interpolation-mode: bicubic; border:none;"/>
                                                                </a>
                                                            </td>
                                                        @endif

                                                        <td valign="top" align="right" width="8"></td>


                                                        @if($socials->where('key', 'linkedin')->isNotEmpty())
                                                            <td valign="top" align="right" width="60">
                                                                <a href="{{ $socials->where('key', 'linkedin')->first()['url'] }}"
                                                                   target="_blank" title="Linked In"
                                                                   style="text-decoration: none;">
                                                                    <img class="imageFix"
                                                                         src="{{ config('app.url') . '/api/assets/vw-group-internal/social/linked-in-logo.png'}}"
                                                                         alt="Linked In" title="Linked In" width="35"
                                                                         height="40"
                                                                         style="display:block; outline:none; text-decoration:none; -ms-interpolation-mode: bicubic; border:none;"/>
                                                                </a>
                                                            </td>
                                                        @endif

                                                        <td valign="top" align="right" width="8"></td>


                                                        @if($socials->where('key', 'instagram')->isNotEmpty())
                                                            <td valign="top" align="right" width="60">
                                                                <a href="{{ $socials->where('key', 'instagram')->first()['url'] }}"
                                                                   target="_blank" title="Instagram"
                                                                   style="text-decoration: none;">
                                                                    <img class="imageFix"
                                                                         src="{{ config('app.url') . '/api/assets/vw-group-internal/social/insta-logo.png'}}"
                                                                         alt="Instagram" title="Instagram" width="35"
                                                                         height="40"
                                                                         style="display:block; outline:none; text-decoration:none; -ms-interpolation-mode: bicubic; border:none;"/>
                                                                </a>
                                                            </td>
                                                        @endif

                                                        <td valign="top" align="right" width="8"></td>


                                                        @if($socials->where('key', 'youtube')->isNotEmpty())
                                                            <td valign="top" align="right" width="60">
                                                                <a href="{{ $socials->where('key', 'youtube')->first()['url'] }}"
                                                                   target="_blank" title="YouTube"
                                                                   style="text-decoration: none;">
                                                                    <img class="imageFix"
                                                                         src="{{ config('app.url') . '/api/assets/vw-group-internal/social/yt-logo.png'}}"
                                                                         alt="YouTube" title="YouTube" width="40"
                                                                         height="40"
                                                                         style="display:block; outline:none; text-decoration:none; -ms-interpolation-mode: bicubic; border:none;"/>
                                                                </a>
                                                            </td>
                                                        @endif
                                                    </tr>
                                                </table>
                                            </td>
                                        </tr>

                                        <tr>
                                            <td valign="top" height="15"></td>
                                        </tr>

                                        <tr>
                                            <td valign="top" align="left">
                                                <p style="color:#000E26; margin:0; font-size:16px; font-weight:500; line-height:24px; font-family: -apple-system, BlinkMacSystemFont, avenir next, avenir, segoe ui, helvetica neue, helvetica, Cantarell, Ubuntu, roboto, noto, arial, sans-serif;">
                                                    @if(!empty($location?->address1))
                                                        {{ $location->address1 }},<br/>
                                                        {{ $location->city }},<br/>
                                                        {{ $location->postcode }}<br/>
                                                    @endif
                                                    @if(false){{ $phone_number_formatted }}@endif
                                                </p>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                                <td valign="top" width="65"></td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td valign="top" height="30"></td>
                </tr>
                <tr>
                    <td valign="top">
                        <table cellpadding="0" cellspacing="0" border="0" align="center" width="940">
                            <tr>
                                <td valign="top" height="1" bgcolor="#EEEEEE" style="background-color:#EEEEEE;"></td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td valign="top" height="30"></td>
                </tr>
                <tr>
                    <td valign="top">
                        <table cellpadding="0" cellspacing="0" border="0" align="center" width="940">
                            <tr>
                                <td valign="top" width="65"></td>
                                <td valign="top" align="center">
                                    <table cellpadding="0" cellspacing="0" border="0" align="center" width="100%">
                                        <tr>
                                            <td valign="top" align="center">
                                                <p style="color:#000E26; margin:0; font-size:14px; font-weight:400; font-family: -apple-system, BlinkMacSystemFont, avenir next, avenir, segoe ui, helvetica neue, helvetica, Cantarell, Ubuntu, roboto, noto, arial, sans-serif;">
                                                    Visit us online at <a href="{{ $site_url }}"
                                                                          target="_blank"
                                                                          style="color:#000E26; text-decoration: underline;">{{ $site_url }}</a>
                                                </p>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td valign="top" height="20"></td>
                                        </tr>
                                        <tr>
                                            <td valign="top" align="center">
                                                @yield('footer')
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                                <td valign="top" width="65"></td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td valign="top" height="50"></td>
    </tr>
    <!-- END OF FOOTER -->
</table>
<!-- End of wrapper table -->
</body>
</html>
