local ParkourBonusPanel = BaseClass("ParkourBonusPanel", UIAsyncContainer)
local Const = require("Scene.LWBattle.Const")
local base = UIAsyncContainer
local Localization = CS.GameEntry.Localization
local ParkourBonusTimeConditionPanel = require("UI.UIParkour.MainUI.Component.ParkourBonus.ParkourBonusTimeConditionPanel")
local ParkourBonusGoldPanel = require("UI.UIParkour.MainUI.Component.ParkourBonus.ParkourBonusGoldPanel")
local ParkourBonusProgressPanel = require("UI.UIParkour.MainUI.Component.ParkourBonus.ParkourBonusProgressPanel")
local OnCreate = function(self)
  base.OnCreate(self)
  self:ComponentDefine()
  self:DataDefine()
end
local OnDestroy = function(self)
  self:DataDestroy()
  self:ComponentDestroy()
  base.OnDestroy(self)
end
local OnEnable = function(self)
  base.OnEnable(self)
end
local OnDisable = function(self)
  base.OnDisable(self)
end
local ComponentDefine = function(self)
  self.compTimeConditionPanel = self:AddComponent(ParkourBonusTimeConditionPanel, "TimeConditionPanel")
  self.compGoldPanel = self:AddComponent(ParkourBonusGoldPanel, "GoldPanel")
  self.compProgressPanel = self:AddComponent(ParkourBonusProgressPanel, "ProgressPanel")
  self.compTimeConditionPanel:SetActive(false)
  self.compGoldPanel:SetActive(false)
  self.compProgressPanel:SetActive(false)
end
local ComponentDestroy = function(self)
  self.compTimeConditionPanel = nil
  self.compGoldPanel = nil
  self.compProgressPanel = nil
end
local DataDefine = function(self)
end
local DataDestroy = function(self)
  self.bonusType = nil
  self.conditions = nil
  self.cacheInitParam = nil
  self.cacheRefreshParam = nil
  self.cacheRefreshConditionsParam = nil
end
local OnAddListener = function(self)
  base.OnAddListener(self)
end
local OnRemoveListener = function(self)
  base.OnRemoveListener(self)
end
local SetData = function(self, param)
  if self:AsyncLoadDone() then
    self:SetDataOnDone(param)
  else
    self.cacheInitParam = param
  end
end
local SetDataOnDone = function(self, param)
  self.bonusType = param.bonusType
  self.conditions = param.conditions
  self.compGoldPanel:SetActive(false)
  self.compProgressPanel:SetActive(false)
  if self.bonusType == Const.ParkourBattleBonusType.GoldMonster then
    self.compGoldPanel:SetActive(true)
    self.compGoldPanel:SetData(param.extendData)
  elseif self.bonusType == Const.ParkourBattleBonusType.ProgressMonster then
    self.compProgressPanel:SetActive(true)
    self.compProgressPanel:SetData(param.extendData)
  end
  self.compTimeConditionPanel:SetActive(false)
  if param.conditions then
    local timeCondition = param.conditions[Const.ParkourWinType.Time]
    if timeCondition then
      self.compTimeConditionPanel:SetActive(true)
      self.compTimeConditionPanel:SetData(param.useTime, timeCondition)
    end
  end
end
local Refresh = function(self, param)
  if self:AsyncLoadDone() then
    self:RefreshOnDone(param)
  else
    self.cacheRefreshParam = param
  end
end
local RefreshOnDone = function(self, param)
  if param.goodsId then
    if param.goodsId == ResourceType.Wood then
      self.compGoldPanel:SetActive(true)
      self.compGoldPanel:Refresh(param)
    elseif param.goodsId == ResourceType.GoldProgress then
      self.compProgressPanel:SetActive(true)
      self.compProgressPanel:Refresh(param)
    end
  end
end
local RefreshConditions = function(self, param)
  if self:AsyncLoadDone() then
    self:RefreshConditionsOnDone(param)
  else
    self.cacheRefreshConditionsParam = param
  end
end
local RefreshConditionsOnDone = function(self, param)
  if self.conditions then
    local timeCondition = self.conditions[Const.ParkourWinType.Time]
    if timeCondition then
      self.compTimeConditionPanel:Refresh(param.useTime)
    end
  end
end
local UpdateData = function(self)
  if self.cacheInitParam then
    self:SetDataOnDone(self.cacheInitParam)
    self.cacheInitParam = nil
  end
  if self.cacheRefreshParam then
    self:RefreshOnDone(self.cacheRefreshParam)
    self.cacheRefreshParam = nil
  end
  if self.cacheRefreshConditionsParam then
    self:RefreshConditionsOnDone(self.cacheRefreshConditionsParam)
    self.cacheRefreshConditionsParam = nil
  end
end
ParkourBonusPanel.OnCreate = OnCreate
ParkourBonusPanel.OnDestroy = OnDestroy
ParkourBonusPanel.OnEnable = OnEnable
ParkourBonusPanel.OnDisable = OnDisable
ParkourBonusPanel.ComponentDefine = ComponentDefine
ParkourBonusPanel.ComponentDestroy = ComponentDestroy
ParkourBonusPanel.DataDefine = DataDefine
ParkourBonusPanel.DataDestroy = DataDestroy
ParkourBonusPanel.OnAddListener = OnAddListener
ParkourBonusPanel.OnRemoveListener = OnRemoveListener
ParkourBonusPanel.SetData = SetData
ParkourBonusPanel.SetDataOnDone = SetDataOnDone
ParkourBonusPanel.Refresh = Refresh
ParkourBonusPanel.RefreshOnDone = RefreshOnDone
ParkourBonusPanel.RefreshConditions = RefreshConditions
ParkourBonusPanel.RefreshConditionsOnDone = RefreshConditionsOnDone
ParkourBonusPanel.UpdateData = UpdateData
return ParkourBonusPanel
