File size: 21,424 Bytes
489b6e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
"""Shared page chrome for the Lowe's offline clone.

The header, category nav, footer and account drawer are rebuilt from the two
sanitized desktop screenshots under ``source-current/``. Structure and copy that
were legible there are reproduced; anything below the observed fold, and every
step past the drawer's Continue button, is clone-authored and marked in
``scope/claims.jsonl``.

Rendering rules that the tests depend on:

* no inline ``<script>`` and no inline ``style`` attribute, so the app can ship
  a strict same-origin CSP without ``unsafe-inline``;
* every interactive control is a real link, form or submit button, so the page
  works with JavaScript disabled — there is no ``href="#"`` anywhere;
* off-site destinations point at the local ``/external/<slug>`` boundary page
  instead of a remote origin.
"""

from __future__ import annotations

import html
from dataclasses import dataclass, field
from typing import Any, Mapping, Sequence

from ui.icons import icon

SITE_LABEL = "Lowe's"
CLONE_LABEL = "WebsiteBench offline clone"


def esc(value: Any) -> str:
    return html.escape("" if value is None else str(value), quote=True)


def attr(value: Any) -> str:
    return html.escape("" if value is None else str(value), quote=True)


@dataclass
class Drawer:
    """State of the observed 'Sign In or Create Account' side panel."""

    open: bool = False
    step: str = "identify"
    identifier: str = ""
    identity_display: str = ""
    remember: bool = True
    errors: dict[str, str] = field(default_factory=dict)
    notice: str = ""
    sandbox_code: str | None = None
    next_path: str = "/"


@dataclass
class Chrome:
    """Everything the shared chrome needs for one response."""

    categories: Sequence[Mapping[str, Any]]
    stores: Sequence[Mapping[str, Any]]
    store: Mapping[str, Any] | None
    postal_code: str
    cart_units: int
    account: Mapping[str, Any] | None
    drawer: Drawer
    path: str = "/"
    query: str = ""


# ---------------------------------------------------------------------------
# top-level document
# ---------------------------------------------------------------------------


def document(
    *,
    title: str,
    chrome: Chrome,
    body: str,
    description: str = "",
    status_note: str = "",
) -> str:
    return (
        "<!doctype html>\n"
        '<html lang="en">\n'
        "<head>\n"
        '<meta charset="utf-8">\n'
        '<meta name="viewport" content="width=device-width, initial-scale=1">\n'
        f"<title>{esc(title)}</title>\n"
        f'<meta name="description" content="{attr(description)}">\n'
        '<meta name="robots" content="noindex, nofollow">\n'
        '<meta name="generator" content="WebsiteBench offline clone (lowes)">\n'
        '<link rel="icon" href="/static/site/img/lowes-logo.svg" type="image/svg+xml">\n'
        '<link rel="stylesheet" href="/static/site/lowes.css">\n'
        '<script src="/static/site/lowes.js" defer></script>\n'
        "</head>\n"
        '<body data-route="' + attr(chrome.path) + '">\n'
        '<a class="visually-hidden" href="#main">Skip to main content</a>\n'
        + promo_strip()
        + masthead(chrome)
        + catnav(chrome)
        + f'<main id="main">{body}</main>\n'
        + site_footer(status_note)
        + account_drawer(chrome)
        + "</body>\n</html>\n"
    )


# ---------------------------------------------------------------------------
# chrome pieces
# ---------------------------------------------------------------------------

PROMO_LINKS: tuple[tuple[str, str], ...] = (
    ("Lowe's Credit Center", "/external/lowes-credit-center"),
    ("Order Status", "/account/orders"),
    ("Weekly Ad", "/search?sort=savings"),
    ("Lowe's PRO", "/external/lowes-pro"),
)


def promo_strip() -> str:
    links = "".join(
        f'<li><a href="{attr(href)}">{esc(label)}</a></li>'
        for label, href in PROMO_LINKS
    )
    return (
        '<div class="promo-strip"><div class="shell">'
        '<a class="promo-strip__deal" href="/search?sort=savings">'
        "Shop this week's top deals now. &gt;</a>"
        f'<ul class="promo-strip__links">{links}</ul>'
        "</div></div>\n"
    )


