{
  "$schema": "../../packages/ui/screens/screen.schema.json",
  "id": "training.today",
  "version": 1,
  "app": "trainer",
  "route": "/heute",
  "title": "Heute",
  "nav": {
    "label": "Heute",
    "icon": "home",
    "order": 1,
    "tab": true
  },
  "requires": [
    "training.attendance"
  ],
  "data": {
    "today": {
      "source": "training.sessions.today",
      "offline": true
    },
    "current": {
      "source": "training.sessions.attendance",
      "params": {
        "id": {
          "$bind": "today.next.id"
        }
      },
      "offline": true
    }
  },
  "actions": {
    "markAbsent": {
      "handler": "training.markAbsent",
      "risk": "reversible",
      "success": "Als abwesend markiert"
    },
    "addNote": {
      "handler": "training.addNote",
      "risk": "safe"
    }
  },
  "body": [
    {
      "component": "page-header",
      "data": {
        "title": {
          "$text": "Hallo {user.firstName}"
        },
        "meta": {
          "$text": "{today.dateLabel} · {today.count} Trainings"
        }
      }
    },
    {
      "component": "action-tile",
      "if": {
        "$bind": "today.next"
      },
      "data": {
        "href": "#praesenz",
        "eyebrow": {
          "$text": "Jetzt · {today.next.timeLabel}"
        },
        "title": "Präsenz",
        "icon": "chevron-right",
        "meta": {
          "$text": "{today.next.className} · {today.next.roleLabel}"
        }
      }
    },
    {
      "layout": "section",
      "id": "praesenz",
      "title": {
        "$bind": "current.className"
      },
      "children": [
        {
          "layout": "cluster",
          "justify": "between",
          "children": [
            {
              "component": "badge",
              "data": {
                "label": {
                  "$text": "{current.presentCount} von {current.total} da"
                },
                "tone": "info"
              }
            },
            {
              "component": "save-status",
              "data": {
                "state": {
                  "$bind": "current.sync.state"
                },
                "count": {
                  "$bind": "current.sync.pending"
                }
              }
            }
          ]
        },
        {
          "component": "list",
          "data": {
            "label": {
              "$text": "Teilnehmende {current.className}"
            },
            "items": {
              "$each": "current.students",
              "as": "s",
              "map": {
                "id": {
                  "$bind": "s.id"
                },
                "title": {
                  "$bind": "s.name"
                },
                "meta": {
                  "$bind": "s.note"
                },
                "avatar": {
                  "$bind": "s.initials"
                },
                "belt": {
                  "label": {
                    "$bind": "s.belt.label"
                  },
                  "color": {
                    "$bind": "s.belt.color"
                  }
                },
                "done": {
                  "$not": {
                    "$bind": "s.present"
                  }
                },
                "actions": [
                  {
                    "action": "markAbsent",
                    "label": "Als abwesend markieren",
                    "icon": "x"
                  },
                  {
                    "action": "addNote",
                    "label": "Notiz hinzufügen",
                    "icon": "edit"
                  }
                ],
                "swipe": {
                  "mode": "reveal",
                  "end": {
                    "action": "markAbsent",
                    "label": "War nicht da",
                    "icon": "x",
                    "tone": "danger"
                  }
                }
              }
            }
          }
        }
      ]
    },
    {
      "layout": "section",
      "id": "spaeter",
      "title": "Später",
      "if": {
        "$bind": "today.later.length"
      },
      "children": [
        {
          "component": "list",
          "data": {
            "label": "Weitere Trainings heute",
            "items": {
              "$each": "today.later",
              "as": "t",
              "map": {
                "id": {
                  "$bind": "t.id"
                },
                "title": {
                  "$bind": "t.title"
                },
                "meta": {
                  "$bind": "t.meta"
                },
                "href": "#"
              }
            }
          }
        }
      ]
    }
  ]
}
