{
  "$schema": "./.schemas/page.schema.json",
  "title": "Reminders",
  "icon": "checklist",
  "sources": {
    "reminders": {
      "kind": "reminders",
      "show": "dashboard"
    }
  },
  "cards": [
    {
      "id": "tasks",
      "type": "tabs",
      "same_height": true,
      "tabs": [
        {
          "label": "Due",
          "cards": [
            {
              "id": "due",
              "type": "checklist",
              "mark": "fill",
              "max_items": 7,
              "items": [],
              "source": {
                "ref": "reminders",
                "map": {
                  "items": {
                    "each": "due",
                    "limit": 100,
                    "fields": {
                      "text": {
                        "if": {
                          "path": "priority_mark",
                          "not": ""
                        },
                        "then": {
                          "template": "{priority_mark} {title}"
                        },
                        "else": {
                          "template": "{title}"
                        }
                      },
                      "detail": {
                        "template": "{info}"
                      },
                      "done": "done",
                      "badge": {
                        "if": {
                          "path": "repeats",
                          "equals": true
                        },
                        "then": {
                          "template": "arrow.clockwise"
                        },
                        "else": {
                          "template": ""
                        }
                      },
                      "badge_at": {
                        "template": "end"
                      },
                      "badge_label": {
                        "template": "Repeating"
                      },
                      "section": "group"
                    }
                  }
                },
                "empty": {
                  "when": {
                    "path": "due_count",
                    "equals": 0
                  },
                  "text": "Nothing due today."
                }
              },
              "itemAction": {
                "kind": "complete-reminder",
                "label": "Complete",
                "icon": "checkmark"
              }
            }
          ]
        },
        {
          "label": "Upcoming",
          "cards": [
            {
              "id": "upcoming",
              "type": "checklist",
              "mark": "fill",
              "max_items": 7,
              "items": [],
              "source": {
                "ref": "reminders",
                "map": {
                  "items": {
                    "each": "upcoming",
                    "limit": 100,
                    "fields": {
                      "text": {
                        "if": {
                          "path": "priority_mark",
                          "not": ""
                        },
                        "then": {
                          "template": "{priority_mark} {title}"
                        },
                        "else": {
                          "template": "{title}"
                        }
                      },
                      "detail": {
                        "template": "{info}"
                      },
                      "done": "done",
                      "badge": {
                        "if": {
                          "path": "repeats",
                          "equals": true
                        },
                        "then": {
                          "template": "arrow.clockwise"
                        },
                        "else": {
                          "template": ""
                        }
                      },
                      "badge_at": {
                        "template": "end"
                      },
                      "badge_label": {
                        "template": "Repeating"
                      },
                      "section": "group"
                    }
                  }
                },
                "empty": {
                  "when": {
                    "path": "upcoming_count",
                    "equals": 0
                  },
                  "text": "Nothing scheduled in the next 7 days."
                }
              },
              "itemAction": {
                "kind": "complete-reminder",
                "label": "Complete",
                "icon": "checkmark"
              }
            }
          ]
        },
        {
          "label": "No date",
          "cards": [
            {
              "id": "undated",
              "type": "checklist",
              "mark": "fill",
              "max_items": 7,
              "items": [],
              "source": {
                "ref": "reminders",
                "map": {
                  "items": {
                    "each": "undated",
                    "limit": 100,
                    "fields": {
                      "text": {
                        "if": {
                          "path": "priority_mark",
                          "not": ""
                        },
                        "then": {
                          "template": "{priority_mark} {title}"
                        },
                        "else": {
                          "template": "{title}"
                        }
                      },
                      "detail": {
                        "template": "{list}"
                      },
                      "done": "done",
                      "badge": {
                        "if": {
                          "path": "repeats",
                          "equals": true
                        },
                        "then": {
                          "template": "arrow.clockwise"
                        },
                        "else": {
                          "template": ""
                        }
                      },
                      "badge_at": {
                        "template": "end"
                      },
                      "badge_label": {
                        "template": "Repeating"
                      }
                    }
                  }
                },
                "empty": {
                  "when": {
                    "path": "undated_count",
                    "equals": 0
                  },
                  "text": "Every reminder has a date."
                }
              },
              "itemAction": {
                "kind": "complete-reminder",
                "label": "Complete",
                "icon": "checkmark"
              }
            }
          ]
        }
      ]
    },
    {
      "id": "more-reminders",
      "type": "text",
      "tone": "info",
      "body": "Some tabs show only their first 100 reminders. Open Reminders for the rest.",
      "source": {
        "ref": "reminders",
        "when": {
          "any": [
            {
              "path": "due_count",
              "gt": 100
            },
            {
              "path": "upcoming_count",
              "gt": 100
            },
            {
              "path": "undated_count",
              "gt": 100
            }
          ]
        }
      }
    },
    {
      "id": "lists",
      "type": "list",
      "label": "Lists",
      "max_items": 4,
      "items": [],
      "source": {
        "ref": "reminders",
        "map": {
          "items": {
            "each": "lists",
            "limit": 100,
            "fields": {
              "text": "title",
              "detail": "detail",
              "url": {
                "template": "legato://page/reminders-list?list={id}"
              }
            }
          }
        },
        "empty": {
          "when": {
            "path": "list_count",
            "equals": 0
          },
          "text": "No lists in Reminders."
        }
      }
    },
    {
      "id": "completed",
      "type": "heading",
      "text": "Completed",
      "collapsed": true,
      "cards": [
        "done-days",
        "recent"
      ],
      "source": {
        "ref": "reminders",
        "map": {
          "detail": {
            "template": "{done_today} today · {done_count} in 7 days"
          }
        }
      }
    },
    {
      "id": "done-days",
      "type": "columns",
      "label": "Done each day",
      "series": [
        "Done"
      ],
      "items": [],
      "source": {
        "ref": "reminders",
        "map": {
          "items": {
            "each": "by_day",
            "fields": {
              "label": "label",
              "values[0]": "count"
            }
          }
        }
      }
    },
    {
      "id": "recent",
      "type": "list",
      "label": "Recently completed",
      "max_items": 4,
      "items": [],
      "source": {
        "ref": "reminders",
        "map": {
          "items": {
            "each": "completed",
            "limit": 4,
            "fields": {
              "text": "title",
              "detail": {
                "template": "{completed|ago} · {list}"
              }
            }
          }
        },
        "empty": {
          "when": {
            "path": "done_count",
            "equals": 0
          },
          "text": "Nothing completed lately."
        }
      }
    }
  ]
}
