<?php

/* =========================================================
   COMPLETE BLISS - CONTACT SECTION
========================================================= */

require_once
    __DIR__ .
    '/../../config/database.php';


$contactSettings = [

    'company_name' => 'Complete Bliss Solutions',
    'support_phone' => '',
    'support_email' => '',
    'support_whatsapp' => ''

];


try {

    $contactStatement =
        $pdo->query(
            "
            SELECT
                company_name,
                support_phone,
                support_email,
                support_whatsapp
            FROM settings
            LIMIT 1
            "
        );


    $settingsRow =
        $contactStatement->fetch(
            PDO::FETCH_ASSOC
        );


    if ($settingsRow) {

        $contactSettings =
            array_merge(
                $contactSettings,
                $settingsRow
            );

    }

} catch (PDOException $e) {

    /*
        Keep the section usable even if
        settings cannot be loaded.
    */

}


/* =========================================================
   CLEAN CONTACT VALUES
========================================================= */

$companyName =
    trim(
        $contactSettings['company_name']
        ?: 'Complete Bliss Solutions'
    );


$supportPhone =
    trim(
        $contactSettings['support_phone']
        ?? ''
    );


$supportEmail =
    trim(
        $contactSettings['support_email']
        ?? ''
    );


$supportWhatsapp =
    trim(
        $contactSettings['support_whatsapp']
        ?? ''
    );


/* WhatsApp requires digits only */

$whatsappNumber =
    preg_replace(
        '/\D+/',
        '',
        $supportWhatsapp
    );


/*
    If number begins with 0,
    convert Nigerian format to 234.
*/

if (
    $whatsappNumber !== '' &&
    str_starts_with(
        $whatsappNumber,
        '0'
    )
) {

    $whatsappNumber =
        '234' .
        substr(
            $whatsappNumber,
            1
        );

}


$whatsappLink =
    $whatsappNumber !== ''
        ? 'https://wa.me/' .
          $whatsappNumber .
          '?text=' .
          rawurlencode(
              'Hello Complete Bliss, I would like to make an enquiry.'
          )
        : '';

?>


<section
    class="cbx-contact"
    id="contact"
>

    <div class="cbx-container">


        <div class="cbx-contact-shell">


            <!-- =====================================
                 LEFT SIDE
            ====================================== -->

            <div class="cbx-contact-intro">


                <div class="cbx-contact-tag">

                    <i class="fa-solid fa-paper-plane"></i>

                    <span>
                        GET IN TOUCH
                    </span>

                </div>


                <h2>

                    Have a question?

                    <span>
                        We’re here to help.
                    </span>

                </h2>


                <p>
                    Whether you need help understanding a scheme,
                    accessing your account or simply want more
                    information before joining, you can reach
                    <?= htmlspecialchars($companyName) ?>
                    through the available support channels.
                </p>


                <!-- TRUST POINTS -->

                <div class="cbx-contact-trust">


                    <div>

                        <i class="fa-solid fa-circle-check"></i>

                        <span>
                            Ask before you join
                        </span>

                    </div>


                    <div>

                        <i class="fa-solid fa-circle-check"></i>

                        <span>
                            Get account assistance
                        </span>

                    </div>


                    <div>

                        <i class="fa-solid fa-circle-check"></i>

                        <span>
                            Get scheme clarification
                        </span>

                    </div>


                </div>


            </div>



            <!-- =====================================
                 RIGHT CONTACT PANEL
            ====================================== -->

            <div class="cbx-contact-panel">


                <div class="cbx-contact-panel-heading">

                    <span>
                        CONTACT COMPLETE BLISS
                    </span>

                    <h3>
                        Choose the easiest way to reach us.
                    </h3>

                </div>



                <!-- WHATSAPP -->

                <?php if ($whatsappLink !== ''): ?>

                    <a
                        href="<?= htmlspecialchars($whatsappLink) ?>"
                        target="_blank"
                        rel="noopener noreferrer"
                        class="cbx-contact-option cbx-contact-whatsapp"
                    >

                        <div class="cbx-contact-option-icon">

                            <i class="fa-brands fa-whatsapp"></i>

                        </div>


                        <div>

                            <span>
                                WHATSAPP
                            </span>

                            <strong>
                                Chat With Us
                            </strong>

                            <small>
                                <?= htmlspecialchars($supportWhatsapp) ?>
                            </small>

                        </div>


                        <i class="fa-solid fa-arrow-up-right-from-square"></i>

                    </a>

                <?php endif; ?>



                <!-- PHONE -->

                <?php if ($supportPhone !== ''): ?>

                    <a
                        href="tel:<?= htmlspecialchars(
                            preg_replace(
                                '/[^0-9+]/',
                                '',
                                $supportPhone
                            )
                        ) ?>"
                        class="cbx-contact-option cbx-contact-phone"
                    >

                        <div class="cbx-contact-option-icon">

                            <i class="fa-solid fa-phone"></i>

                        </div>


                        <div>

                            <span>
                                PHONE
                            </span>

                            <strong>
                                Call Complete Bliss
                            </strong>

                            <small>
                                <?= htmlspecialchars($supportPhone) ?>
                            </small>

                        </div>


                        <i class="fa-solid fa-arrow-right"></i>

                    </a>

                <?php endif; ?>



                <!-- EMAIL -->

                <?php if ($supportEmail !== ''): ?>

                    <a
                        href="mailto:<?= htmlspecialchars($supportEmail) ?>"
                        class="cbx-contact-option cbx-contact-email"
                    >

                        <div class="cbx-contact-option-icon">

                            <i class="fa-solid fa-envelope"></i>

                        </div>


                        <div>

                            <span>
                                EMAIL
                            </span>

                            <strong>
                                Send Us an Email
                            </strong>

                            <small>
                                <?= htmlspecialchars($supportEmail) ?>
                            </small>

                        </div>


                        <i class="fa-solid fa-arrow-right"></i>

                    </a>

                <?php endif; ?>



                <!-- =====================================
                     NO CONTACT DETAILS
                ====================================== -->

                <?php if (
                    $supportPhone === '' &&
                    $supportEmail === '' &&
                    $whatsappLink === ''
                ): ?>

                    <div class="cbx-contact-empty">

                        <i class="fa-solid fa-circle-info"></i>

                        <p>
                            Support contact details will
                            appear here once configured.
                        </p>

                    </div>

                <?php endif; ?>



                <!-- MEMBER CTA -->

                <div class="cbx-contact-member-cta">


                    <div>

                        <span>
                            READY TO GET STARTED?
                        </span>

                        <strong>
                            Create your Complete Bliss account.
                        </strong>

                    </div>


                    <a href="register.php">

                        Become a Member

                        <i class="fa-solid fa-arrow-right"></i>

                    </a>


                </div>


            </div>


        </div>


    </div>

</section>