{
  "namespace": "trade_pocket",

  //---------------------------------------------------------------------------
  // Common Controls
  //---------------------------------------------------------------------------

  // Backgrounds //
  "background_image": {
    "type": "image",
    "size": [ "100%", "100%" ],
    "texture": "textures/ui/background_panel",
    "layer": 1
  },

  "recipe_item_panel": {
    "type": "panel",
    "size": [ 26, 26 ],
    "$item_collection_name": "$recipe_collection",
    "controls": [
      {
        "item_renderer@common.item_renderer": {
          "size": [ 16, 16 ],
          "layer": 1,
          "bindings": [
            {
              "binding_name": "#item_id_aux",
              "binding_condition": "visible",
              "binding_type": "collection",
              "binding_collection_name": "$item_collection_name"
            }
          ],
          "controls": [
            {
              "stack_count_label@common.stack_count_label": {
                "layer": 2,
                "bindings": [
                  {
                    "binding_name": "#item_stack_count",
                    "binding_name_override": "#inventory_stack_count",
                    "binding_condition": "visible",
                    "binding_type": "collection",
                    "binding_collection_name": "$item_collection_name"
                  }
                ]
              }
            }
          ]
        }
      }
    ]
  },

  "result_item_panel": {
    "type": "panel",
    "size": [ 26, 26 ],
    "$item_collection_name": "$recipe_collection",
    "controls": [
      {
        "output_item_name": {
          "type": "label",
          "color": "$dark_body_text_color",
          "anchor_from": "top_middle",
          "anchor_to": "bottom_middle",
          "text": "#text",
          "text_alignment": "center",
          "size": [ "300%", "default" ],
          "bindings": [
            {
              "binding_name": "#sell_item_name",
              "binding_name_override": "#text",
              "binding_type": "global",
              "binding_condition": "visible"
            }
          ]
        }
      },
      { "recipe_item_panel@trade.recipe_item_panel": {} }
    ]
  },

  "trade_item_slot": {
    "type": "panel",
    "size": [ 26, 26 ],
    "$item_collection_name": "$trade_ingredient_collection",
    "controls": [
      {
        "container_item@common.pocket_ui_container_item": {
          "anchor_to": "center",
          "anchor_from": "center"
        }
      }
    ]
  },

  "trade_item_slotB@trade_item_slot": {
    "bindings": [
      {
        "binding_name": "#show_second_trade_slot",
        "binding_name_override": "#visible",
        "binding_type": "global"
      }
    ]
  },

  "trade_item_slot_result_button@common.container_slot_button_prototype": {
    "button_mappings": [
      {
        "from_button_id": "button.menu_select",
        "to_button_id": "button.trade_take_all_place_all",
        "mapping_type": "pressed"
      },
      {
        "from_button_id": "button.menu_ok",
        "to_button_id": "button.trade_take_all_place_all",
        "mapping_type": "pressed"
      },
      {
        "from_button_id": "button.menu_secondary_select",
        "to_button_id": "button.trade_take_all_place_all",
        "mapping_type": "pressed"
      },
      {
        "from_button_id": "button.controller_select",
        "to_button_id": "button.trade_take_all_place_all",
        "mapping_type": "pressed"
      },
      {
        "from_button_id": "button.menu_auto_place",
        "to_button_id": "button.container_auto_place",
        "mapping_type": "pressed"
      },
      {
        "from_button_id": "button.controller_secondary_select",
        "to_button_id": "button.container_auto_place",
        "mapping_type": "pressed"
      },
      {
        "from_button_id": "button.menu_inventory_drop",
        "to_button_id": "button.drop_one",
        "mapping_type": "pressed"
      },
      {
        "from_button_id": "button.menu_inventory_drop_all",
        "to_button_id": "button.drop_all",
        "mapping_type": "pressed"
      },
      {
        "from_button_id": "button.menu_select",
        "to_button_id": "button.trade_coalesce_stack",
        "mapping_type": "double_pressed"
      },
      {
        "from_button_id": "button.menu_ok",
        "to_button_id": "button.trade_coalesce_stack",
        "mapping_type": "double_pressed"
      },
      {
        "to_button_id": "button.container_slot_hovered",
        "mapping_type": "pressed"
      }
    ]
  },

  "trade_item_slot_result@trade_item_slot": {
    "$button_ref": "trade_pocket.trade_item_slot_result_button"
  },

  //---------------------------------------------------------------------------
  // Panels
  //---------------------------------------------------------------------------

  // Merchant Grid and Panel's //

  "purchase_grid": {
    "type": "grid",
    "size": [ 120, 60 ],
    "anchor_from": "center",
    "anchor_to": "center",
    "grid_dimensions": [ 4, 1 ],
    "controls": [
      {
        "grid_slot1@trade.purchase_grid_item": {
          "grid_position": [ 0, 0 ],
          "$top_item": "trade.recipe_item_panel",
          "$bottom_item": "trade_pocket.trade_item_slot",
          "$recipe_collection": "trade_item_A",
          "$trade_ingredient_collection": "trade_ingredient1_items"
        }
      },
      {
        "grid_slot2@trade.purchase_grid_item": {
          "grid_position": [ 1, 0 ],
          "$top_item": "trade.recipe_item_panel",
          "$bottom_item": "trade_pocket.trade_item_slotB",
          "$recipe_collection": "trade_item_B",
          "$trade_ingredient_collection": "trade_ingredient2_items"
        }
      },
      {
        "arrow@trade.purchase_grid_item": {
          "grid_position": [ 2, 0 ],
          "$top_item": "trade.arrow",
          "$bottom_item": "trade.arrow"
        }
      },
      {
        "result_item_slot@trade.purchase_grid_item": {
          "grid_position": [ 3, 0 ],
          "$cell_image_size": [ 26, 26 ],
          "$top_item": "trade_pocket.result_item_panel",
          "$bottom_item": "trade_pocket.trade_item_slot_result",
          "$recipe_collection": "sell_item",
          "$trade_ingredient_collection": "trade_result_item"
        }
      }
    ]
  },

  "merchant_purchase_panel": {
    "type": "panel",
    "controls": [
      {
        "left@trade.cycle_recipe_left_button": {
          "size": [ 30, 30 ],
          "$default_texture": "textures/ui/pocket_button_default",
          "$hover_texture": "textures/ui/pocket_button_hover",
          "$pressed_texture": "textures/ui/pocket_button_pressed"
        }
      },
      { "purchase_grid@trade_pocket.purchase_grid": {} },
      {
        "right@trade.cycle_recipe_right_button": {
          "size": [ 30, 30 ],
          "$default_texture": "textures/ui/pocket_button_default",
          "$hover_texture": "textures/ui/pocket_button_hover",
          "$pressed_texture": "textures/ui/pocket_button_pressed"
        }
      }
    ]
  },

  "merchant_panel": {
    "type": "panel",
    "size": [ 200, 80 ],
    "controls": [
      { "merchant_purchase_panel@trade_pocket.merchant_purchase_panel": {} }
    ]
  },

  // Inventory Grids and Panel //

  "inventory_grid": {
    "type": "grid",
    "grid_rescaling_type": "horizontal",
    "anchor_to": "top_left",
    "anchor_from": "top_left",
    "size": [ "100%", "default" ],
    "maximum_grid_items": 36,
    "collection_name": "combined_hotbar_and_inventory_items",
    "grid_item_template": "common.pocket_ui_container_item",
    "$item_collection_name": "combined_hotbar_and_inventory_items"
  },

  "inventory_content": {
    "type": "panel",
    "size": [ "80%", "95%" ],
    "anchor_to": "center",
    "anchor_from": "center",
    "controls": [
      {
        "scrolling_panel@common.scrolling_panel": {
          "layer": 1,
          "$allow_scrolling_even_when_content_fits": false,
          "$scrolling_pane_size": [ "100%", "100%-2px" ],
          "$scrolling_content": "trade_pocket.inventory_grid",
          "$scroll_box_mouse_image_control": "common-classic.button_state_default",
          "$scroll_size": [ "8px", "100%" ]
        }
      }
    ]
  },

  //---------------------------------------------------------------------------
  // Screens
  //---------------------------------------------------------------------------

  // Half Screens //
  "half_screen": {
    "type": "panel",
    "size": [ "50%", "100%-31px" ],
    "offset": [ 0, 27 ],
    "anchor_from": "top_left",
    "anchor_to": "top_left"
  },

  "inventory_half_screen@trade_pocket.half_screen": {
    "size": [ "50%", "100%-35px" ],
    "max_size": [ "100%-200px", "100%-35px" ],
    "offset": [ 9, 31 ],
    "controls": [
      { "inventory_content@trade_pocket.inventory_content": {} }
    ]
  },

  "merchant_half_screen@trade_pocket.half_screen": {
    "anchor_from": "top_right",
    "anchor_to": "top_right",
    "size": [ "50%", "100%-35px" ],
    "min_size": [ 200, "100%-35px" ],
    "controls": [
      { "merchant_panel@trade_pocket.merchant_panel": {} }
    ]
  },

  // Header //
  "header": {
    "type": "panel",
    "layer": 2,
    "size": [ "100%", 28 ],
    "anchor_from": "top_middle",
    "anchor_to": "top_middle",
    "controls": [
      {
        "header_background": {
          "type": "image",
          "texture": "textures/ui/header_bar"
        }
      },
      { "close_button@common.legacy_pocket_close_button": {} },
      {
        "villager_name_label": {
          "type": "label",
          "color": "$pocket_title_text_color",
          "text": "$villager_name",
          "layer": 1,
          "anchor_from": "center",
          "anchor_to": "center"
        }
      }
    ]
  },

  // Trade Screen //
  "trade_panel@common.inventory_screen_common": {
    "size": [ "100%", "100%" ],
    "controls": [
      { "bg@background_image": { "layer": 1 } },
      { "root_panel@common.root_panel": {} },
      { "header@trade_pocket.header": { "layer": 2 } },
      {
        "inventory@trade_pocket.inventory_half_screen": {
          "layer": 1
        }
      },
      { "merchant_half_screen@trade_pocket.merchant_half_screen": { "layer": 8 } },

      { "gamepad_helpers@common.container_gamepad_helpers": { "layer": 1 } },
      { "container_gamepad_helpers@common.container_gamepad_helpers": { "layer": 2 } },
      { "inventory_selected_icon_button@common.inventory_selected_icon_button": {} },
      { "selected_item_details_factory@common.selected_item_details_factory": {} },
      {
        "item_lock_notification_factory@common.item_lock_notification_factory": {
          "$offset": [ 0, "85%" ]
        }
      },
      { "flying_item_renderer@common.flying_item_renderer": {} }
    ],
    "button_mappings": [
      {
        "from_button_id": "button.menu_cancel",
        "to_button_id": "button.menu_exit",
        "mapping_type": "global"
      }
    ]
  }
}
