local FourteenDayBountyCell = class("FourteenDayBountyCell", BaseCell)

function FourteenDayBountyCell:init()
    local uiMap = self:getUIMap()
    self.imgLevel = uiMap["fourteen_day_bounty_cell.level"]
    self.txLevel = uiMap["fourteen_day_bounty_cell.level.tx_level"]
    self.line = uiMap["fourteen_day_bounty_cell.line"]
    self.bountyRewardCell1 = uiMap["fourteen_day_bounty_cell.bounty_reward_cell_1"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.BOUNTY_REWARD_CELL)
    self.bountyRewardCell2 = uiMap["fourteen_day_bounty_cell.bounty_reward_cell_2"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.BOUNTY_REWARD_CELL)
end

function FourteenDayBountyCell:refresh(id)
    self.txLevel:setText(id)
    self.line:setActive(id < #DataManager.FourteenDayData:getBountyCfg())

    self.bountyRewardCell1:refresh(
        DataManager.FourteenDayData:getBountyGradeReward(id, GConst.FourteenDayConst.BOUNTY_GRADE_TYPE.FREE), false, 
        not DataManager.FourteenDayData:isBountyGradeUnlock(GConst.FourteenDayConst.BOUNTY_GRADE_TYPE.FREE), 
        DataManager.FourteenDayData:isReceivedBountyReward(id, GConst.FourteenDayConst.BOUNTY_GRADE_TYPE.FREE))
	self.bountyRewardCell2:refresh(
        DataManager.FourteenDayData:getBountyGradeReward(id, GConst.FourteenDayConst.BOUNTY_GRADE_TYPE.PAY), true, 
        not DataManager.FourteenDayData:isBountyGradeUnlock(GConst.FourteenDayConst.BOUNTY_GRADE_TYPE.PAY), 
        DataManager.FourteenDayData:isReceivedBountyReward(id, GConst.FourteenDayConst.BOUNTY_GRADE_TYPE.PAY))

	if DataManager.FourteenDayData:getActiveDays() >= id then
		self.imgLevel:setImageGray(false)
		if DataManager.FourteenDayData:canGetBountyReward(id, GConst.FourteenDayConst.BOUNTY_GRADE_TYPE.FREE) then
            self.bountyRewardCell1:showLight()
            self.bountyRewardCell1:addClickListener(function()
                ModuleManager.FourteenDayManager:reqBountyReward(id, GConst.FourteenDayConst.BOUNTY_GRADE_TYPE.FREE)
            end)
		else
			self.bountyRewardCell1:hideLight()
            self.bountyRewardCell1:addClickListener(nil)
		end
		if DataManager.FourteenDayData:canGetBountyReward(id, GConst.FourteenDayConst.BOUNTY_GRADE_TYPE.PAY) then
            self.bountyRewardCell2:showLight()
            self.bountyRewardCell2:addClickListener(function()
                ModuleManager.FourteenDayManager:reqBountyReward(id, GConst.FourteenDayConst.BOUNTY_GRADE_TYPE.PAY)
            end)
		else
			self.bountyRewardCell2:hideLight()
            self.bountyRewardCell2:addClickListener(nil)
		end
	else
		self.imgLevel:setImageGray(true)
		self.bountyRewardCell1:hideLight()
		self.bountyRewardCell2:hideLight()
	end
end

return FourteenDayBountyCell