def masthead(chrome: Chrome) -> str:
    store = chrome.store or {}
    store_name = store.get("name", "Select a store")
    closes_at = store.get("closes_at", "")
    account_label = "Sign In"
    account_href = "/signin"
    if chrome.account:
        first = str(chrome.account.get("display_name", "")).split(" ")[0] or "Account"
        account_label = first[:14]
        account_href = "/account"

    store_options = "".join(
        f'<option value="{attr(item["id"])}"'
        + (" selected" if store.get("id") == item["id"] else "")
        + f'>{esc(item["name"])} &middot; {esc(item["zip"])}</option>'
        for item in chrome.stores
    )

    return (
        '<header class="masthead"><div class="shell masthead__row">\n'
        '<a class="brand-logo" href="/" aria-label="Lowe\'s offline clone home">'
        '<img src="/static/site/img/lowes-logo.svg" width="82" height="38"'
        ' alt="Lowe\'s offline clone"></a>\n'
        '<form class="locator" method="post" action="/preferences">\n'
        f'<input type="hidden" name="next" value="{attr(chrome.path)}">\n'
        '<label class="visually-hidden" for="store-select">Selected store</label>\n'
        + icon("store", 18)
        + '<select class="locator__button" id="store-select" name="store_id"'
        ' data-autosubmit>'
        + store_options
        + "</select>\n"
        f'<span class="locator__button" aria-hidden="true"><strong>{esc(closes_at)}</strong></span>\n'
        '<span class="locator__divider"></span>\n'
        + icon("truck", 18)
        + '<label class="visually-hidden" for="zip-input">Delivery ZIP code</label>\n'
        '<input class="locator__button" id="zip-input" name="postal_code"'
        f' value="{attr(chrome.postal_code)}" size="6" inputmode="numeric"'
        ' pattern="[0-9]{5}" maxlength="5">\n'
        '<button class="visually-hidden" type="submit">Update store and ZIP</button>\n'
        "</form>\n"
        f'<span class="visually-hidden">Selected store: {esc(store_name)}</span>\n'
        + searchbar(chrome)
        + '<div class="masthead__utilities">\n'
        '<a class="utility" href="/assist">'
        + icon("sparkle", 22)
        + "<span>AI Assist</span></a>\n"
        f'<a class="utility" href="{attr(account_href)}" data-account-open>'
        + icon("account", 22)
        + f"<span>{esc(account_label)}</span></a>\n"
        '<a class="utility utility--cart" href="/cart">'
        + icon("cart", 22)
        + (
            f'<span class="utility__count">{esc(chrome.cart_units)}</span>'
            if chrome.cart_units
            else ""
        )
        + "<span>Cart</span></a>\n"
        "</div>\n"
        "</div></header>\n"
    )


def searchbar(chrome: Chrome) -> str:
    return (
        '<div class="searchbar">\n'
        '<form class="searchbar__form" method="get" action="/search" role="search"'
        ' data-suggest-form>\n'
        '<label class="visually-hidden" for="site-search">What can we help you find?</label>\n'
        '<input class="searchbar__input" id="site-search" type="search" name="q"'
        ' autocomplete="off" placeholder="What can we help you find?"'
        f' value="{attr(chrome.query)}" data-suggest-input role="combobox"'
        ' aria-expanded="false" aria-controls="search-suggestions"'
        ' aria-autocomplete="list">\n'
        '<button class="icon-button" type="submit" aria-label="Search">'
        + icon("search", 22)
        + "</button>\n"
        '<a class="icon-button" href="/visual-search" aria-label="Visual search">'
        + icon("camera", 22)
        + "</a>\n"
        "</form>\n"
        '<div class="suggestions" id="search-suggestions" role="listbox"'
        ' aria-label="Search suggestions" data-suggest-panel hidden></div>\n'
        "</div>\n"
    )


NAV_PRIMARY: tuple[tuple[str, str, str | None, bool], ...] = (
    ("Shop All", "/departments", "grid", True),
    ("Installations", "/services/installation", "tools", False),
    ("Deals", "/search?sort=savings", "tag", False),
    ("Design & Ideas", "/ideas", "bulb", False),
    ("$99 Maintenance", "/services/maintenance", None, False),
)


