local this = class("cellModuleHomeCenterBuildingManageToggle", G_UIModuleBase)
local moduleHomeCenterBuildingManageConfig = require("ui.pages.home.homeCenter.moduleHomeCenterBuildingManage.moduleHomeCenterBuildingManageConfig")
local ToggleKey2ToggleConfig = moduleHomeCenterBuildingManageConfig.toggleKey2ToggleConfig

function this.bind()
  return {
    active_self = true,
    text_name1 = "",
    text_name2 = ""
  }
end

function this.methods()
  return {
    onClick_toggle = function(self)
      self:emit("onClick_toggle", {
        toggleModuleName = self.UIData.toggleModuleName
      })
    end
  }
end

function this:open()
  self.UIData = {}
  self:registerCallbackOnSystemUpdate()
end

function this:close()
  self:unregisterCallbackOnSystemUpdate()
end

function this:playInactive()
  self.bindComponents.offAnim:Play("anim_homecenter_build_cell_off")
end

function this:playActive()
  self.bindComponents.onAnim:Play("anim_homecenter_build_cell_on")
end

function this:refreshData(toggleKey)
  local toggleConfig = ToggleKey2ToggleConfig[toggleKey]
  self.UIData.toggleName = toggleConfig.toggleName
  self.UIData.toggleModuleName = toggleConfig.toggleModuleName
  self.UIData.systemId = toggleConfig.systemId
end

function this:refreshUI()
  self.bind.text_name1 = self.UIData.toggleName
  self.bind.text_name2 = self.UIData.toggleName
  self:refreshSystemUnlockRelated()
end

function this:registerCallbackOnSystemUpdate()
  L_SystemUnlockStore:listenCallFunc(L_SystemUnlockStore.event.updateSystem, self.refreshSystemUnlockRelated, self)
end

function this:unregisterCallbackOnSystemUpdate()
  L_SystemUnlockStore:unListenCallFunc(L_SystemUnlockStore.event.updateSystem, self.refreshSystemUnlockRelated, self)
end

function this:refreshSystemUnlockRelated(systemId)
  if self.UIData.systemId == nil then
    return
  end
  if systemId ~= nil and systemId ~= self.UIData.systemId then
    return
  end
  if L_SystemUnlockManager:check(self.UIData.systemId) == true then
    self.bind.active_self = true
  else
    self.bind.active_self = false
  end
end

function this:getIfSystemUnlocked()
  return L_SystemUnlockManager:check(self.UIData.systemId) == true
end

function this:getToggleModuleName()
  return self.UIData.toggleModuleName
end

return this
