{
  "$schema": "../../packages/ui/screens/screen.schema.json",
  "id": "athlete.challenges-archive",
  "version": 1,
  "app": "athlete",
  "route": "/challenges/archiv",
  "title": "Frühere Challenges",
  "data": {
    "archive": {
      "source": "athlete.challenges.past"
    }
  },
  "chrome": {
    "title": "Frühere Challenges",
    "back": {
      "label": "Challenges",
      "href": "?screen=athlete.challenges"
    }
  },
  "body": [
    {
      "component": "page-header",
      "data": {
        "title": "Frühere Challenges"
      }
    },
    {
      "component": "chip-group",
      "data": {
        "label": "Status",
        "name": "status",
        "chips": [
          {
            "value": "all",
            "label": "Alle",
            "href": {
              "$text": "?screen=athlete.challenges-archive&status=all&month={params.month}"
            },
            "pressed": {
              "$eq": [
                {
                  "$bind": "params.status"
                },
                "all"
              ]
            }
          },
          {
            "value": "done",
            "label": "Erledigt",
            "href": {
              "$text": "?screen=athlete.challenges-archive&status=done&month={params.month}"
            },
            "pressed": {
              "$eq": [
                {
                  "$bind": "params.status"
                },
                "done"
              ]
            }
          },
          {
            "value": "expired",
            "label": "Abgelaufen",
            "href": {
              "$text": "?screen=athlete.challenges-archive&status=expired&month={params.month}"
            },
            "pressed": {
              "$eq": [
                {
                  "$bind": "params.status"
                },
                "expired"
              ]
            }
          }
        ]
      }
    },
    {
      "component": "chip-group",
      "data": {
        "label": "Monat",
        "name": "month",
        "chips": [
          {
            "value": "all",
            "label": "Alle Monate",
            "href": {
              "$text": "?screen=athlete.challenges-archive&month=all&status={params.status}"
            },
            "pressed": {
              "$eq": [
                {
                  "$bind": "params.month"
                },
                "all"
              ]
            }
          },
          {
            "value": "2026-09",
            "label": "Sep 2026",
            "href": {
              "$text": "?screen=athlete.challenges-archive&month=2026-09&status={params.status}"
            },
            "pressed": {
              "$eq": [
                {
                  "$bind": "params.month"
                },
                "2026-09"
              ]
            }
          },
          {
            "value": "2026-08",
            "label": "Aug 2026",
            "href": {
              "$text": "?screen=athlete.challenges-archive&month=2026-08&status={params.status}"
            },
            "pressed": {
              "$eq": [
                {
                  "$bind": "params.month"
                },
                "2026-08"
              ]
            }
          }
        ]
      }
    },
    {
      "each": "archive.items",
      "as": "c",
      "where": {
        "$and": [
          {
            "$or": [
              {
                "$eq": [
                  {
                    "$bind": "params.status"
                  },
                  "all"
                ]
              },
              {
                "$eq": [
                  {
                    "$bind": "c.status"
                  },
                  {
                    "$bind": "params.status"
                  }
                ]
              }
            ]
          },
          {
            "$or": [
              {
                "$eq": [
                  {
                    "$bind": "params.month"
                  },
                  "all"
                ]
              },
              {
                "$eq": [
                  {
                    "$bind": "c.month"
                  },
                  {
                    "$bind": "params.month"
                  }
                ]
              }
            ]
          }
        ]
      },
      "node": {
        "layout": "card",
        "itemId": {
          "$bind": "c.id"
        },
        "title": {
          "$bind": "c.title"
        },
        "tags": [
          {
            "label": {
              "$text": "+{c.points} P."
            },
            "kind": "points"
          }
        ],
        "children": [
          {
            "layout": "cluster",
            "children": [
              {
                "component": "badge",
                "data": {
                  "label": {
                    "$bind": "c.statusLabel"
                  },
                  "tone": {
                    "$bind": "c.tone"
                  }
                }
              },
              {
                "component": "badge",
                "data": {
                  "label": {
                    "$bind": "c.category"
                  }
                }
              }
            ]
          }
        ]
      }
    },
    {
      "component": "empty-state",
      "if": {
        "$eq": [
          {
            "$count": "archive.items",
            "as": "c",
            "where": {
              "$and": [
                {
                  "$or": [
                    {
                      "$eq": [
                        {
                          "$bind": "params.status"
                        },
                        "all"
                      ]
                    },
                    {
                      "$eq": [
                        {
                          "$bind": "c.status"
                        },
                        {
                          "$bind": "params.status"
                        }
                      ]
                    }
                  ]
                },
                {
                  "$or": [
                    {
                      "$eq": [
                        {
                          "$bind": "params.month"
                        },
                        "all"
                      ]
                    },
                    {
                      "$eq": [
                        {
                          "$bind": "c.month"
                        },
                        {
                          "$bind": "params.month"
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          },
          0
        ]
      },
      "data": {
        "icon": "filter",
        "title": "Nichts in dieser Auswahl",
        "text": "Wähle einen anderen Status oder Monat."
      }
    }
  ]
}