def catnav(chrome: Chrome) -> str:
    items: list[str] = []
    for label, href, glyph, strong in NAV_PRIMARY:
        badge = '<span class="badge-new">New</span>' if label.startswith("$99") else ""
        items.append(
            f'<li><a class="catnav__link{" catnav__link--strong" if strong else ""}"'
            f' href="{attr(href)}">'
            + (icon(glyph, 18) if glyph else "")
            + f"<span>{esc(label)}</span>{badge}</a></li>"
        )
    for category in chrome.categories[:8]:
        items.append(
            f'<li><a class="catnav__link" href="/search?category={attr(category["id"])}">'
            f'{esc(category["label"])}</a></li>'
        )
    return (
        '<nav class="catnav" aria-label="Departments"><div class="shell">'
        f'<ul class="catnav__list">{"".join(items)}</ul>'
        "</div></nav>\n"
    )


FOOTER_COLUMNS: tuple[tuple[str, tuple[tuple[str, str], ...]], ...] = (
    (
        "Customer Service",
        (
            ("Order Status", "/account/orders"),
            ("Returns", "/help/returns"),
            ("Shipping & Delivery", "/help/delivery"),
            ("Store Pickup", "/help/pickup"),
        ),
    ),
    (
        "Shop",
        (
            ("All Departments", "/departments"),
            ("Deals", "/search?sort=savings"),
            ("Top Sellers", "/search?sort=top-sellers"),
            ("Top Rated", "/search?sort=rating"),
        ),
    ),
    (
        "Services",
        (
            ("Installation Services", "/services/installation"),
            ("$99 Maintenance", "/services/maintenance"),
            ("Design & Ideas", "/ideas"),
            ("Store Locator", "/stores"),
        ),
    ),
    (
        "About this clone",
        (
            ("Clone scope and limits", "/about-this-clone"),
            ("Terms of Use", "/external/terms-of-use"),
            ("Privacy Statement", "/external/privacy-statement"),
            ("Lowe's PRO", "/external/lowes-pro"),
        ),
    ),
)


def site_footer(status_note: str = "") -> str:
    columns = "".join(
        f"<div><h3>{esc(title)}</h3><ul>"
        + "".join(
            f'<li><a href="{attr(href)}">{esc(label)}</a></li>' for label, href in links
        )
        + "</ul></div>"
        for title, links in FOOTER_COLUMNS
    )
    note = f"<p>{esc(status_note)}</p>" if status_note else ""
    return (
        '<footer class="site-footer"><div class="shell">'
        f'<div class="footer-grid">{columns}</div>'
        '<div class="footer-note">'
        "<p>This is a WebsiteBench offline clone of the Lowe's home page and "
        "account drawer. It is not Lowe's, it is not connected to Lowe's, and "
        "no request leaves this machine. Prices, products, ratings, reviews, "
        "stores, orders and payments are synthetic local fixtures.</p>"
        f"{note}"
        "</div>"
        "</div></footer>\n"
    )


# ---------------------------------------------------------------------------
# account drawer
# ---------------------------------------------------------------------------

DRAWER_BENEFITS: tuple[tuple[str, str], ...] = (
    ("package", "Order Status"),
    ("wrench", "Projects & Installations"),
    ("heart", "Lists"),
    ("medal", "Military Discount"),
    ("asterisk", "First Responder Benefits"),
)

DRAWER_LEGAL: tuple[tuple[str, str], ...] = (
    ("Terms of Use", "/external/terms-of-use"),
    ("Personal Account Terms", "/external/personal-account-terms"),
    ("Privacy Statement", "/external/privacy-statement"),
    (
        "Notice of Financial Incentive / Loyalty Programs",
        "/external/loyalty-programs",
    ),
)


def _field(
    *,
    name: str,
    label: str,
    kind: str = "text",
    value: str = "",
    error: str = "",
    autocomplete: str = "",
    placeholder: str = "",
    required: bool = True,
    extra: str = "",
) -> str:
    complete = f' autocomplete="{attr(autocomplete)}"' if autocomplete else ""
    place = f' placeholder="{attr(placeholder)}"' if placeholder else ""
    error_html = (
        f'<span class="field__error" id="{attr(name)}-error">{esc(error)}</span>'
        if error
        else ""
    )
    described = f' aria-describedby="{attr(name)}-error"' if error else ""
    return (
        f'<label class="field" for="field-{attr(name)}">'
        f'<span class="field__label">{esc(label)}</span>'
        f'<input class="field__control" id="field-{attr(name)}" type="{attr(kind)}"'
        f' name="{attr(name)}" value="{attr(value)}"'
        f'{" required" if required else ""}{complete}{place}{described}{extra}>'
        f"{error_html}</label>"
    )


