# Leave by

*Your next place, when to leave, and a ride one tap away.*

**Type: [Place](types/place.md).** Where to be, on a real map, with how and when to get there. This is one good use of it; the same widget serves next appointment, dinner reservation, pickup point, hotel tonight and more. Switch the subject when something else matters more.

Template id `leave-by` · Right now · uses Calendar, Location · for: Any agent; booking needs one with a ride app or browser.

## Goal

The user never has to work out when to leave or how to get there.

## When to offer it

The user has places to be: appointments, school runs, meetings across town. Offer it when the calendar has events with locations.

## What the user gets

- Shows your next event with a place, on a map, and when to leave
- Books the ride or tells people you're late when you tap
- Changes on its own as the day goes on

## What each size shows

- **Small**: countdown (relative): Leave in.
- **Medium**: metric: Dr. Lee = 3:00; countdown (relative): Leave in; buttons: Book a ride (`ride`), Running late (`late`).
- **Large**: countdown (relative): Leave in; map: 210 Court St; buttons: Book a ride (`ride`), Running late (`late`).
- **Lock Screen**: inline "Leave 2:35 for Dr. Lee".

## Make it theirs

**Look.** Send `look` instead of `theme` and `accent`; every combination is designed to read well:

- `style`: `glass` (default: see-through, adapts to dark mode), `soft` (a calm pale tint) or `bold` (a vivid gradient with dark buttons).
- `accent`: blue, indigo, purple, pink, red, orange, green, teal, graphite, or a hex.
- `font`: default, rounded, serif or mono.

This template's own accent is **orange**. To restyle a widget you already saved, send only the look:

```json
{"slug": "leave-by", "look": {"style": "bold", "accent": "orange", "font": "rounded"}}
```

Preview a look without saving: `droplet_preview_widget` with the slug and `look`. When the user says "make it greener", "calmer" or "bolder", change the look; keep the content.

**Their choices.** Ask once (droplet_ask) or use what you know:

- Buffer before leaving (default 5 min)
- How they get there: ride, subway, walk, drive

**Search words:** commute, leave, late, miss, missing, on time, train, bus, subway, uber, ride, appointment, traffic, directions, travel time, map.


## Before you build

- Check `droplet_get_phone_context`: the phone must share calendar, location. If something is off, ask the user to turn it on in Droplet.ai, Settings, Phone access.
- You need: Any agent; booking needs one with a ride app or browser.
- Ask once: Every booking and every message: approval first, naming the price or the recipient.

## Fill it with real data

Start from the template (`droplet_library` with `id: "leave-by"`), keep the design, and replace each sample value:

| Block | Real value |
|---|---|
| 0 · metric | The next event's title and start time (calendar); also put "Name · 3:00" in the widget subtitle, which large shows instead. |
| 1 · countdown | `to` = leave-by time: start minus travel time minus 5 min, with the phone's UTC offset. |
| 2 · map | The event's address, geocoded (lat, lon); label = street address. Never coordinates as text. |
| 3 · buttons | Keep the ids `ride` and `late`. |

Sources:
- Next calendar event that has a location (droplet_get_phone_context: calendar).
- Travel time from the phone's place/city to that address (your maps tool, or 20 min in a city as a fallback). Leave-by = start minus travel minus 5 min.
- map block: geocode the address; never show raw coordinates.

## The widget

Sample values; send it with `droplet_set_widget` on your widget's slug (or a new slug with `new_widget: true` if the user asked for a separate widget). Preview it and fix every warning first.

```json
{
  "slug": "leave-by",
  "title": "Next",
  "subtitle": "Dr. Lee · 3:00",
  "symbol": "car.fill",
  "accent": "#FF9F0A",
  "blocks": [
    {"type": "metric", "label": "Dr. Lee", "value": "3:00"},
    {"type": "countdown", "label": "Leave in", "to": "2030-01-01T08:40:00+00:00", "style": "relative"},
    {"type": "map", "lat": 40.6865, "lon": -73.9937, "label": "210 Court St", "span": 900},
    {"type": "buttons", "items": [{"id": "ride", "label": "Book a ride", "symbol": "car.fill"}, {"id": "late", "label": "Running late", "symbol": "clock.badge.exclamationmark"}]}
  ],
  "sizes": {"small": [1], "medium": [0, 1, 3], "large": [1, 2, 3]},
  "lock": {"inline": "Leave 2:35 for Dr. Lee"}
}
```

## Keep it fresh

When the next event changes, after it starts, and every 30 min on travel days (droplet_schedule or your own loop). The countdown ticks on the phone by itself.

## Handle the taps

Each tap reaches you once on `droplet_get_events` (keep a waker running, SKILL.md Process C). Answer within seconds by updating the widget.

**Book a ride** (`ride`)

```json
{"widget": "leave-by", "kind": "button", "target": "ride", "value": {"label": "Book a ride"}}
```

Get a price and ETA from the user's ride app or browser, then droplet_ask 'Book an Uber XL, $24, pickup 2:32?' (decision). Only book on yes. Put the driver and ETA on the widget.

**Running late** (`late`)

```json
{"widget": "leave-by", "kind": "button", "target": "late", "value": {"label": "Running late"}}
```

Draft 'Running 10 min late' to the event's organiser, droplet_ask to send it (decision, name the recipient). Send only on yes, then show 'Told Dr. Lee's office' on the widget.

## Ask first

Every booking and every message: approval first, naming the price or the recipient.

For example:

```json
{"question": "Book an Uber to Dr. Lee, $24, pickup 2:32?", "kind": "decision", "options": ["Book it", "Not now"], "risk": "medium"}
```

## Phone actions

None needed. Optional: a 'Leave now' notification only if the user asked for one.

## Edge cases

- No upcoming event has a location: show the next one without the map and with only `late`, or say 'Nothing to leave for today' with a calendar link.
- The event is in under 10 minutes: change the countdown label to 'Leave now'.
- The user is already there (place matches): switch to the following event.

## Never

Never book or message without the user's yes. Never show an event without a location here.

## Done when

- [ ] Every sample value is replaced with real data (no "Dr. Lee" on a real widget).
- [ ] `droplet_preview_widget` shows no warnings at the sizes the user placed (`placed` in `droplet_whoami`).
- [ ] Every button has a handler and a waker is running.
- [ ] Refresh is set up as above.
- [ ] You told the user in one line what it does on its own and what it asks first.
