{
  "$schema": "./.schemas/page.schema.json",
  "cards": [
    {
      "id": "todos",
      "itemAction": {
        "icon": "checkmark",
        "label": "Complete",
        "method": "POST",
        "path": "/api/v1/tasks/{id}/close"
      },
      "items": [],
      "label": "Project",
      "max_items": 15,
      "source": {
        "empty": {
          "text": "No open tasks.",
          "when": {
            "equals": 0,
            "value": {
              "count": "tasks.results"
            }
          }
        },
        "map": {
          "items": {
            "each": "task_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": ""
                  },
                  "if": {
                    "not": "",
                    "path": "parent_name"
                  },
                  "then": {
                    "template": "↳ {parent_name}"
                  }
                },
                "if": {
                  "equals": true,
                  "path": "has_due"
                },
                "then": {
                  "else": {
                    "else": {
                      "template": "{due.date|day}"
                    },
                    "if": {
                      "contains": "T",
                      "path": "due.date"
                    },
                    "then": {
                      "template": "{due.date|day} · {due.date|clock}"
                    }
                  },
                  "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": "section.name",
              "text": "content"
            },
            "limit": 60,
            "lookup": {
              "as": "section",
              "by": "id",
              "from": "sections.results",
              "on": "section_id"
            },
            "sort": [
              "section.order_key",
              "order_key"
            ]
          },
          "label": "project.name"
        },
        "ref": "todoist"
      },
      "type": "checklist"
    },
    {
      "body": "This project is shortened here. Open [Todoist](https://app.todoist.com) for the full list.",
      "id": "more-tasks",
      "source": {
        "ref": "todoist",
        "when": {
          "any": [
            {
              "not": "",
              "path": "tasks_cursor"
            },
            {
              "not": "",
              "path": "sections_cursor"
            },
            {
              "gt": 60,
              "value": {
                "count": "tasks.results"
              }
            }
          ]
        }
      },
      "tone": "info",
      "type": "text"
    }
  ],
  "icon": "folder",
  "params": {
    "project": {
      "example": "ExampleProject0001",
      "pattern": "[A-Za-z0-9]{1,40}"
    }
  },
  "sidebar": false,
  "sources": {
    "todoist": {
      "derive": [
        {
          "name": "task_rows",
          "value": {
            "each": "tasks.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": "tasks.results",
              "on": "parent_id"
            },
            "sort": [
              "due.date",
              "order_key"
            ]
          }
        },
        {
          "name": "tasks_cursor",
          "value": {
            "default": "",
            "path": "tasks.next_cursor"
          }
        },
        {
          "name": "sections_cursor",
          "value": {
            "default": "",
            "path": "sections.next_cursor"
          }
        }
      ],
      "every": "5m",
      "requests": {
        "project": "/api/v1/projects/{param.project}",
        "sections": "/api/v1/sections?project_id={param.project}&limit=200",
        "tasks": "/api/v1/tasks?project_id={param.project}&limit=200"
      },
      "secret": "todoist",
      "url": "https://api.todoist.com"
    }
  },
  "title": "Project"
}
