/********************************************************
*   (c) Mojang. All rights reserved                      *
*   (c) Microsoft. All rights reserved.                  *
*********************************************************/
{
  "namespace": "code",

  "toolbar_button@common.button": {
    "size": [ 16, 16 ],
    "layer": 3,
    "controls": [
      {
        "default": {
          "type": "image",
          "texture": "$default_image"
        }
      },
      {
        "hover": {
          "type": "image",
          "texture": "$hover_image"
        }
      },
      {
        "pressed": {
          "type": "image",
          "texture": "$hover_image"
        }
      }
    ]
  },

  "split_left_button@code.toolbar_button": {
    "$default_image": "textures/ui/left_split_panel_default",
    "$hover_image": "textures/ui/left_split_panel_hover",
    "$pressed_button_name": "button.split_left"
  },

  "split_right_button@code.toolbar_button": {
    "$default_image": "textures/ui/right_split_panel_default",
    "$hover_image": "textures/ui/right_split_panel_hover",
    "$pressed_button_name": "button.split_right"
  },

  "reset_button@code.toolbar_button": {
    "$default_image": "textures/ui/gear_default",
    "$hover_image": "textures/ui/gear_hover",
    "$pressed_button_name": "button.reset"
  },

  "maximize_button@code.toolbar_button": {
    "$default_image": "textures/ui/maximize_arrow_default",
    "$hover_image": "textures/ui/maximize_arrow_hover",
    "$pressed_button_name": "button.maximize"
  },

  "restore_button@code.toolbar_button": {
    "$default_image": "textures/ui/restore_arrow_default",
    "$hover_image": "textures/ui/restore_arrow_hover",
    "$pressed_button_name": "button.restore"
  },

  "close_button@common.empty_panel": {
    "size": [ "100%c", "100%c" ],
    "controls": [
      {
        "button@common.close_button": {
          "$close_button_panel_size": [ 15, 15 ],
          "$close_button_offset": [ 0, -2 ]
        }
      }
    ]
  },

  "editor_button_image": {
    "type": "image",
    "texture": "#texture",
    "bindings": [
      {
        "binding_name": "$texture_binding",
        "binding_name_override": "#texture",
        "binding_type": "collection",
        "binding_collection_name": "editor_buttons_collection",
        "binding_collection_prefix": "editor_buttons"
      }
    ]
  },

  "editor_button@common.button": {
    "$pressed_button_name": "button.editor_button",
    "layer": 4,
    "size": [ "100% - 8px", "100%x" ],
    "$button_text": "#editor_button_text",

    "$button_text_binding_type": "collection",
    "$button_binding_condition": "once",
    "$button_text_grid_collection_name": "editor_buttons_collection",

    "bindings": [
      {
        "binding_type": "collection_details",
        "binding_collection_name": "editor_buttons_collection",
        "binding_collection_prefix": "editor_buttons"
      },
      {
        "binding_type": "collection",
        "binding_collection_name": "editor_buttons_collection",
        "binding_collection_prefix": "editor_buttons",
        "binding_name": "#editor_button_visible",
        "binding_name_override": "#visible"
      }
    ],
    "controls": [
      { "default@code.editor_button_image": { "$texture_binding": "#editor_button_default" } },
      { "hover@code.editor_button_image": { "$texture_binding": "#editor_button_hover" } },
      { "pressed@code.editor_button_image": { "$texture_binding": "#editor_button_hover" } }
    ]
  },

  "padded_editor_button": {
    "type": "panel",
    "size": [ "50%", "100%x" ],
    "controls": [
      { "button@code.editor_button": {} }
    ]
  },

  "editors": {
    "type": "grid",
    "size": [ 120, "100%c" ],
    "grid_item_template": "code.padded_editor_button",
    "grid_dimension_binding": "#editor_grid_dimensions",
    "factory": {
      "name": "editor_button_factory",
      "control_name": "code.padded_editor_button"
    },
    "collection_name": "editor_buttons_collection",
    "bindings": [
      {
        "binding_name": "#editor_grid_dimensions"
      }
    ]
  },

  "editors_panel@common.scrolling_panel": {
    "$show_background": false,
    "size": [ "100%", "fill" ],
    "$scrolling_content": "code.editors",
    "$scrolling_content_anchor_from": "top_middle",
    "$scrolling_content_anchor_to": "top_middle"
  },

  "editor_chooser": {
    "type": "stack_panel",
    "orientation": "vertical",
    "size": [ "100% - 4px", "100% - 1px" ],
    "offset": [ 2, 2 ],
    "anchor_from": "top_left",
    "anchor_to": "top_left",
    "bindings": [
      {
        "binding_name": "#show_editor_chooser",
        "binding_name_override": "#visible"
      }
    ],
    "controls": [
      { "p0@common.empty_panel": { "size": [ 0, 10 ] } },
      {
        "chooser_label@edu_common.light_label": {
          "size": [ "100%", 15 ],
          "text_alignment": "center",
          "text": "codeScreen.chooseEditor"
        }
      },
      { "editors@code.editors_panel": {} }
    ]
  },

  "webview": {
    "type": "custom",
    "anchor_from": "top_middle",
    "anchor_to": "top_middle",
    "offset": [ 0, -1 ],
    "layer": 2,
    // Extra size to overlap with the borders, as we want to maximize web view real estate
    "size": [ "100% + 14px", "100% + 14px" ],
    "renderer": "web_view_renderer",
    "bindings": [
      {
        "binding_name": "#show_webview",
        "binding_name_override": "#visible"
      },
      {
        "binding_type": "global",
        "binding_condition": "visible",
        // Binding itself doesn't do anything, but the callback is used to fill the property bag
        "binding_name": "#webview_update"
      }
    ]
  },

  "code_screen_content": {
    "type": "panel",
    "size": [ "100%", "100%" ],
    "controls": [
      { "chooser@code.editor_chooser": {} },
      { "webview@code.webview": {} }
    ]
  },

  "dim_background": {
    "type": "image",
    "texture": "textures/ui/Banners",
    "alpha": 0.4,
    "layer": -1,
    "controls": [
      {
        "dismiss_region": {
          "type": "button",
          "button_mappings": [
            {
              "from_button_id": "button.menu_select",
              "to_button_id": "button.menu_exit",
              "mapping_type": "pressed"
            },
            {
              "from_button_id": "button.menu_ok",
              "to_button_id": "button.menu_exit",
              "mapping_type": "focused"
            }
          ]
        }
      }
    ]
  },

  "code_screen@common.base_screen": {
    "$screen_content": "code.code_screen_panel",
    "$screen_bg_content": "code.dim_background",
    "button_mappings": [
      {
        "from_button_id": "button.menu_cancel",
        "to_button_id": "button.menu_exit",
        "mapping_type": "global"
      }
    ]
  },

  "no_toolbar@common.empty_panel": {
    "size": [ 0, 0 ]
  },

  "parent_relative_panel@common_dialogs.dialog_background_hollow_3": {
    "$show_close_button|default": true,
    "$child_control|default": "common.empty_panel",
    "$left_toolbar|default": "code.left_toolbar",
    "$right_toolbar|default": "code.right_toolbar",

    "controls": [
      {
        "content_background": {
          "type": "image",
          "texture": "$dialog_background_texture",
          "layer": 1,
          "size": [ "100% - 16px", "100% - 32px" ],
          "offset": [ 0, 7 ],
          "alpha": "$fill_alpha",
          "controls": [
            { "inside_header_panel@$child_control": {} }
          ]
        }
      },
      {
        "toolbar@common.empty_panel": {
          "controls": [
            {
              "left_toolbar": {
                "layer": 20,
                "type": "panel",
                "anchor_from": "top_left",
                "anchor_to": "top_left",
                "offset": [ 6, 4 ],
                "size": [ "100%c", 18 ],
                "controls": [
                  { "toolbar@$left_toolbar": {} }
                ]
              }
            },
            {
              "right_toolbar": {
                "layer": 20,
                "type": "panel",
                "anchor_from": "top_right",
                "anchor_to": "top_right",
                "offset": [ -4, 4 ],
                "size": [ "100%c", 18 ],
                "controls": [
                  { "toolbar@$right_toolbar": {} }
                ]
              }
            },
            {
              "title_label@common_dialogs.title_label": {
                "anchor_from": "top_middle",
                "anchor_to": "top_middle",
                "offset": [ 0, 8 ]
              }
            }
          ]
        }
      },
      {
        "prevent_dismiss_region": {
          "type": "input_panel",
          // A bit big to prevent accidentally dismissing the window when touching near the edge
          "size": [ "100% + 20px", "100%" ],
          // Behind the content but in front of the background dismiss region
          "layer": 0
        }
      }
    ]
  },

  "padded_toolbar_button@common.empty_panel": {
    "size": [ "100%c + 2px", "100%c" ],
    "$toolbar_button_anchor|default": "center",
    "controls": [
      {
        "button@$toolbar_button": {
          "anchor_from": "$toolbar_button_anchor",
          "anchor_to": "$toolbar_button_anchor"
        }
      }
    ]
  },

  "right_padded_toolbar_button@code.padded_toolbar_button": {
    "$toolbar_button_anchor": "top_left"
  },

  "left_padded_toolbar_button@code.padded_toolbar_button": {
    "$toolbar_button_anchor": "top_right"
  },

  "right_toolbar": {
    "type": "stack_panel",
    "orientation": "horizontal",
    "size": [ "100%c", "100%" ],
    "$show_toolbar_close|default": false,

    "controls": [
      {
        "reset@code.left_padded_toolbar_button": {
          "$toolbar_button": "code.reset_button",
          "bindings": [
            {
              "binding_name": "#show_reset",
              "binding_name_override": "#visible"
            }
          ]
        }
      },
      {
        "close@code.left_padded_toolbar_button": {
          "$toolbar_button": "code.close_button",
          "visible": "$show_toolbar_close"
        }
      }
    ]
  },

  "left_toolbar": {
    "type": "stack_panel",
    "orientation": "horizontal",
    "size": [ "100%c", "100%" ],
    "$show_toolbar_split_left|default": false,
    "$show_toolbar_split_right|default": false,
    "$show_toolbar_maximize|default": false,
    "$show_toolbar_restore|default": false,

    "controls": [
      {
        "split_left@code.right_padded_toolbar_button": {
          "visible": "$show_toolbar_split_left",
          "$toolbar_button": "code.split_left_button"
        }
      },
      {
        "split_right@code.right_padded_toolbar_button": {
          "visible": "$show_toolbar_split_right",
          "$toolbar_button": "code.split_right_button"
        }
      },
      {
        "max@code.right_padded_toolbar_button": {
          "visible": "$show_toolbar_maximize",
          "$toolbar_button": "code.maximize_button"
        }
      },
      {
        "restore@code.right_padded_toolbar_button": {
          "visible": "$show_toolbar_restore",
          "$toolbar_button": "code.restore_button"
        }
      }
    ]
  },

  "code_screen_panel_base@code.parent_relative_panel": {
    "$text_name": "codeScreen.title",
    "$child_control": "code.code_screen_content",
    "anchor_from": "$anchor_from_to",
    "anchor_to": "$anchor_from_to",
    "$show_toolbar_reset": true,
    "$show_toolbar_close": true,
    "bindings": [
      {
        "binding_name": "$visibility_binding",
        "binding_name_override": "#visible"
      }
    ]
  },

  "code_screen_panel_split_right@code.code_screen_panel_base": {
    "$anchor_from_to": "top_right",
    "size": [ "50%", "100%" ],
    "$visibility_binding": "#show_split_right",
    "$show_toolbar_split_left": true,
    "$show_toolbar_maximize": true
  },

  "code_screen_panel_split_left@code.code_screen_panel_base": {
    "$anchor_from_to": "top_left",
    "size": [ "50%", "100%" ],
    "$visibility_binding": "#show_split_left",
    "$show_toolbar_split_right": true,
    "$show_toolbar_maximize": true
  },

  "code_screen_panel_full@code.code_screen_panel_base": {
    "$anchor_from_to": "top_right",
    "size": [ "100%", "100%" ],
    "$visibility_binding": "#show_full",
    "$show_toolbar_restore": true
  },

  "reset_warning_content": {
    "type": "image",
    "texture": "textures/ui/Banners",
    "size": [ "100%", "100%" ],
    "controls": [
      {
        "warning_text": {
          "type": "label",
          "anchor_from": "top_middle",
          "anchor_to": "top_middle",
          "size": [ "100% - 4px", "default" ],
          "offset": [ 2, 2 ],
          "color": "$f_color_format",
          "text": "codeScreen.resetWarning"
        }
      }
    ]
  },

  "reset_warning_button@common_buttons.light_text_button": {
    "button_mappings": [
      {
        "from_button_id": "button.menu_select",
        "to_button_id": "$button_mapping",
        "mapping_type": "pressed"
      },
      {
        "from_button_id": "button.menu_ok",
        "to_button_id": "$button_mapping",
        "mapping_type": "focused"
      }
    ]
  },

  "reset_warning_ok@code.reset_warning_button": {
    "$button_mapping": "button.reset_warning_ok",
    "$button_text": "gui.ok"
  },

  "reset_warning_cancel@code.reset_warning_button": {
    "$button_mapping": "button.reset_warning_cancel",
    "$button_text": "gui.cancel"
  },

  "reset_warning": {
    "type": "input_panel",
    "size": [ 220, 135 ],
    "controls": [
      {
        "warning@common_dialogs.main_panel_two_buttons": {
          "layer": 21,
          "$show_close_button": false,
          "$child_control": "code.reset_warning_content",
          "$top_button_panel": "code.reset_warning_ok",
          "$bottom_button_panel": "code.reset_warning_cancel"
        }
      }
    ],
    "bindings": [
      {
        "binding_name": "#show_reset_warning",
        "binding_name_override": "#visible"
      }
    ]
  },

  "code_screen_panel": {
    "type": "panel",
    "controls": [
      { "sr@code_screen_panel_split_right": {} },
      { "sl@code_screen_panel_split_left": {} },
      { "f@code_screen_panel_full": {} },
      { "reset@code.reset_warning": {} }
    ]
  }
}