# =track <number>: which carrier does this tracking number look like? Lists every
# plausible carrier (UPS, FedEx, USPS, DHL) with its tracking page, says why each one
# matches, and runs the UPS 1Z check digit (mod 10) where the carrier defines one.
# Pure and on-device: nothing is sent anywhere until you open a row.
#
#   =track 1Z999AA10123456784   -> UPS, check digit valid
#   =track 123456789012         -> FedEx (12 digits); no public check digit used here
#
# The number is normalized first (spaces and dashes removed, upper case, letters and
# digits only) and only then placed into a link. Input that is not 8 to 40 letters or
# digits after that gets one honest row and no links.
#
# Bolt already opens a carrier page for a bare UPS, FedEx or USPS number out of the box.
# This App adds the part Bolt does not show: every plausible carrier side by side, the
# reason for each, and the UPS check-digit result. Several 10, 12 and 15 digit numbers
# are not parcels at all (a 10 digit number may be a timestamp), so a match is a hint.
schema_version: 1
runtime: bridge
id: track
chip: track
title: Carrier picker
icon: package
description: "Which carrier is this tracking number? Lists each plausible carrier with its tracking page, why it matches, and the UPS check digit (on-device)"
placeholder_examples: ["1Z999AA10123456784", "123456789012"]
emits: Document

dispatch:
  confirm_label: 'Identify carrier: {{query}}'
  confirm_hint: "Press Enter to list plausible carriers · nothing leaves your machine until you open one"

bridge:
  command:
    macos: "python3 {{scripts_dir}}/bolt-track.py {{query}}"
    linux: "python3 {{scripts_dir}}/bolt-track.py {{query}}"
    windows: "python {{scripts_dir}}/bolt-track.py {{query}}"
  parse: json
  timeout_seconds: 8

presentation:
  widget: list
  title_field: title
  subtitle_field: subtitle
  searchable: true
  right_widget:
    kind: entity_preview
    mode: selected_row
    bind:
      title: "{{row.title}}"
      subtitle: "{{row.subtitle}}"
      fields:
        - { label: Carrier, value: "{{row.carrier}}", kind: badge }
        - { label: Check digit, value: "{{row.check}}" }
        - { label: Number, value: "{{row.number}}" }
        - { label: URL, value: "{{row.url}}" }
      body: "{{row.body}}"
      actions: [open, copy-number, copy-url]

actions:
  - { id: open, kind: url, target: row, label: Open page, url_template: "{{row.url}}", primary: true }
  - { id: copy-number, kind: composer, target: row, label: Copy number, insert: "{{row.number}}" }
  - { id: copy-url, kind: composer, target: row, label: Copy URL, insert: "{{row.url}}" }
