{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://rangka-os.github.io/rangka-os/schema/0.5/layout.json",
  "title": "Rangka layout",
  "description": "Layer 6: the app shell and pages built from UI blocks. Templates: side-only (Frappe-style sidebar, default), top-nav, pos (full-screen counter), portal (customers).",
  "type": "object",
  "required": [
    "name"
  ],
  "additionalProperties": false,
  "properties": {
    "$schema": {
      "type": "string"
    },
    "name": {
      "$ref": "model.json#/$defs/name"
    },
    "label": {
      "$ref": "model.json#/$defs/label"
    },
    "extends": {
      "type": "string",
      "default": "rangka/side-only"
    },
    "shell": {
      "enum": [
        "top-nav",
        "side-only",
        "pos",
        "portal"
      ],
      "default": "side-only"
    },
    "home": {
      "type": "string",
      "pattern": "^(dashboard|model|page):[a-z][a-z0-9_]*$",
      "description": "Start page, e.g. dashboard:crm_overview"
    },
    "nav": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "top": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/link"
          },
          "maxItems": 6
        },
        "side": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "items"
            ],
            "additionalProperties": false,
            "properties": {
              "group": {
                "$ref": "model.json#/$defs/label"
              },
              "items": {
                "type": "array",
                "items": {
                  "anyOf": [
                    {
                      "$ref": "#/$defs/link"
                    },
                    {
                      "type": "object",
                      "required": [
                        "label",
                        "items"
                      ],
                      "additionalProperties": false,
                      "description": "A sub-menu (contract 0037)",
                      "properties": {
                        "label": {
                          "$ref": "model.json#/$defs/label"
                        },
                        "icon": {
                          "type": "string"
                        },
                        "items": {
                          "type": "array",
                          "minItems": 1,
                          "maxItems": 12,
                          "items": {
                            "$ref": "#/$defs/link"
                          }
                        }
                      }
                    }
                  ]
                }
              },
              "collapsed": {
                "type": "boolean",
                "description": "Starting state of the group (contract 0037)"
              }
            }
          }
        },
        "create": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]*$"
          },
          "description": "Models offered by the blue Buat button"
        },
        "app_switcher": {
          "type": "boolean",
          "default": true
        }
      }
    },
    "responsive": {
      "type": "object",
      "additionalProperties": false,
      "description": "Desk shells per width (contract 0038); breakpoints come from the design tokens",
      "properties": {
        "tablet": {
          "enum": [
            "rail",
            "sidebar",
            "drawer"
          ],
          "description": "768-1023px; default rail"
        },
        "phone": {
          "enum": [
            "drawer",
            "tabs"
          ],
          "description": "below 768px; default drawer"
        },
        "tabs": {
          "type": "array",
          "minItems": 2,
          "maxItems": 5,
          "items": {
            "$ref": "#/$defs/link"
          },
          "description": "phone: tabs only; a last Menu tab opens the drawer"
        }
      }
    },
    "pages": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/page"
      }
    }
  },
  "$defs": {
    "link": {
      "type": "object",
      "required": [
        "to"
      ],
      "additionalProperties": false,
      "properties": {
        "to": {
          "type": "string",
          "pattern": "^(dashboard|model|page|settings|url):.+$"
        },
        "label": {
          "$ref": "model.json#/$defs/label"
        },
        "icon": {
          "type": "string"
        },
        "if": {
          "$ref": "model.json#/$defs/cel"
        }
      }
    },
    "block": {
      "type": "object",
      "required": [
        "block"
      ],
      "additionalProperties": false,
      "properties": {
        "block": {
          "enum": [
            "page_header",
            "list",
            "board",
            "form",
            "dashboard",
            "number",
            "chart",
            "table",
            "markdown",
            "filter_bar",
            "tabs",
            "columns",
            "empty_state",
            "embed"
          ]
        },
        "span": {
          "type": "integer",
          "minimum": 1,
          "maximum": 12
        },
        "props": {
          "type": "object",
          "description": "Props of the UI block, e.g. {model: deal, view: kanban}"
        },
        "children": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/block"
          }
        },
        "if": {
          "$ref": "model.json#/$defs/cel"
        }
      }
    },
    "page": {
      "type": "object",
      "required": [
        "name",
        "label",
        "blocks"
      ],
      "additionalProperties": false,
      "properties": {
        "name": {
          "$ref": "model.json#/$defs/name"
        },
        "label": {
          "$ref": "model.json#/$defs/label"
        },
        "icon": {
          "type": "string"
        },
        "roles": {
          "type": "array",
          "items": {
            "$ref": "model.json#/$defs/name"
          }
        },
        "blocks": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/block"
          },
          "minItems": 1
        }
      }
    }
  }
}
