{
  "$schema": "../../packages/ui/screens/screen.schema.json",
  "id": "emailhub.schedule",
  "version": 1,
  "app": "email-hub",
  "route": "/wochenplan",
  "title": "Wochenplan",
  "data": {
    "schedule": {
      "source": "schedule.get"
    }
  },
  "body": [
    {
      "component": "page-header",
      "data": {
        "title": "Wochenplan",
        "meta": "Trainingszeiten für alle Gruppen — Quelle: live aus dem Google Kalender"
      }
    },
    {
      "component": "alert",
      "data": {
        "tone": "neutral",
        "title": "Diese Zeiten werden automatisch in die generierten Antworten eingefügt, passend zur erkannten Altersgruppe."
      }
    },
    {
      "component": "chip-group",
      "data": {
        "label": "Sortierung",
        "name": "sort",
        "chips": [
          {
            "value": "class",
            "label": "Nach Klasse",
            "pressed": {
              "$not": {
                "$eq": [
                  {
                    "$bind": "params.sort"
                  },
                  "day"
                ]
              }
            },
            "href": "?screen=emailhub.schedule&sort=class"
          },
          {
            "value": "day",
            "label": "Nach Tag",
            "pressed": {
              "$eq": [
                {
                  "$bind": "params.sort"
                },
                "day"
              ]
            },
            "href": "?screen=emailhub.schedule&sort=day"
          }
        ]
      }
    },
    {
      "component": "alert",
      "data": {
        "tone": "warning",
        "title": "Ausfälle & Änderungen",
        "body": {
          "$bind": "schedule.cancellationsText"
        }
      }
    },
    {
      "component": "alert",
      "data": {
        "tone": "info",
        "title": "Ferien & Events",
        "body": {
          "$bind": "schedule.closuresText"
        },
        "link": {
          "label": "bearbeiten",
          "href": "?screen=emailhub.closures"
        }
      }
    },
    {
      "component": "alert",
      "data": {
        "tone": "neutral",
        "title": "Besondere Termine",
        "body": {
          "$bind": "schedule.specialText"
        }
      }
    },
    {
      "layout": "grid",
      "min": "20rem",
      "if": {
        "$not": {
          "$eq": [
            {
              "$bind": "params.sort"
            },
            "day"
          ]
        }
      },
      "children": [
        {
          "each": "schedule.groups",
          "as": "g",
          "node": {
            "component": "table",
            "data": {
              "caption": {
                "$bind": "g.label"
              },
              "density": "dense",
              "stack": false,
              "columns": [
                {
                  "key": "day",
                  "label": "Tag"
                },
                {
                  "key": "time",
                  "label": "Zeit"
                },
                {
                  "key": "name",
                  "label": "Training"
                }
              ],
              "rows": {
                "$each": "g.sessions",
                "as": "s",
                "map": {
                  "cells": {
                    "day": {
                      "$bind": "s.day"
                    },
                    "time": {
                      "$bind": "s.time"
                    },
                    "name": {
                      "$bind": "s.name"
                    }
                  }
                }
              }
            }
          }
        }
      ]
    },
    {
      "layout": "grid",
      "min": "20rem",
      "if": {
        "$eq": [
          {
            "$bind": "params.sort"
          },
          "day"
        ]
      },
      "children": [
        {
          "each": "schedule.days",
          "as": "d",
          "node": {
            "component": "table",
            "data": {
              "caption": {
                "$bind": "d.day"
              },
              "density": "dense",
              "stack": false,
              "columns": [
                {
                  "key": "time",
                  "label": "Zeit"
                },
                {
                  "key": "name",
                  "label": "Training"
                },
                {
                  "key": "group",
                  "label": "Gruppe"
                }
              ],
              "rows": {
                "$each": "d.sessions",
                "as": "s",
                "map": {
                  "cells": {
                    "time": {
                      "$bind": "s.time"
                    },
                    "name": {
                      "$bind": "s.name"
                    },
                    "group": {
                      "$bind": "s.group"
                    }
                  }
                }
              }
            }
          }
        }
      ]
    }
  ]
}
