{
  "$schema": "../../packages/ui/screens/screen.schema.json",
  "id": "comms.inquiry",
  "version": 2,
  "app": "anfragen",
  "route": "/anfragen/gesendet/:id",
  "title": {
    "$text": "Anfrage von {inquiry.from}"
  },
  "requires": [
    "comms.inquiries"
  ],
  "data": {
    "inquiry": {
      "source": "comms.inquiries.get",
      "params": {
        "id": {
          "$bind": "params.id"
        }
      }
    }
  },
  "actions": {
    "sendRegistrationLink": {
      "handler": "comms.sendRegistrationLink",
      "risk": "safe",
      "success": {
        "$text": "Link zum Anmeldeformular an {inquiry.fromEmail} geschickt"
      }
    }
  },
  "body": [
    {
      "component": "alert",
      "if": {
        "$not": {
          "$flag": "anfragen.history"
        }
      },
      "data": {
        "tone": "neutral",
        "title": "Diese Seite gehört zur Funktion «Verlauf je Anfrage»",
        "body": "Sie ist ausgeschaltet; schalte sie unter «Funktionen» ein."
      }
    },
    {
      "component": "page-header",
      "data": {
        "title": {
          "$bind": "inquiry.from"
        },
        "meta": {
          "$text": "Gesendet von {inquiry.sentBy} · {inquiry.sentLabel}"
        },
        "back": {
          "label": "Gesendet",
          "href": "?screen=comms.sent"
        },
        "actions": [
          {
            "label": "Anmeldeformular schicken",
            "icon": "mail",
            "action": "sendRegistrationLink",
            "actionId": {
              "$bind": "inquiry.id"
            }
          }
        ]
      }
    },
    {
      "layout": "split",
      "children": [
        {
          "layout": "stack",
          "children": [
            {
              "component": "message",
              "data": {
                "label": "Anfrage",
                "from": {
                  "$text": "{inquiry.from} <{inquiry.fromEmail}>"
                },
                "dateLabel": {
                  "$bind": "inquiry.dateLabel"
                },
                "subject": {
                  "$bind": "inquiry.subject"
                },
                "body": {
                  "$bind": "inquiry.body"
                }
              }
            },
            {
              "component": "message",
              "data": {
                "direction": "out",
                "label": {
                  "$text": "Antwort von {inquiry.sentBy}"
                },
                "from": "Taekwondo Bern <training@taekwondobern.ch>",
                "to": {
                  "$text": "{inquiry.from} <{inquiry.fromEmail}>"
                },
                "dateLabel": {
                  "$bind": "inquiry.sentLabel"
                },
                "body": {
                  "$bind": "inquiry.replyDraft"
                }
              }
            }
          ]
        },
        {
          "layout": "stack",
          "children": [
            {
              "component": "kv",
              "data": {
                "items": [
                  {
                    "term": "Stand",
                    "value": {
                      "$bind": "inquiry.outcome.label"
                    }
                  }
                ]
              }
            },
            {
              "layout": "section",
              "id": "verlauf",
              "title": "Verlauf",
              "children": [
                {
                  "component": "list",
                  "data": {
                    "label": "Verlauf der Anfrage",
                    "items": {
                      "$each": "inquiry.history",
                      "as": "h",
                      "map": {
                        "id": {
                          "$bind": "h.id"
                        },
                        "title": {
                          "$bind": "h.title"
                        },
                        "meta": {
                          "$bind": "h.meta"
                        }
                      }
                    }
                  }
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}
