local ActScoreTaskCellV1 = class("ActScoreTaskCellV1", BaseCell)
local REWARD_CELL_COUNT = 3

function ActScoreTaskCellV1:init()
	local uiMap = self:getUIMap()
	self.descTx = uiMap["task_cell.bg.desc_tx"]
	self.slider = uiMap["task_cell.bg.slider_bg.slider"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER)
	self.sliderTx = uiMap["task_cell.bg.slider_bg.slider_tx"]
	self.rewardLayout = uiMap["task_cell.bg.rewards"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_HORIZONTAL_OR_VERTICAL_LAYOUT)
	self.rewardList = {}
	for i = 1, REWARD_CELL_COUNT do
		table.insert(self.rewardList, CellManager:addCellComp(uiMap["task_cell.bg.rewards.reward_cell_" .. i], GConst.TYPEOF_LUA_CLASS.REWARD_CELL))
	end
end

function ActScoreTaskCellV1:refresh(actId, actTaskId)
	local num = DataManager.ActTaskData:getTaskNumScore(actId, actTaskId)
	local type = DataManager.ActTaskData:getTaskType(actTaskId)
	local limit = DataManager.ActTaskData:getTaskTarget(actTaskId)
	local rewards = DataManager.ActTaskData:getTaskReward(actTaskId)
	local hasGot = DataManager.ActTaskData:getHasGotTaskRewardScore(actId, actTaskId)
	local canGet = num >= limit and not hasGot
	num = math.min(num, limit)

	self.descTx:setText(GFunc.getTaskDesc(type, limit))
	self.slider.value = num / limit
	self.sliderTx:setText(num .. "/" .. limit)
	for i = 1, REWARD_CELL_COUNT do
		local reward = rewards and rewards[i]
		if reward then
			self.rewardList[i].baseObject:setActive(true)
			self.rewardList[i]:refreshByConfig(reward, hasGot, hasGot)
			if canGet then
				self.rewardList[i]:showFrameAnimation()
				self.rewardList[i]:addClickListener(function()
					ModuleManager.ActSprintManager:reqStandardTask(actId, 0)
				end)
			else
				self.rewardList[i]:hideFrameAnimation()
			end
		else
			self.rewardList[i].baseObject:setActive(false)
		end
	end
	self.rewardLayout:RefreshLayout()
end

return ActScoreTaskCellV1