
from __future__ import annotations
from typing import Dict, Union
from bs4 import BeautifulSoup
from ..registry import extractor
from ..helpers.price import parse_price

@extractor
def ex_regular_price_fallback(soup: BeautifulSoup, url: str) -> Dict:
    """
    Fallback extractor for legacy 'Regular Price' blocks outside oe-list-price:
      <div class="rrp-price"><label>Regular Price: </label><span class="price">£16.55</span></div>
    """
    rrp = soup.select_one("div.rrp-price")
    if not rrp:
        return {}
    span = rrp.select_one("span.price")
    price_text = span.get_text(strip=True) if span else rrp.get_text(" ", strip=True)
    value, currency, raw = parse_price(price_text or "")
    out: Dict[str, Union[str, float]] = {}
    if raw:
        out["regular_price_raw"] = raw
    if value is not None:
        out["regular_price"] = value
    if currency:
        out["regular_price_currency"] = currency
    if value is not None:
        out.setdefault("rrp", value)
    if currency:
        out.setdefault("rrp_currency", currency)
    if raw:
        out.setdefault("rrp_raw", raw)
    return out
