"""Page bodies for the Lowe's offline clone.
Home-page structure follows the captured desktop screenshot top to bottom:
promotion strip, masthead, category nav, "Recommended Searches for You" chips,
the dark promotional hero with its brand row and savings table, the
"Members Get More" strip, then the deal cards. Everything below that fold, and
every route other than ``/`` and the account drawer, is clone-authored around
the synthetic catalog; ``scope/claims.jsonl`` records which is which.
"""
from __future__ import annotations
from typing import Any, Mapping, Sequence
from urllib.parse import urlencode
from backend import store as site_store
from ui.icons import icon
from ui.layout import Chrome, attr, esc
STAR_FULL = "★"
STAR_EMPTY = "☆"
# ---------------------------------------------------------------------------
# small components
# ---------------------------------------------------------------------------
def image_url(product: Mapping[str, Any], view: str = "front") -> str:
return f"/img/p/{product['id']}/{view}.svg"
def price_block(product: Mapping[str, Any]) -> str:
dollars, cents = site_store.money_parts(int(product["price_cents"]))
was = product.get("was_cents")
extra = ""
if was:
saved = int(was) - int(product["price_cents"])
extra = (
f'was ${esc(site_store.money(int(was)))}'
f'Save ${esc(site_store.money(saved))}'
)
return (
'
'
f'${esc(dollars)}{esc(cents)}'
f"{extra}
"
)
def rating_block(product: Mapping[str, Any]) -> str:
rating = float(product["rating"])
filled = int(rating + 0.5)
stars = STAR_FULL * filled + STAR_EMPTY * (5 - filled)
average = "{:.1f}".format(rating)
reviews = "{:,}".format(int(product["review_count"]))
return (
''
f'{esc(stars)}'
f"{esc(average)} ({esc(reviews)} reviews)"
""
)
def fulfillment_block(product: Mapping[str, Any], store_name: str) -> str:
pickup = (
f"Free pickup today at {esc(store_name)}"
if product["pickup_today"]
else "Not available for store pickup"
)
delivery = (
f"Free delivery in {esc(product['delivery_days'])} days"
if product["free_delivery"]
else f"Delivery in {esc(product['delivery_days'])} days"
)
return f'
{pickup}{delivery}
'
def product_card(product: Mapping[str, Any], store_name: str) -> str:
flag = ""
if product.get("badge"):
flag = (
''
f'{esc(product["badge"])}'
)
return (
''
f"{flag}"
f''
f''
'
'
+ "".join(product_card(product, store_name) for product in products)
+ "
"
)
def breadcrumbs(trail: Sequence[tuple[str, str | None]]) -> str:
parts: list[str] = []
for label, href in trail:
if href:
parts.append(f'{esc(label)}')
else:
parts.append(f"{esc(label)}")
return '"
def _query_string(base: Mapping[str, Any], **overrides: Any) -> str:
merged: list[tuple[str, str]] = []
for key, value in base.items():
if key in overrides:
continue
if isinstance(value, (list, tuple)):
merged.extend((key, str(item)) for item in value)
elif value not in (None, "", False):
merged.append((key, str(value)))
for key, value in overrides.items():
if isinstance(value, (list, tuple)):
merged.extend((key, str(item)) for item in value)
elif value not in (None, "", False):
merged.append((key, str(value)))
return urlencode(merged)
# ---------------------------------------------------------------------------
# home
# ---------------------------------------------------------------------------
def home(
chrome: Chrome,
*,
recommended: Sequence[str],
deals: Sequence[Mapping[str, Any]],
top_sellers: Sequence[Mapping[str, Any]],
) -> str:
store_name = (chrome.store or {}).get("name", "your store")
chips = "".join(
f'{esc(term)}'
for term in recommended
)
return (
''
'
'
"myLowe’s Rewards"
"Members Get More when you spend $1,799 or more on "
"select Frigidaire and Electrolux major appliances."
"FREE Delivery and Haul Away"
"FREE Basic Installation and Installation Parts"
"2-Year Lowe’s Protection Plan"
"
"
"
"
)
SERVICES: tuple[tuple[str, str, str, str], ...] = (
(
"tools",
"Installation Services",
"Book a local installer for appliances, flooring, windows and more.",
"/services/installation",
),
(
"truck",
"Delivery & Haul Away",
"Schedule delivery to your ZIP code and have the old unit taken away.",
"/help/delivery",
),
(
"store",
"Store Pickup",
"Buy online and pick up at the store you selected in the header.",
"/help/pickup",
),
(
"points",
"myLowe's Rewards",
"Earn points on eligible purchases and get member-only offers.",
"/rewards",
),
)
def services_section() -> str:
cards = "".join(
''
+ icon(glyph, 26)
+ f"
{esc(title)}
{esc(copy)}
"
f'Learn more'
""
for glyph, title, copy, href in SERVICES
)
return (
''
'
How We Can Help
'
f'
{cards}
'
""
)
# ---------------------------------------------------------------------------
# search results
# ---------------------------------------------------------------------------
def search_results(
chrome: Chrome,
*,
result: Mapping[str, Any],
params: Mapping[str, Any],
categories: Sequence[Mapping[str, Any]],
brands: Sequence[str],
) -> str:
store_name = (chrome.store or {}).get("name", "your store")
heading = (
f'Results for "{result["query"]}"' if result["query"] else "Shop all products"
)
label_by_id = {str(row["id"]): str(row["label"]) for row in categories}
applied: list[str] = []
for category_id in params.get("category", []):
applied.append(
''
f'{esc(label_by_id.get(category_id, category_id))} {icon("close", 12)}'
)
for brand in params.get("brand", []):
applied.append(
''
f'{esc(brand)} {icon("close", 12)}'
)
if params.get("min_price") or params.get("max_price"):
applied.append(
''
f'${esc(params.get("min_price") or "0")}–${esc(params.get("max_price") or "any")} '
f'{icon("close", 12)}'
)
if params.get("rating"):
applied.append(
''
f'{esc(params["rating"])}+ stars {icon("close", 12)}'
)
for flag, label in (("pickup", "Pickup today"), ("free_delivery", "Free delivery")):
if params.get(flag):
applied.append(
''
f'{esc(label)} {icon("close", 12)}'
)
applied_html = (
f'
"
if applied
else ""
)
sort_options = "".join(
f'"
for key, label in site_store.SORT_OPTIONS
)
body = (
card_grid(result["products"], store_name)
if result["products"]
else (
'
No results.
'
"
Try fewer filters or a different search term. This offline clone "
"carries a fixed synthetic catalog, so it will not match every real "
"Lowe’s product.
'
for label, value in rows
)
cta = ""
if action and not submit:
cta = (
f''
f"{esc(action_label)}"
)
elif submit:
cta = (
'"
)
return (
'"
)
# ---------------------------------------------------------------------------
# checkout
# ---------------------------------------------------------------------------
def checkout_page(
chrome: Chrome,
*,
cart: Mapping[str, Any],
totals: Mapping[str, Any],
form: Mapping[str, Any],
errors: Mapping[str, str],
scenarios: Sequence[Mapping[str, str]],
payment: Mapping[str, Any] | None = None,
) -> str:
fulfillment = str(form.get("fulfillment", "pickup"))
store_options = "".join(
f''
for item in chrome.stores
)
scenario_inputs = "".join(
'"
for item in scenarios
)
payment_notice = ""
if payment:
status = str(payment["status"])
wording = {
"DECLINED": "The local sandbox declined this simulated payment. Nothing "
"was charged and your cart is unchanged. Pick another scenario to retry.",
"RETRYABLE": "The local sandbox returned a retryable result. Nothing was "
"charged and your cart is unchanged. Submit again to retry.",
}.get(status, "The local sandbox returned an unexpected result.")
payment_notice = (
'
Simulated locally. No payment was taken and '
"no message was delivered; the confirmation was written to this clone’s "
"local outbox with template variables only.
This offline clone does not open third-party or legal '
f"destinations. The source page linked to {esc(slug)}; no "
"remote request was made and nothing was fetched.