<?php
/**
 * Onboarding banner — shown at the top of every plugin admin page when the
 * site is not connected to the SaaS. A single purple "Connect your site" CTA.
 *
 * Also contains the shared `.tts-ob-*` styles used by the richer onboarding
 * experience on the Overview / Settings page (connect card + steps + demo +
 * stats + help links). Keeping the CSS here means there's a single source of
 * truth; the Settings page only needs to render the additional HTML blocks.
 *
 * Included automatically from admin/partials/layout-open.php — pages don't
 * need to include it directly. Pages can suppress it by setting
 * `$tts_hide_onboarding = true;` before including the layout.
 *
 * @package TTSWP
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

// Banner HTML is suppressed on pages that render their own richer onboarding
// (currently Overview / Settings). The shared CSS further below still emits so
// that page's own `.tts-ob-*` markup picks up the styles.
if ( empty( $tts_hide_onboarding ) ) :
    $tts_ob_connect_url = Mementor_TTS_Connect::get_connect_url();
?>
<a href="<?php echo esc_url( $tts_ob_connect_url ); ?>" class="tts-ob-connect">
    <div class="tts-ob-connect-accent"></div>
    <div class="tts-ob-connect-inner">
        <div class="tts-ob-connect-left">
            <div class="tts-ob-connect-icon">
                <svg width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="#fff" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"/><path d="M19 10v2a7 7 0 0 1-14 0v-2"/><line x1="12" y1="19" x2="12" y2="23"/><line x1="8" y1="23" x2="16" y2="23"/></svg>
            </div>
            <div>
                <h2 class="tts-ob-connect-title"><?php esc_html_e( 'Connect your site to start generating audio', 'text-to-speech-tts' ); ?></h2>
                <p class="tts-ob-connect-desc"><?php esc_html_e( 'Activate your site and get 10,000 free credits instantly. No setup required.', 'text-to-speech-tts' ); ?></p>
            </div>
        </div>
        <div class="tts-ob-connect-right">
            <span class="tts-ob-connect-btn"><?php esc_html_e( 'Get Started', 'text-to-speech-tts' ); ?> &rarr;</span>
        </div>
    </div>
</a>
<?php endif; ?>

<?php
/**
 * The shared onboarding CSS below is only enqueued once per request — the
 * `$GLOBALS['tts_ob_styles_printed']` guard prevents duplicate output if the
 * partial is ever included twice (e.g. in nested admin screens).
 */
if ( empty( $GLOBALS['tts_ob_styles_printed'] ) ) :
    $GLOBALS['tts_ob_styles_printed'] = true;
