"""Jami-Dating Werbebanner – statisch & animiert (ClipWelle & Co.)."""

from __future__ import annotations

import html
import urllib.parse

from jam.jami_animated_ad import (
    dating_ad_embed_css,
    dating_ad_embed_html,
    dating_ad_embed_script,
)

JAMI_SITE_URL = "https://www.jami-dating.de"
JAMI_LOGO = f"{JAMI_SITE_URL}/images/jami-dating-logo.png"


def jami_signup_url(
    *,
    utm_source: str = "vidpuls",
    utm_medium: str = "banner",
    utm_campaign: str = "crosspromo",
) -> str:
    q = urllib.parse.urlencode(
        {
            "utm_source": utm_source,
            "utm_medium": utm_medium,
            "utm_campaign": utm_campaign,
        }
    )
    return f"{JAMI_SITE_URL}/?{q}"


def jami_promo_banner_css(*, animated: bool = True, variant: str = "compact") -> str:
    if animated:
        return dating_ad_embed_css(compact=variant != "wide")
    return _static_banner_css()


def jami_promo_banner_html(
    *,
    variant: str = "compact",
    utm_source: str = "vidpuls",
    utm_medium: str = "banner",
    animated: bool = True,
) -> str:
    """variant: compact (Sidebar) | wide (Landing). animated: Facebook-Ad-Workflow."""
    if animated:
        embed_id = "jamiAdWide" if variant == "wide" else "jamiAdCompact"
        wrap_open = '<div class="jami-promo-wrap">' if variant == "wide" else ""
        wrap_close = "</div>" if variant == "wide" else ""
        inner = dating_ad_embed_html(
            signup_url=jami_signup_url(utm_source=utm_source, utm_medium=utm_medium),
            logo_url=JAMI_LOGO,
            variant=variant,
            embed_id=embed_id,
        )
        if variant == "wide":
            return f'{wrap_open}<div style="max-width:880px;margin:0 auto 1.25rem;padding:0 1.25rem">{inner}</div>{wrap_close}'
        return inner

    return _static_banner_html(
        variant=variant, utm_source=utm_source, utm_medium=utm_medium
    )


def jami_promo_banner_script(*, animated: bool = True) -> str:
    if animated:
        return dating_ad_embed_script()
    return ""


def _static_banner_css() -> str:
    return """
.jami-promo-banner {
  display: block;
  text-decoration: none;
  color: inherit;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid rgba(255, 77, 141, 0.35);
  background:
    radial-gradient(ellipse 120% 80% at 10% 0%, rgba(255, 77, 141, 0.22), transparent 55%),
    linear-gradient(145deg, rgba(26, 10, 40, 0.95), rgba(12, 6, 18, 0.98));
}
.jami-promo-inner { padding: 0.85rem 0.95rem 1rem; }
.jami-promo-cta {
  display: inline-block; width: 100%; text-align: center;
  padding: 0.55rem; border-radius: 999px; font-weight: 800;
  background: linear-gradient(135deg, #ffc107, #ff9800); color: #1a0a10;
}
"""


def _static_banner_html(
    *,
    variant: str,
    utm_source: str,
    utm_medium: str,
) -> str:
    href = html.escape(jami_signup_url(utm_source=utm_source, utm_medium=utm_medium))
    logo = html.escape(JAMI_LOGO)
    return f"""<a class="jami-promo-banner" href="{href}" target="_blank" rel="noopener sponsored">
  <div class="jami-promo-inner">
    <img src="{logo}" width="44" height="44" alt="Jami" loading="lazy"/>
    <strong>Jami-Dating · 100 Coins gratis</strong>
    <span class="jami-promo-cta">Jetzt testen</span>
  </div>
</a>"""