def account_drawer(chrome: Chrome) -> str:
    drawer = chrome.drawer
    if chrome.account:
        inner = _drawer_signed_in(chrome)
    elif drawer.step == "sign-in":
        inner = _drawer_sign_in(drawer)
    elif drawer.step == "create":
        inner = _drawer_create(drawer)
    elif drawer.step == "verify":
        inner = _drawer_verify(drawer)
    else:
        inner = _drawer_identify(drawer)

    state = "open" if drawer.open else "closed"
    return (
        '<div class="drawer-overlay" data-account-overlay'
        + ("" if drawer.open else " hidden")
        + "></div>\n"
        f'<aside class="drawer" data-account-drawer="{attr(state)}" role="dialog"'
        ' aria-modal="true" aria-labelledby="drawer-title"'
        + ("" if drawer.open else " hidden")
        + ">\n"
        '<div class="drawer__head">'
        '<h2 class="drawer__title" id="drawer-title">'
        + ("Your Account" if chrome.account else "Sign In or Create Account")
        + "</h2>"
        '<a class="icon-button" href="' + attr(drawer.next_path) + '"'
        ' data-account-close aria-label="Close">' + icon("close", 22) + "</a>"
        "</div>\n"
        + inner
        + "</aside>\n"
    )


def _drawer_legal_block() -> str:
    links = ", ".join(
        f'<a href="{attr(href)}">{esc(label)}</a>' for label, href in DRAWER_LEGAL
    )
    return (
        '<p class="drawer__legal">By signing in to this offline clone, you are '
        "agreeing to the local stand-ins for " + links + ". These pages are not "
        "cloned; each link opens a same-origin boundary page.</p>"
    )


def _drawer_benefits_block() -> str:
    items = "".join(
        f"<li>{icon(glyph, 18)}<span>{esc(label)}</span></li>"
        for glyph, label in DRAWER_BENEFITS
    )
    return f'<ul class="drawer__benefits">{items}</ul>'


def _notice(drawer: Drawer) -> str:
    blocks = ""
    if drawer.notice:
        blocks += f'<p class="notice">{esc(drawer.notice)}</p>'
    if drawer.errors.get("form"):
        blocks += f'<p class="notice notice--error">{esc(drawer.errors["form"])}</p>'
    return blocks


def _drawer_identify(drawer: Drawer) -> str:
    return (
        '<form method="post" action="/account/identify">'
        f'<input type="hidden" name="next" value="{attr(drawer.next_path)}">'
        + _notice(drawer)
        + '<p class="drawer__intro">Enter your <strong>email or phone number</strong> '
        "to get started. We&#8217;ll check if you have an account.</p>"
        + _field(
            name="identifier",
            label="Email or Phone Number",
            value=drawer.identifier,
            error=drawer.errors.get("identifier", ""),
            autocomplete="username",
            placeholder="Email or Phone Number",
        )
        + '<label class="checkbox"><input type="checkbox" name="remember"'
        + (" checked" if drawer.remember else "")
        + ' value="1"><span>Remember me on this device</span>'
        + icon("info", 16)
        + "</label>"
        '<button class="button button--primary button--block" type="submit">'
        "Continue</button>"
        + _drawer_legal_block()
        + _drawer_benefits_block()
        + "</form>"
    )


def _drawer_sign_in(drawer: Drawer) -> str:
    return (
        '<form method="post" action="/account/sign-in">'
        f'<input type="hidden" name="next" value="{attr(drawer.next_path)}">'
        f'<input type="hidden" name="identifier" value="{attr(drawer.identifier)}">'
        f'<input type="hidden" name="remember" value="{"1" if drawer.remember else "0"}">'
        + _notice(drawer)
        + '<p class="drawer__intro">Welcome back. Enter the password for '
        f"<strong>{esc(drawer.identity_display or drawer.identifier)}</strong>.</p>"
        + _field(
            name="password",
            label="Password",
            kind="password",
            error=drawer.errors.get("password", ""),
            autocomplete="current-password",
        )
        + '<button class="button button--primary button--block" type="submit">'
        "Sign In</button>"
        '<p class="drawer__legal">Wrong address? '
        '<a href="/signin">Start over with a different email or phone number.</a></p>'
        + _drawer_benefits_block()
        + "</form>"
    )


