{
  "$schema": "./.schemas/page.schema.json",
  "title": "Budget",
  "icon": "chart.pie",
  "sources": {
    "ynab": {
      "url": "https://api.ynab.com/v1/plans/last-used/months/current",
      "secret": "ynab",
      "every": "15m",
      "derive": [
        {
          "name": "overspent",
          "value": {
            "count": "data.month.categories",
            "where": {
              "path": "balance",
              "lt": 0
            }
          }
        }
      ]
    }
  },
  "cards": [
    {
      "id": "assign",
      "type": "stat",
      "label": "Ready to assign",
      "unit": "USD",
      "value": 0,
      "source": {
        "ref": "ynab",
        "map": {
          "value": "data.month.to_be_budgeted_currency",
          "delta": {
            "template": "Age of money {data.month.age_of_money} days"
          }
        }
      }
    },
    {
      "id": "overspent",
      "type": "status",
      "label": "Categories",
      "state": "unknown",
      "source": {
        "ref": "ynab",
        "map": {
          "state": {
            "path": "overspent",
            "values": {
              "0": "ok"
            },
            "default": "warning"
          },
          "detail": {
            "path": "overspent",
            "values": {
              "0": "Nothing overspent this month"
            },
            "default": {
              "template": "{overspent} overspent this month"
            }
          }
        }
      }
    },
    {
      "id": "spending",
      "type": "list",
      "label": "Left in your biggest categories",
      "items": [],
      "source": {
        "ref": "ynab",
        "map": {
          "items": {
            "each": "data.month.categories",
            "where": {
              "path": "hidden",
              "equals": false
            },
            "sort": "activity",
            "limit": 5,
            "template": "{name} · {balance_formatted}"
          }
        }
      }
    },
    {
      "id": "open",
      "type": "link",
      "label": "Open YNAB",
      "url": "https://app.ynab.com"
    }
  ]
}
