---
-- @package   eg4-crank-ui
-- @file      hardware-fitted.lua
-- @brief     Handles hardware fitted informationm
--
-- @copyright Copyright 2020 Hanover Displays Limited.
-- @license   This program is the confidential and proprietary product of
--            Hanover Displays Limited. Any unauthorised use, reproduction or
--            transfer of this program is strictly prohibited. (Subject to 
--            limited distribution and restricted disclosure only.) All 
--            rights reserved.                                              
--
--



---
--- @brief  Process hardware fitted status event
--- @param  gre#context mapargs
---
function CBProcessHardwareFittedStatus(mapargs)
  if mapargs.context_event_data.text == nil then
    return
  end
  local info = assert(loadstring(mapargs.context_event_data.text))()
  if info == nil then
    return
  end
  
  local table = mapargs.context_layer..".hardware_fitted_group.items"
  -- Adjust table to number of rows available
  gre.set_table_attrs(table, {height = #info * 81})
  gre.set_table_attrs(table, {rows = #info})

  -- Populate table items
  local data = {}
  for row=1,#info do
    data[string.format(table..".text.%d.1", row)] = info[row].name
    SetCheckboxValue(table, info[row].fitted, row)
  end

  gre.set_data(data)

  SBCInitialiseScrollbar(mapargs)
end
