# -*- coding: utf-8 -*-
"""Wires click-through prototype flows into the PayGo file."""
import json

M0, M1, M2, M3A, M3B, M4, M5, M6 = 409, 436, 508, 559, 595, 625, 701, 752
C1, C2, C3, C4 = 784, 830, 876, 905

SMART = dict(transition={"type": "smartAnimate"}, durationMs=300, easing="easeOut")
PUSH_L = dict(transition={"type": "push", "direction": "left"}, durationMs=280,
              easing="easeOut")
PUSH_R = dict(transition={"type": "push", "direction": "right"}, durationMs=280,
              easing="easeOut")
DISSOLVE = dict(transition={"type": "dissolve"}, durationMs=220, easing="easeOut")

LINKS = [
    # merchant
    (M0, M1, DISSOLVE),            # tap the standby screen to wake
    (480, M3A, DISSOLVE),          # M-1 Tap & Pay    -> success
    (484, M2, PUSH_L),             # M-1 Generate QR  -> QR screen
    (488, M2, PUSH_L),             # M-1 Send link    -> QR screen (share sheet)
    (516, M1, PUSH_R),             # M-2 back         -> home
    (547, M3A, DISSOLVE),          # M-2 share link   -> success
    (551, M1, PUSH_R),             # M-2 cancel       -> home
    (585, M4, PUSH_L),             # M-3a receipt     -> history
    (589, M1, DISSOLVE),           # M-3a home
    (617, M1, DISSOLVE),           # M-3b try again   -> home
    (619, M1, DISSOLVE),           # M-3b home
    (733, M6, PUSH_L),             # M-5 pair key     -> provisioning
    (760, M5, PUSH_R),             # M-6 back         -> settings
    (777, M5, PUSH_R),             # M-6 bind         -> settings
    # customer
    (824, C2, PUSH_L),             # C-1 register     -> checkout
    (870, C3, DISSOLVE),           # C-2 authorize    -> receipt
    (899, C4, PUSH_L),             # C-3 save receipt -> log
    (954, C3, PUSH_R),             # C-4 view receipt -> receipt
]

# bottom-nav tabs, set on the three main components so every instance inherits
NAV_LINKS = [(362, M1), (366, M4), (370, M5),
             (377, M1), (381, M4), (385, M5),
             (392, M1), (396, M4), (400, M5)]

cmds = []
for src, dest, opts in LINKS:
    cmds.append({"command": "proto.interaction.add",
                 "params": dict(id=src, trigger={"type": "onClick"},
                                action={"type": "navigate", "dest": dest},
                                **opts)})
for src, dest in NAV_LINKS:
    cmds.append({"command": "proto.interaction.add",
                 "params": dict(id=src, trigger={"type": "onClick"},
                                action={"type": "navigate", "dest": dest},
                                **DISSOLVE)})

# flow starting points, so the shared prototype opens on the right screen
cmds += [
    {"command": "proto.flow.add", "params": {"start": M0,
                                            "name": "Merchant — full flow"}},
    {"command": "proto.flow.add", "params": {"start": C1,
                                            "name": "Customer — full flow"}},
    {"command": "proto.settings", "params": {"device": "None",
                                             "background": "#0F1115",
                                             "width": 390, "height": 844}},
]

json.dump(cmds, open("proto.json", "w"))
print(len(cmds), "commands")
