"""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'' 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'{attr(product[' '
' f'{esc(product["brand"])}' f'' f'{esc(product["title"])}' + price_block(product) + rating_block(product) + fulfillment_block(product, store_name) + "
" ) def card_grid(products: Sequence[Mapping[str, Any]], store_name: str) -> str: return ( '
' + "".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 ( '
' '
' '

Recommended Searches for You

' 'More Suggestions for You ' + icon("chevron", 14) + "" "
" f'
{chips}
' "
" + hero_section() + '
' '
' '

Appliance Special Values

' 'Shop all deals ' + icon("chevron", 14) + "
" + card_grid(deals, store_name) + "
" '
' '
' '

Top Sellers in Your Area

' 'Shop top sellers ' + icon("chevron", 14) + "
" + card_grid(top_sellers, store_name) + "
" + services_section() ) def hero_section() -> str: brands = "".join( f"{esc(name)}" for name in ( "Electrolux", "Frigidaire", "Frigidaire Gallery", "Frigidaire Professional", ) ) return ( '
' '

Electrolux End-of-Summer Sale

' f'
{brands}
' '
' "
" '

Frigidaire

' '

Save up to

' '

$300

' '

When you bundle select Frigidaire major appliances.

' '' "" "" "" "" "" "
SaveWhen You Buy
$1002
$2003
$3004 or More
" 'Shop Now' "
" '
' 'Illustrated kitchen with a range, refrigerator and island' "
" "
" '
' "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'
{"".join(applied)}' '' "Clear all
" 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.

" '

Browse everything

' "
" ) ) return ( breadcrumbs([("Home", "/"), ("Search results", None)]) + '
' f'

{esc(heading)}

' '
' + _filters_form(params, categories, brands, result) + "
" + applied_html + '
' '

' + ( f'Showing {esc(result["first_index"])}–{esc(result["last_index"])} of ' f'{esc(result["total"])} results' if result["total"] else "0 results" ) + "

" '
' + _hidden_params(params, drop={"sort", "page"}) + '' '" '' "
" "
" + body + _pagination(result, params) + "
" ) def _hidden_params(params: Mapping[str, Any], *, drop: set[str]) -> str: fields: list[str] = [] for key, value in params.items(): if key in drop: continue values = value if isinstance(value, (list, tuple)) else [value] for item in values: if item in (None, "", False): continue fields.append( f'' ) return "".join(fields) def _filters_form( params: Mapping[str, Any], categories: Sequence[Mapping[str, Any]], brands: Sequence[str], result: Mapping[str, Any], ) -> str: selected_categories = set(params.get("category", [])) selected_brands = set(params.get("brand", [])) facet_categories = result["facet_categories"] facet_brands = result["facet_brands"] category_options = "".join( '" for row in categories ) brand_options = "".join( '" for name in brands ) rating_options = "".join( '' for value in ("4.5", "4", "3") ) return ( '
' f'' f'' '
' 'Department' + category_options + "
" '
' 'Brand' + brand_options + "
" '
' 'Price' '
' '' '' '' '' "
" '
' 'Customer Rating' + rating_options + "
" '
' 'Availability' '" '" "
" '" "
" ) def _pagination(result: Mapping[str, Any], params: Mapping[str, Any]) -> str: if result["page_count"] <= 1: return "" links: list[str] = [] if result["page"] > 1: links.append( '' ) for number in range(1, int(result["page_count"]) + 1): current = ' aria-current="page"' if number == result["page"] else "" links.append( f'{esc(number)}' ) if result["page"] < result["page_count"]: links.append( '' ) return ( '" ) # --------------------------------------------------------------------------- # product detail # --------------------------------------------------------------------------- def product_detail( chrome: Chrome, *, product: Mapping[str, Any], category_label: str, related: Sequence[Mapping[str, Any]], message: str = "", error: str = "", ) -> str: store_name = (chrome.store or {}).get("name", "your store") thumbs = "".join( f'' for index, view in enumerate(("front", "angle", "detail")) ) specs = "".join( f"{esc(name)}{esc(value)}" for name, value in product["specs"] ) notices = "" if message: notices += f'

{esc(message)}

' if error: notices += f'

{esc(error)}

' pickup_disabled = "" if product["pickup_today"] else " disabled" pickup_note = ( f"Free pickup today at {store_name}" if product["pickup_today"] else "Not available for pickup" ) return ( breadcrumbs( [ ("Home", "/"), (category_label, f"/search?category={product['category_id']}"), (product["title"], None), ] ) + '
' + notices + '
' f'
{thumbs}
' '
' f'{attr(product[' "
" '
' f'

{esc(product["brand"])}

' f'

{esc(product["title"])}

' + rating_block(product) + price_block(product) + f"

{esc(product['summary'])}

" f'

Model # {esc(product["model_number"])} ' f'· Item # {esc(product["id"])}

' '
' f'' f'' '
' '" '' "
" '
' '
' '" '' '' '
" '' "
" + fulfillment_block(product, store_name) + f'

{esc(product["stock"])} in stock at this ' "location in the clone’s synthetic inventory.

" "
" '
' "

Specifications

" f'{specs}
' "
" + ( '
' '

' "Customers also viewed

" + card_grid(related, store_name) + "
" if related else "" ) + "
" ) # --------------------------------------------------------------------------- # cart # --------------------------------------------------------------------------- def cart_page( chrome: Chrome, *, cart: Mapping[str, Any], totals: Mapping[str, Any], message: str = "", error: str = "", ) -> str: if not cart["items"]: return ( breadcrumbs([("Home", "/"), ("Cart", None)]) + '
' '

Your cart is empty

' '

Nothing has been added yet.

' '

' "Shop top sellers

" ) lines = "".join(_cart_line(item) for item in cart["items"]) notices = "" if message: notices += f'

{esc(message)}

' if error: notices += f'

{esc(error)}

' return ( breadcrumbs([("Home", "/"), ("Cart", None)]) + '
' f'

Cart ({esc(cart["units"])} ' f'{esc("item" if cart["units"] == 1 else "items")})

' + notices + '
' + lines + "
" + summary_panel(totals, cart, action="/checkout", action_label="Proceed to Checkout") + "
" ) def _cart_line(item: Mapping[str, Any]) -> str: art = "/img/p/{}/front.svg".format(int(item["product_id"])) return ( '
' '
' f'{attr(item[
' "
" f'

{esc(item["brand"])}

' f'{esc(item["title"])}' '
' '
' f'' '
' '" f'' f'' '
" '' "
" '
' f'' '' "
" '
' f'' '' '
" "
" '

' + esc("Store pickup" if item["fulfillment"] == "pickup" else "Delivery") + "

" "
" '
' f'${esc(site_store.money(int(item["line_total_cents"])))}' "
" "
" ) def summary_panel( totals: Mapping[str, Any], cart: Mapping[str, Any], *, action: str | None = None, action_label: str = "", submit: bool = False, ) -> str: rows = [ ("Subtotal", f"${site_store.money(int(totals['subtotal_cents']))}"), ( "Savings", f"-${site_store.money(int(totals['savings_cents']))}" if totals["savings_cents"] else "$0.00", ), ( "Delivery", "FREE" if totals["delivery_cents"] == 0 else f"${site_store.money(int(totals['delivery_cents']))}", ), ("Estimated tax", f"${site_store.money(int(totals['tax_cents']))}"), ] row_html = "".join( f'
{esc(label)}{esc(value)}
' 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 = ( '

{esc(status)} {esc(wording)}

' ) error_summary = "" if errors: error_summary = ( '

Check the highlighted fields below.

' ) def field_error(name: str) -> str: return ( f'{esc(errors[name])}' if name in errors else "" ) return ( breadcrumbs([("Home", "/"), ("Cart", "/cart"), ("Checkout", None)]) + '
' '

Checkout

' '
    ' '
  1. Cart
  2. ' '
  3. Fulfillment & payment
  4. ' "
  5. Confirmation
" + error_summary + payment_notice + '
' '
' '
' 'How do you want it?' '" '" + field_error("fulfillment") + '" + field_error("store_id") + "
" '
' 'Contact' + _text_field("first_name", "First name", form, errors, "given-name") + _text_field("last_name", "Last name", form, errors, "family-name") + _text_field("email", "Email", form, errors, "email", kind="email") + "
" '
' 'Delivery address' '

Required only when delivery is selected.

' + _text_field("address_1", "Street address", form, errors, "address-line1") + _text_field( "address_2", "Apartment, suite (optional)", form, errors, "address-line2" ) + _text_field("city", "City", form, errors, "address-level2") + _text_field("state", "State (2 letters)", form, errors, "address-level1") + _text_field("zip", "ZIP code", form, errors, "postal-code") + "
" '
' 'Local sandbox payment' '

Local sandbox only. This ' "clone never accepts a card number, CVV, expiry, bank or wallet credential. " "Choose one deterministic outcome below; the amount, currency and order " "fingerprint are computed on the server from your saved cart.

" + scenario_inputs + field_error("scenario_id") + "
" + field_error("cart") + "
" + summary_panel(totals, cart, action_label="Place order", submit=True) + "
" ) def _text_field( name: str, label: str, form: Mapping[str, Any], errors: Mapping[str, str], autocomplete: str, *, kind: str = "text", ) -> str: error = ( f'{esc(errors[name])}' if name in errors else "" ) return ( f'{error}' ) # --------------------------------------------------------------------------- # order confirmation + account # --------------------------------------------------------------------------- def _order_line(item: Mapping[str, Any]) -> str: art = "/img/p/{}/front.svg".format(int(item["product_id"])) return ( '
' f'
{attr(item[
' f'

{esc(item["brand"])}

' f'' f'{esc(item["title"])}' f'

Qty {esc(item["quantity"])} · ' + esc("Store pickup" if item["fulfillment"] == "pickup" else "Delivery") + "

" f'
' f'${esc(site_store.money(int(item["line_total_cents"])))}
' "
" ) def order_confirmation(order: Mapping[str, Any]) -> str: items = "".join(_order_line(item) for item in order["items"]) if order["fulfillment"] == "pickup": store = order.get("store") or {} where = ( f"Pickup at {store.get('name', 'your store')}, {store.get('city', '')}, " f"{store.get('state', '')}" ) else: address = order.get("address") or {} where = ( f"Delivery to {address.get('address_1', '')}, {address.get('city', '')}, " f"{address.get('state', '')} {address.get('zip', '')}" ) mail = order.get("mail") or {} return ( breadcrumbs([("Home", "/"), ("Orders", "/account/orders"), (order["order_number"], None)]) + '
' '
' f'

Order {esc(order["order_number"])} is placed

' f'

{esc(where)}

' f'

payment {esc(order["payment_status"])} ' f'scenario {esc(order["scenario_id"])} ' f'mail {esc(mail.get("status", "none"))}

' '

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.

" "
" '
' + items + "
" + summary_panel( { "subtotal_cents": order["subtotal_cents"], "savings_cents": order["savings_cents"], "delivery_cents": order["delivery_cents"], "tax_cents": order["tax_cents"], "total_cents": order["total_cents"], }, { "units": sum(int(item["quantity"]) for item in order["items"]), "count": len(order["items"]), }, action="/search?sort=top-sellers", action_label="Keep shopping", ) + "
" ) def account_page( chrome: Chrome, *, account: Mapping[str, Any], orders: Sequence[Mapping[str, Any]] ) -> str: order_rows = "".join( "" f'' f'{esc(order["order_number"])}' f'{esc(order["fulfillment"])}' f'{esc(len(order["items"]))} items' f'${esc(site_store.money(int(order["total_cents"])))}' f'{esc(order["payment_status"])}' "" for order in orders ) table = ( '' "" f"{order_rows}
OrderFulfillmentItemsTotalPayment
" if orders else '

No orders in this clone yet.

' ) return ( breadcrumbs([("Home", "/"), ("Account", None)]) + '
' f'

Hi, {esc(account.get("display_name", ""))}

' f'

Signed in as {esc(account.get("contact_display", ""))}.

' '

Order Status

' + table + "
" '
' '' "
" "
" ) def orders_page(chrome: Chrome, *, orders: Sequence[Mapping[str, Any]]) -> str: if not orders: return ( breadcrumbs([("Home", "/"), ("Order Status", None)]) + '

Order Status

' '

This browser session has no orders yet.

' '

Go to your cart

' "
" ) rows = "".join( "" f'' f'{esc(order["order_number"])}' f'{esc(order["customer_name"])}' f'{esc(order["fulfillment"])}' f'${esc(site_store.money(int(order["total_cents"])))}' "" for order in orders ) return ( breadcrumbs([("Home", "/"), ("Order Status", None)]) + '

Order Status

' '' "" f"{rows}
OrderNameFulfillmentTotal
" ) # --------------------------------------------------------------------------- # supporting pages # --------------------------------------------------------------------------- def departments_page( chrome: Chrome, *, categories: Sequence[Mapping[str, Any]], counts: Mapping[str, int] ) -> str: cards = "".join( '
' + icon("grid", 24) + f'

{esc(row["label"])}

' f'

{esc(counts.get(str(row["id"]), 0))} products in this clone.

' f'' "Shop department
" for row in categories ) return ( breadcrumbs([("Home", "/"), ("Shop All", None)]) + '

Shop All Departments

' f'
{cards}
' ) def stores_page(chrome: Chrome, *, stores: Sequence[Mapping[str, Any]]) -> str: cards = "".join( '
' + icon("store", 24) + f'

{esc(row["name"])}

' f'

{esc(row["city"])}, {esc(row["state"])} {esc(row["zip"])}
' f'Closes at {esc(row["closes_at"])}

' '
' f'' f'' '' '' "
" for row in stores ) return ( breadcrumbs([("Home", "/"), ("Store Locator", None)]) + '

Store Locator

' '

Four synthetic stores back the pickup selector in this clone.

' f'
{cards}
' ) def info_page(chrome: Chrome, *, title: str, blocks: Sequence[str]) -> str: body = "".join(f"

{esc(block)}

" for block in blocks) return ( breadcrumbs([("Home", "/"), (title, None)]) + f'

{esc(title)}

' f"{body}
" ) def external_boundary(chrome: Chrome, *, slug: str) -> str: return ( breadcrumbs([("Home", "/"), ("External link", None)]) + '

External link boundary

' '

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.

" '

Return to the home page

' "
" ) def not_found(chrome: Chrome, *, path: str) -> str: return ( '

We can’t find that page

' f"

Nothing is served at {esc(path)} in this offline clone.

" '

Back to the home page ' 'Shop all departments

' "
" )