local this = class("cellReleaseFilterGroup", G_UIModuleBase)
local petReleaseTypeTpl = L_GameTpl:getPetReleaseTypeTpl()

function this.bind()
  return {
    txt_title = nil,
    go_content = true,
    isOn_arrow = true,
    list_option = {
      moduleName = "pages/pet/cellReleaseFilterOption"
    }
  }
end

function this.methods()
  return {
    onClick_title = function(self)
      self.bind.go_content = not self.bind.go_content
      self.bind.isOn_arrow = self.bind.go_content
      L_GameUtil.forceRebuildLayout(self.bindComponents.rect_cellSortFilterGroup)
      self:emit("onClick_title", self.uiBinding, self.bind.go_content)
    end,
    list_option = {
      onClick_select = function(self, id)
        self:setOptionListActive(id)
      end
    }
  }
end

function this:open()
end

function this:refresh()
  self:initOptionList()
end

function this:initOptionList()
  if not self.isBind then
    return
  end
  local data = {}
  local subIds = petReleaseTypeTpl:getSubTypeId(self.bind.tpl)
  self.bind.txt_title = petReleaseTypeTpl:getName(self.bind.tpl)
  local defaultSelectId = petReleaseTypeTpl:getDefaultSubTypeId(self.bind.tpl)
  if math.isEmpty(defaultSelectId) then
    defaultSelectId = subIds[1]
  end
  for _, v in ipairs(subIds) do
    table.insert(data, {
      subId = v,
      go_active = v == defaultSelectId
    })
    if v == defaultSelectId then
      self.selectSubId = v
    end
  end
  self.bind.list_option:clear()
  self.bind.list_option:insert_array(data)
  L_GameUtil.forceRebuildLayout(self.bindComponents.rect_list_option)
  L_GameUtil.forceRebuildLayout(self.bindComponents.rect_cellSortFilterGroup)
end

function this:setOptionListActive(subId)
  self.selectSubId = subId
  for _, v in ipairs(self.modules.list_option) do
    v:setActive(v.bind.subId == subId)
  end
end

function this:getSelectValueList()
  if not table.isEmpty(self._selectValueList) then
    return self._selectValueList
  end
end

function this:getSelectSubId()
  return self.selectSubId
end

return this
