<?php
declare(strict_types=1);
// ==================================================
// Nuclear Fancy Pants Edition™ — NUCLEAR+++
// File: /templates/social/google-connect.php
// Description: Google Business Profile not-connected screen - OAuth connect flow - NUCLEAR+++
// Last Edited: 2026-04-20
// ==================================================

namespace AutoMarketerAI;

defined('ABSPATH') || exit;

$connect_url = GoogleAuth::getAuthUrl();
if ($connect_url === '') {
    echo '<div class="amai-notice amai-notice--warn" style="margin:32px auto;max-width:640px;padding:20px 24px;background:#FEF3C7;border:1.5px solid #FCD34D;border-radius:8px;font-size:14px;color:#78716C;">'
        . '<strong style="color:#57534E;">Google is not configured.</strong> '
        . 'The <code>AMAI_GOOGLE_CLIENT_ID</code> and <code>AMAI_GOOGLE_CLIENT_SECRET</code> constants are missing from <code>wp-config.php</code>. '
        . 'Add them to enable Google Business Profile and GA4.</div>';
    return;
}
$error_msg   = isset($_GET['amai_google_error']) ? sanitize_text_field(wp_unslash($_GET['amai_google_error'])) : '';
?>
<div class="amai-fb-connect-area">
    <div class="amai-fb-connect-shell">
        <div class="amai-fb-connect-hero">
            <div class="amai-fb-connect-icon" style="background:#fff;border-radius:16px;width:64px;height:64px;display:flex;align-items:center;justify-content:center;box-shadow:0 2px 8px rgba(0,0,0,0.10);">
                <svg width="36" height="36" viewBox="0 0 48 48" xmlns="http://www.w3.org/2000/svg">
                    <path fill="#4285F4" d="M47.5 24.5c0-1.6-.1-3.2-.4-4.7H24v9h13.2c-.6 3-2.3 5.5-4.8 7.2v6h7.7c4.5-4.1 7.4-10.2 7.4-17.5z"/>
                    <path fill="#34A853" d="M24 48c6.5 0 11.9-2.1 15.9-5.8l-7.7-6c-2.1 1.4-4.9 2.3-8.2 2.3-6.3 0-11.6-4.2-13.5-10H2.5v6.2C6.5 42.8 14.7 48 24 48z"/>
                    <path fill="#FBBC05" d="M10.5 28.5c-.5-1.4-.8-2.9-.8-4.5s.3-3.1.8-4.5v-6.2H2.5C.9 16.5 0 20.1 0 24s.9 7.5 2.5 10.7l8-6.2z"/>
                    <path fill="#EA4335" d="M24 9.5c3.5 0 6.7 1.2 9.2 3.6l6.9-6.9C36 2.4 30.5 0 24 0 14.7 0 6.5 5.2 2.5 13.3l8 6.2C12.4 13.7 17.7 9.5 24 9.5z"/>
                </svg>
            </div>
            <h2 class="amai-fb-connect-heading">Connect Google Business Profile</h2>
            <p class="amai-fb-connect-subheading">
                Link your Google Business Profile and we'll create and publish posts automatically.
                Keep your listing active, fresh, and visible to local customers.
            </p>
        </div>

        <?php if ($error_msg !== '') : ?>
        <div class="amai-fb-connect-error">
            <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
                <circle cx="8" cy="8" r="7" stroke="currentColor" stroke-width="1.3" fill="none"/>
                <path d="M8 4.5v4" stroke="currentColor" stroke-width="1.3" stroke-linecap="round"/>
                <circle cx="8" cy="11" r="0.6" fill="currentColor"/>
            </svg>
            <span><?php echo esc_html($error_msg); ?></span>
        </div>
        <?php endif; ?>

        <div class="amai-fb-connect-steps">
            <div class="amai-fb-connect-step">
                <div class="amai-fb-step-num">1</div>
                <div class="amai-fb-step-body">
                    <div class="amai-fb-step-title">Authorize with Google</div>
                    <div class="amai-fb-step-desc">Click the button below and sign in with the Google account that manages your Business Profile. We'll ask for permission to post on your behalf.</div>
                </div>
            </div>
            <div class="amai-fb-connect-step">
                <div class="amai-fb-step-num">2</div>
                <div class="amai-fb-step-body">
                    <div class="amai-fb-step-title">Select your business</div>
                    <div class="amai-fb-step-desc">We'll connect your first verified Google Business Profile location automatically.</div>
                </div>
            </div>
            <div class="amai-fb-connect-step">
                <div class="amai-fb-step-num">3</div>
                <div class="amai-fb-step-body">
                    <div class="amai-fb-step-title">Start generating content</div>
                    <div class="amai-fb-step-desc">We'll begin creating posts for your Google Business Profile automatically. Posts appear on your listing in Google Search and Maps.</div>
                </div>
            </div>
        </div>

        <div class="amai-fb-connect-cta">
            <a href="<?php echo esc_url($connect_url); ?>" class="amai-fb-connect-btn amai-fb-connect-btn--google" style="width:auto;align-self:center;">
                <svg width="18" height="18" viewBox="0 0 48 48" xmlns="http://www.w3.org/2000/svg" style="flex-shrink:0;">
                    <path fill="#4285F4" d="M47.5 24.5c0-1.6-.1-3.2-.4-4.7H24v9h13.2c-.6 3-2.3 5.5-4.8 7.2v6h7.7c4.5-4.1 7.4-10.2 7.4-17.5z"/>
                    <path fill="#34A853" d="M24 48c6.5 0 11.9-2.1 15.9-5.8l-7.7-6c-2.1 1.4-4.9 2.3-8.2 2.3-6.3 0-11.6-4.2-13.5-10H2.5v6.2C6.5 42.8 14.7 48 24 48z"/>
                    <path fill="#FBBC05" d="M10.5 28.5c-.5-1.4-.8-2.9-.8-4.5s.3-3.1.8-4.5v-6.2H2.5C.9 16.5 0 20.1 0 24s.9 7.5 2.5 10.7l8-6.2z"/>
                    <path fill="#EA4335" d="M24 9.5c3.5 0 6.7 1.2 9.2 3.6l6.9-6.9C36 2.4 30.5 0 24 0 14.7 0 6.5 5.2 2.5 13.3l8 6.2C12.4 13.7 17.7 9.5 24 9.5z"/>
                </svg>
                Connect with Google
            </a>
            <p class="amai-fb-connect-legal">
                Requires a verified Google Business Profile with Owner or Manager access.
            </p>
        </div>
    </div>
</div>