?>
<style>
/* ── Onboarding: Connect Card ── */
.tts-ob-connect { display: block; background: #1e1b4b; border: none; border-radius: 10px; overflow: hidden; margin-bottom: 16px; text-decoration: none; cursor: pointer; transition: transform 0.15s, box-shadow 0.15s; }
.tts-ob-connect:hover { transform: translateY(-1px); box-shadow: 0 8px 24px rgba(30, 27, 75, 0.3); }
.tts-ob-connect-accent { height: 3px; background: linear-gradient(90deg, #a78bfa, #6B45D4, #a78bfa); }
.tts-ob-connect-inner { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 24px 28px; }
.tts-ob-connect-left { display: flex; align-items: center; gap: 16px; }
.tts-ob-connect-icon { width: 48px; height: 48px; background: rgba(255,255,255,0.12); border-radius: 12px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.tts-ob-connect-title { font-size: 18px; font-weight: 600; color: #fff; margin: 0 0 4px; }
.tts-ob-connect-desc { font-size: 14px; color: rgba(255,255,255,0.6); margin: 0; }
.tts-ob-connect-right { text-align: center; flex-shrink: 0; }
.tts-ob-connect-btn { display: inline-block; padding: 14px 28px; font-size: 15px; font-weight: 700; background: #fff; color: #1e1b4b; border-radius: 8px; text-decoration: none; animation: tts-ob-pulse 2s ease-in-out infinite; }
.tts-ob-connect-btn:hover { background: #f3f0ff; color: #6B45D4; box-shadow: 0 0 20px rgba(167, 139, 250, 0.3); }

@keyframes tts-ob-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255,255,255,0.2); }
    50% { box-shadow: 0 0 0 8px rgba(255,255,255,0); }
}

/* ── Onboarding: Steps (used on Settings/Overview only) ── */
.tts-ob-steps { margin-bottom: 16px; }
.tts-ob-step { padding: 20px; animation: tts-ob-fadeup 0.5s ease both; transition: border-color 0.2s, box-shadow 0.2s; }
.tts-ob-step-header { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.tts-ob-step-num { width: 28px; height: 28px; background: var(--tts-purple); color: #fff; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; flex-shrink: 0; }
.tts-ob-step h3 { font-size: 14px; font-weight: 600; color: var(--tts-text-primary); margin: 0; }
.tts-ob-step p { font-size: 13px; color: #6b7280; margin: 0; line-height: 1.5; }
.tts-ob-step:hover { border-color: var(--tts-purple-border); box-shadow: 0 0 0 3px rgba(107, 69, 212, 0.08); }
.tts-ob-step--cta { cursor: pointer; text-decoration: none; color: inherit; }

/* ── Onboarding: Demo Player (Settings/Overview only) ── */
.tts-ob-demo { padding: 20px; margin-bottom: 16px; animation: tts-ob-fadeup 0.5s ease both; background: #f3f0ff; border-color: #e0d9ff; }
.tts-ob-demo-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--tts-purple); margin-bottom: 12px; display: block; }
.tts-ob-demo-player { display: flex; align-items: center; gap: 14px; }
.tts-ob-play-btn { width: 44px; height: 44px; background: var(--tts-purple); border: none; border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: transform 0.15s; flex-shrink: 0; }
.tts-ob-play-btn:hover { transform: scale(1.08); }
.tts-ob-waveform { display: flex; align-items: center; gap: 2px; height: 36px; flex: 1; }
.tts-ob-waveform-bar { width: 3px; border-radius: 2px; background: #d4d0e8; transition: background 0.2s; }
.tts-ob-waveform-bar.active { background: var(--tts-purple); }
.tts-ob-waveform.playing .tts-ob-waveform-bar { animation: tts-ob-wave 0.8s ease-in-out infinite alternate; }
.tts-ob-meta { flex-shrink: 0; text-align: right; }
.tts-ob-meta-title { display: block; font-size: 13px; font-weight: 500; color: var(--tts-text-primary); }
.tts-ob-meta-sub { display: block; font-size: 11px; color: #6a6d73; }

/* ── Onboarding: Stats (Settings/Overview only) ── */
.tts-ob-stats { margin-bottom: 16px; }
.tts-ob-stat { padding: 20px; text-align: center; animation: tts-ob-fadeup 0.5s ease both; }
.tts-ob-stat-value { display: block; font-size: 24px; font-weight: 700; color: var(--tts-purple); }
.tts-ob-stat-label { display: block; font-size: 12px; color: #6b7280; margin-top: 8px; }

/* ── Onboarding: Help Links (Settings/Overview only) ── */
.tts-ob-help-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.tts-ob-help-card { display: flex; align-items: center; gap: 14px; padding: 18px 20px; text-decoration: none; color: inherit; transition: border-color 0.2s, box-shadow 0.2s; animation: tts-ob-fadeup 0.5s ease both; }
.tts-ob-help-card:hover { border-color: var(--tts-purple-border); box-shadow: 0 0 0 3px rgba(107, 69, 212, 0.06); }
.tts-ob-help-icon { width: 40px; height: 40px; background: #f3f0ff; border-radius: 10px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; color: var(--tts-purple); }
.tts-ob-help-card h3 { font-size: 14px; font-weight: 600; color: var(--tts-text-primary); margin: 0 0 2px; }
.tts-ob-help-card p { font-size: 12px; color: #6b7280; margin: 0; }

/* ── Animations ── */
@keyframes tts-ob-fadeup {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes tts-ob-wave {
    0% { transform: scaleY(0.4); }
    100% { transform: scaleY(1); }
}

/* ── Locked state for gated pages while disconnected ── */
.tts-main-content.is-locked { position: relative; }
.tts-main-content.is-locked > *:not(.tts-ob-connect) {
    opacity: 0.5;
    filter: grayscale(0.5);
    pointer-events: none;
    user-select: none;
}

@media (max-width: 782px) {
    .tts-ob-connect-inner { flex-direction: column; align-items: flex-start; }
    .tts-ob-help-row { grid-template-columns: 1fr; }
}
</style>
<?php endif; ?>
