{
  "$schema": "./.schemas/page.schema.json",
  "cards": [
    {
      "id": "lists",
      "tabs": [
        {
          "cards": [
            {
              "id": "today",
              "itemAction": {
                "icon": "checkmark",
                "label": "Complete",
                "method": "POST",
                "path": "/api/v1/tasks/{id}/close"
              },
              "items": [],
              "max_items": 7,
              "source": {
                "empty": {
                  "text": "Nothing due or overdue.",
                  "when": {
                    "equals": 0,
                    "value": {
                      "add": [
                        {
                          "count": "today.results"
                        },
                        {
                          "count": "overdue.results"
                        }
                      ]
                    }
                  }
                },
                "map": {
                  "items": {
                    "each": [
                      "today_rows",
                      "overdue_rows"
                    ],
                    "fields": {
                      "badge": {
                        "else": {
                          "template": ""
                        },
                        "if": {
                          "equals": true,
                          "path": "due.is_recurring"
                        },
                        "then": {
                          "template": "arrow.clockwise"
                        }
                      },
                      "badge_at": {
                        "template": "end"
                      },
                      "badge_label": {
                        "template": "Repeating"
                      },
                      "detail": {
                        "else": {
                          "else": {
                            "template": "{project.name}"
                          },
                          "if": {
                            "not": "",
                            "path": "parent_name"
                          },
                          "then": {
                            "template": "↳ {parent_name}"
                          }
                        },
                        "if": {
                          "equals": true,
                          "path": "has_due"
                        },
                        "then": {
                          "else": {
                            "else": {
                              "template": "{due.date|day} · {project.name}"
                            },
                            "if": {
                              "contains": "T",
                              "path": "due.date"
                            },
                            "then": {
                              "template": "{due.date|day} · {due.date|clock} · {project.name}"
                            }
                          },
                          "if": {
                            "not": "",
                            "path": "parent_name"
                          },
                          "then": {
                            "else": {
                              "template": "{due.date|day} · ↳ {parent_name}"
                            },
                            "if": {
                              "contains": "T",
                              "path": "due.date"
                            },
                            "then": {
                              "template": "{due.date|day} · {due.date|clock} · ↳ {parent_name}"
                            }
                          }
                        }
                      },
                      "done": "checked",
                      "section": "group_label",
                      "text": "content"
                    },
                    "limit": 60,
                    "lookup": {
                      "as": "project",
                      "by": "id",
                      "from": "projects.results",
                      "on": "project_id"
                    }
                  }
                },
                "ref": "todoist"
              },
              "type": "checklist"
            }
          ],
          "label": "Due"
        },
        {
          "cards": [
            {
              "id": "upcoming",
              "itemAction": {
                "icon": "checkmark",
                "label": "Complete",
                "method": "POST",
                "path": "/api/v1/tasks/{id}/close"
              },
              "items": [],
              "max_items": 7,
              "source": {
                "empty": {
                  "text": "Nothing else scheduled in the next 7 days.",
                  "when": {
                    "equals": 0,
                    "value": {
                      "count": "upcoming.results"
                    }
                  }
                },
                "map": {
                  "items": {
                    "each": "upcoming_rows",
                    "fields": {
                      "badge": {
                        "else": {
                          "template": ""
                        },
                        "if": {
                          "equals": true,
                          "path": "due.is_recurring"
                        },
                        "then": {
                          "template": "arrow.clockwise"
                        }
                      },
                      "badge_at": {
                        "template": "end"
                      },
                      "badge_label": {
                        "template": "Repeating"
                      },
                      "detail": {
                        "else": {
                          "else": {
                            "template": "{project.name}"
                          },
                          "if": {
                            "not": "",
                            "path": "parent_name"
                          },
                          "then": {
                            "template": "↳ {parent_name}"
                          }
                        },
                        "if": {
                          "equals": true,
                          "path": "has_due"
                        },
                        "then": {
                          "else": {
                            "else": {
                              "template": "{due.date|day} · {project.name}"
                            },
                            "if": {
                              "contains": "T",
                              "path": "due.date"
                            },
                            "then": {
                              "template": "{due.date|day} · {due.date|clock} · {project.name}"
                            }
                          },
                          "if": {
                            "not": "",
                            "path": "parent_name"
                          },
                          "then": {
                            "else": {
                              "template": "{due.date|day} · ↳ {parent_name}"
                            },
                            "if": {
                              "contains": "T",
                              "path": "due.date"
                            },
                            "then": {
                              "template": "{due.date|day} · {due.date|clock} · ↳ {parent_name}"
                            }
                          }
                        }
                      },
                      "done": "checked",
                      "section": {
                        "template": "{due.date|day}"
                      },
                      "text": "content"
                    },
                    "limit": 60,
                    "lookup": {
                      "as": "project",
                      "by": "id",
                      "from": "projects.results",
                      "on": "project_id"
                    },
                    "sort": [
                      "due.date",
                      "order_key"
                    ]
                  }
                },
                "ref": "todoist"
              },
              "type": "checklist"
            }
          ],
          "label": "Upcoming"
        },
        {
          "cards": [
            {
              "id": "inbox",
              "itemAction": {
                "icon": "checkmark",
                "label": "Complete",
                "method": "POST",
                "path": "/api/v1/tasks/{id}/close"
              },
              "items": [],
              "max_items": 7,
              "source": {
                "empty": {
                  "text": "Inbox is empty.",
                  "when": {
                    "equals": 0,
                    "value": {
                      "count": "inbox.results"
                    }
                  }
                },
                "map": {
                  "items": {
                    "each": "inbox_rows",
                    "fields": {
                      "badge": {
                        "else": {
                          "template": ""
                        },
                        "if": {
                          "equals": true,
                          "path": "due.is_recurring"
                        },
                        "then": {
                          "template": "arrow.clockwise"
                        }
                      },
                      "badge_at": {
                        "template": "end"
                      },
                      "badge_label": {
                        "template": "Repeating"
                      },
                      "detail": {
                        "else": {
                          "else": {
                            "template": "{project.name}"
                          },
                          "if": {
                            "not": "",
                            "path": "parent_name"
                          },
                          "then": {
                            "template": "↳ {parent_name}"
                          }
                        },
                        "if": {
                          "equals": true,
                          "path": "has_due"
                        },
                        "then": {
                          "else": {
                            "else": {
                              "template": "{due.date|day} · {project.name}"
                            },
                            "if": {
                              "contains": "T",
                              "path": "due.date"
                            },
                            "then": {
                              "template": "{due.date|day} · {due.date|clock} · {project.name}"
                            }
                          },
                          "if": {
                            "not": "",
                            "path": "parent_name"
                          },
                          "then": {
                            "else": {
                              "template": "{due.date|day} · ↳ {parent_name}"
                            },
                            "if": {
                              "contains": "T",
                              "path": "due.date"
                            },
                            "then": {
                              "template": "{due.date|day} · {due.date|clock} · ↳ {parent_name}"
                            }
                          }
                        }
                      },
                      "done": "checked",
                      "text": "content"
                    },
                    "limit": 60,
                    "lookup": {
                      "as": "project",
                      "by": "id",
                      "from": "projects.results",
                      "on": "project_id"
                    },
                    "sort": "child_order"
                  }
                },
                "ref": "todoist"
              },
              "type": "checklist"
            }
          ],
          "label": "Inbox"
        }
      ],
      "type": "tabs",
      "same_height": true
    },
    {
      "body": "Some lists are shortened here. Open [Todoist](https://app.todoist.com) for the full lists. Project counts may be partial.",
      "id": "more-tasks",
      "source": {
        "ref": "todoist",
        "when": {
          "any": [
            {
              "equals": "yes",
              "path": "limited"
            },
            {
              "gt": 60,
              "value": {
                "add": [
                  {
                    "count": "today.results"
                  },
                  {
                    "count": "overdue.results"
                  }
                ]
              }
            },
            {
              "gt": 60,
              "value": {
                "count": "inbox.results"
              }
            },
            {
              "gt": 60,
              "value": {
                "count": "upcoming.results"
              }
            },
            {
              "gt": 15,
              "value": {
                "count": "projects.results"
              }
            }
          ]
        }
      },
      "tone": "info",
      "type": "text"
    },
    {
      "id": "projects",
      "items": [],
      "label": "Projects",
      "max_items": 4,
      "source": {
        "map": {
          "items": {
            "else": {
              "path": "project_rows"
            },
            "if": {
              "not": "",
              "path": "all_cursor"
            },
            "then": {
              "each": "project_rows",
              "fields": {
                "detail": {
                  "template": "At least {detail}"
                },
                "text": "text",
                "url": "url"
              }
            }
          }
        },
        "ref": "todoist"
      },
      "type": "list"
    },
    {
      "cards": [
        "done-days",
        "recent"
      ],
      "collapsed": true,
      "id": "completed",
      "source": {
        "map": {
          "detail": {
            "template": "{done_today} today · {done_week} in 7 days"
          }
        },
        "ref": "todoist"
      },
      "text": "Completed",
      "type": "heading"
    },
    {
      "id": "done-days",
      "items": [],
      "label": "Done each day",
      "series": [
        "Done"
      ],
      "source": {
        "map": {
          "items": {
            "each": "stats.days_items",
            "fields": {
              "label": {
                "template": "{date|weekday}"
              },
              "values[0]": "total_completed"
            },
            "sort": "date"
          }
        },
        "ref": "todoist"
      },
      "type": "columns"
    },
    {
      "id": "recent",
      "items": [
        "—"
      ],
      "label": "Recently completed",
      "max_items": 4,
      "source": {
        "empty": {
          "text": "Nothing completed lately.",
          "when": {
            "equals": 0,
            "value": {
              "count": "done.results"
            }
          }
        },
        "map": {
          "items": {
            "each": "done.results",
            "fields": {
              "detail": {
                "template": "{event_date|ago}"
              },
              "text": "extra_data.content"
            },
            "limit": 20
          }
        },
        "ref": "todoist"
      },
      "type": "list"
    }
  ],
  "icon": "checklist",
  "sources": {
    "todoist": {
      "derive": [
        {
          "name": "today_rows",
          "value": {
            "each": "today.results",
            "fields": {
              "added_at": "added_at",
              "checked": "checked",
              "child_order": "child_order",
              "content": "content",
              "due": "due",
              "group_label": {
                "template": "Today"
              },
              "has_due": {
                "default": false,
                "path": "due.is_recurring",
                "values": {
                  "false": true,
                  "true": true
                }
              },
              "id": "id",
              "order_key": "order_key",
              "parent_name": {
                "default": "",
                "path": "parent.content"
              },
              "project_id": "project_id",
              "section_id": "section_id"
            },
            "lookup": {
              "as": "parent",
              "by": "id",
              "from": "all.results",
              "on": "parent_id"
            },
            "sort": [
              "due.date",
              "order_key"
            ]
          }
        },
        {
          "name": "overdue_rows",
          "value": {
            "each": "overdue.results",
            "fields": {
              "added_at": "added_at",
              "checked": "checked",
              "child_order": "child_order",
              "content": "content",
              "due": "due",
              "group_label": {
                "template": "Overdue"
              },
              "has_due": {
                "default": false,
                "path": "due.is_recurring",
                "values": {
                  "false": true,
                  "true": true
                }
              },
              "id": "id",
              "order_key": "order_key",
              "parent_name": {
                "default": "",
                "path": "parent.content"
              },
              "project_id": "project_id",
              "section_id": "section_id"
            },
            "lookup": {
              "as": "parent",
              "by": "id",
              "from": "all.results",
              "on": "parent_id"
            },
            "sort": [
              "due.date",
              "order_key"
            ]
          }
        },
        {
          "name": "upcoming_rows",
          "value": {
            "each": "upcoming.results",
            "fields": {
              "added_at": "added_at",
              "checked": "checked",
              "child_order": "child_order",
              "content": "content",
              "due": "due",
              "has_due": {
                "default": false,
                "path": "due.is_recurring",
                "values": {
                  "false": true,
                  "true": true
                }
              },
              "id": "id",
              "order_key": "order_key",
              "parent_name": {
                "default": "",
                "path": "parent.content"
              },
              "project_id": "project_id",
              "section_id": "section_id"
            },
            "lookup": {
              "as": "parent",
              "by": "id",
              "from": "all.results",
              "on": "parent_id"
            },
            "sort": [
              "due.date",
              "order_key"
            ]
          }
        },
        {
          "name": "inbox_rows",
          "value": {
            "each": "inbox.results",
            "fields": {
              "added_at": "added_at",
              "checked": "checked",
              "child_order": "child_order",
              "content": "content",
              "due": "due",
              "has_due": {
                "default": false,
                "path": "due.is_recurring",
                "values": {
                  "false": true,
                  "true": true
                }
              },
              "id": "id",
              "order_key": "order_key",
              "parent_name": {
                "default": "",
                "path": "parent.content"
              },
              "project_id": "project_id",
              "section_id": "section_id"
            },
            "lookup": {
              "as": "parent",
              "by": "id",
              "from": "all.results",
              "on": "parent_id"
            },
            "sort": [
              "due.date",
              "order_key"
            ]
          }
        },
        {
          "name": "done_today",
          "value": {
            "default": 0,
            "first": "total_completed",
            "of": "stats.days_items",
            "where": {
              "equals": "Today",
              "value": {
                "template": "{date|day}"
              }
            }
          }
        },
        {
          "name": "done_week",
          "value": {
            "limit": 7,
            "of": "stats.days_items",
            "sort": {
              "by": "date",
              "order": "desc"
            },
            "sum": "total_completed"
          }
        },
        {
          "name": "all_cursor",
          "value": {
            "default": "",
            "path": "all.next_cursor"
          }
        },
        {
          "name": "today_cursor",
          "value": {
            "default": "",
            "path": "today.next_cursor"
          }
        },
        {
          "name": "overdue_cursor",
          "value": {
            "default": "",
            "path": "overdue.next_cursor"
          }
        },
        {
          "name": "upcoming_cursor",
          "value": {
            "default": "",
            "path": "upcoming.next_cursor"
          }
        },
        {
          "name": "inbox_cursor",
          "value": {
            "default": "",
            "path": "inbox.next_cursor"
          }
        },
        {
          "name": "projects_cursor",
          "value": {
            "default": "",
            "path": "projects.next_cursor"
          }
        },
        {
          "name": "limited",
          "value": {
            "else": {
              "template": "no"
            },
            "if": {
              "any": [
                {
                  "not": "",
                  "path": "all_cursor"
                },
                {
                  "not": "",
                  "path": "today_cursor"
                },
                {
                  "not": "",
                  "path": "overdue_cursor"
                },
                {
                  "not": "",
                  "path": "upcoming_cursor"
                },
                {
                  "not": "",
                  "path": "inbox_cursor"
                },
                {
                  "not": "",
                  "path": "projects_cursor"
                }
              ]
            },
            "then": {
              "template": "yes"
            }
          }
        },
        {
          "name": "project_rows",
          "value": {
            "each": "all.results",
            "fields": {
              "detail": {
                "else": {
                  "template": "{count} open"
                },
                "if": {
                  "equals": 1,
                  "path": "count"
                },
                "then": {
                  "template": "1 open"
                }
              },
              "text": {
                "first": "project.name",
                "of": "rows"
              },
              "url": {
                "template": "legato://page/todoist-project?project={key}"
              }
            },
            "group": "project_id",
            "limit": 15,
            "lookup": {
              "as": "project",
              "by": "id",
              "from": "projects.results",
              "on": "project_id"
            },
            "sort": {
              "by": "count",
              "order": "desc"
            },
            "where": {
              "not": true,
              "path": "project.inbox_project"
            }
          }
        }
      ],
      "every": "5m",
      "requests": {
        "all": "/api/v1/tasks?limit=200",
        "done": "/api/v1/activities?object_type=item&event_type=completed&limit=20",
        "inbox": "/api/v1/tasks/filter?limit=200&query=%23Inbox",
        "overdue": "/api/v1/tasks/filter?limit=200&query=overdue",
        "projects": "/api/v1/projects?limit=200",
        "stats": "/api/v1/tasks/completed/stats",
        "today": "/api/v1/tasks/filter?limit=200&query=today",
        "upcoming": "/api/v1/tasks/filter?limit=200&query=7%20days%20%26%20!today%20%26%20!overdue"
      },
      "secret": "todoist",
      "url": "https://api.todoist.com"
    }
  },
  "title": "Todoist"
}