def _drawer_create(drawer: Drawer) -> str:
    return (
        '<form method="post" action="/account/create">'
        f'<input type="hidden" name="next" value="{attr(drawer.next_path)}">'
        f'<input type="hidden" name="identifier" value="{attr(drawer.identifier)}">'
        f'<input type="hidden" name="remember" value="{"1" if drawer.remember else "0"}">'
        + _notice(drawer)
        + '<p class="drawer__intro">Create an account for '
        f"<strong>{esc(drawer.identity_display or drawer.identifier)}</strong>.</p>"
        + _field(
            name="first_name",
            label="First Name",
            value=drawer.errors.get("first_name_value", ""),
            error=drawer.errors.get("first_name", ""),
            autocomplete="given-name",
        )
        + _field(
            name="last_name",
            label="Last Name",
            value=drawer.errors.get("last_name_value", ""),
            error=drawer.errors.get("last_name", ""),
            autocomplete="family-name",
        )
        + _field(
            name="password",
            label="Password (8 characters or more)",
            kind="password",
            error=drawer.errors.get("password", ""),
            autocomplete="new-password",
        )
        + '<button class="button button--primary button--block" type="submit">'
        "Create Account</button>"
        '<p class="drawer__legal">Already have an account? '
        '<a href="/signin">Start over.</a></p>'
        + _drawer_legal_block()
        + "</form>"
    )


def _drawer_verify(drawer: Drawer) -> str:
    sandbox = ""
    if drawer.sandbox_code:
        sandbox = (
            '<p class="notice notice--sandbox"><strong>Local sandbox helper.</strong> '
            "This offline clone cannot send mail, so the code issued for this "
            "browser session is shown here: "
            f"<code>{esc(drawer.sandbox_code)}</code>. The code lives only in this "
            "process&#8217;s memory, is never written to the database or a log, "
            "and disappears on restart. Lowe&#8217;s does not do this; set "
            "<code>LOWES_LOCAL_SANDBOX_HELP=0</code> to hide it.</p>"
        )
    return (
        '<form method="post" action="/account/verify">'
        f'<input type="hidden" name="next" value="{attr(drawer.next_path)}">'
        f'<input type="hidden" name="identifier" value="{attr(drawer.identifier)}">'
        f'<input type="hidden" name="remember" value="{"1" if drawer.remember else "0"}">'
        + _notice(drawer)
        + '<p class="drawer__intro">Enter the 6-digit verification code issued for '
        f"<strong>{esc(drawer.identity_display or drawer.identifier)}</strong>.</p>"
        + sandbox
        + _field(
            name="code",
            label="Verification Code",
            value="",
            error=drawer.errors.get("code", ""),
            autocomplete="one-time-code",
            placeholder="000000",
            extra=' inputmode="numeric" pattern="[0-9]{6}" maxlength="6"',
        )
        + '<button class="button button--primary button--block" type="submit">'
        "Verify and Create Account</button>"
        "</form>"
        '<form method="post" action="/account/resend">'
        f'<input type="hidden" name="next" value="{attr(drawer.next_path)}">'
        f'<input type="hidden" name="identifier" value="{attr(drawer.identifier)}">'
        '<button class="link-button" type="submit">Send a new code</button>'
        "</form>"
    )


def _drawer_signed_in(chrome: Chrome) -> str:
    account = chrome.account or {}
    return (
        '<p class="drawer__intro">Signed in as '
        f"<strong>{esc(account.get('display_name', ''))}</strong><br>"
        f"{esc(account.get('contact_display', ''))}</p>"
        '<p><a class="button button--primary button--block" href="/account">'
        "Go to your account</a></p>"
        '<form method="post" action="/account/sign-out">'
        f'<input type="hidden" name="next" value="{attr(chrome.drawer.next_path)}">'
        '<button class="button button--outline button--block" type="submit">'
        "Sign Out</button>"
        "</form>" + _drawer_benefits_block()
    )