local Prop = require("gfx.prop")
local Children = require("gfx.prop.children")
local Element = require("gfx.element")

local Container = Element:new()

function Container:getHeight()
  if self:isStrict() then
    return Element.getHeight(self)
  end
  local max = 0
  for _,child in self:_iterateChildren() do
    max = math.max(max, child:getY() + child:getHeight())
  end
  return max
end

function Container:getWidth()
  if self:isStrict() then
    return Element.getWidth(self)
  end
  local max = 0
  for _,child in self:_iterateChildren() do
    max = math.max(max, child:getX() + child:getWidth())
  end
  return max
end

function Container:isStrict()
  return self.strict == true
end

function Container:setStrict(strict)
  local needReload = (not not self.strict) ~= strict
  self.strict = strict
  if needReload then
    self:_reload()
  end
end

return Prop.attach(Container, Children)