local DailyTaskCell = class("DailyTaskCell", BaseCell)

function DailyTaskCell:init()
	local uiMap = self.baseObject:genAllChildren()
	self.icon = uiMap["task_cell.icon"]
	self.nameTx = uiMap["task_cell.name_tx"]
	self.progressBg = uiMap["task_cell.progress_bg"]
	self.progress = uiMap["task_cell.progress_bg.progress"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER)
	self.progressTx = uiMap["task_cell.progress_bg.progress_tx"]
	self.pointTx = uiMap["task_cell.point_tx"]
	self.getBtn = uiMap["task_cell.get_btn"]
	self.getBtnTx = uiMap["task_cell.get_btn.text"]
	self.getBtn:addClickListener(function()
		if DataManager.DailyTaskData:canClaimTask(self.taskId) then
            ModuleManager.TaskManager:claimDailyTask(self.taskId)
        else
            ModuleManager.TaskManager:taskGoto(self.taskType)
        end
	end)
end

function DailyTaskCell:refresh(taskId)
	self.taskId = taskId
	self.taskType = DataManager.DailyTaskData:getTaskType(self.taskId)
	-- local icon = DataManager.DailyTaskData:getDailyTaskIcon(task.id)
	-- self.icon:setSprite(GConst.ATLAS_PATH.ICON_TASK, icon)

	local taskTarget = DataManager.DailyTaskData:getTaskTarget(self.taskId)
	local taskProg = DataManager.DailyTaskData:getTaskProg(self.taskId)
	taskProg = taskProg > taskTarget and taskTarget or taskProg

	self.pointTx:setText(DataManager.DailyTaskData:getTaskPoint(self.taskId))
	self.progress.value = taskProg / taskTarget
	self.progressTx:setText(taskProg.."/"..taskTarget)

	if DataManager.DailyTaskData:isTaskReceived(self.taskId) then
		-- 已完成
		-- self.mask:setActive(true)
		self.getBtn:setTouchEnable(false)
		self.getBtnTx:setText(I18N:getGlobalText(I18N.GlobalConst.BTN_DONE))
		self.getBtn:setSprite(GConst.ATLAS_PATH.COMMON, "common_btn_grey_1")
		-- self.nameTx:setText("<color=#574A40>" .. GFunc.getTaskDesc(self.taskType, taskTarget) .. "</color>")
		self.nameTx:setText(GFunc.getTaskDesc(self.taskType, taskTarget))
		self.baseObject:setSprite(GConst.ATLAS_PATH.UI_TASK, "task_bg_3")
	else
		-- 未完成 or 可领取
		-- self.mask:setActive(false)
		self.getBtn:setTouchEnable(true)
		-- self.nameTx:setText("<color=#5C3A2D>" .. GFunc.getTaskDesc(self.taskType, taskTarget) .. "</color>")
		self.nameTx:setText(GFunc.getTaskDesc(self.taskType, taskTarget))

		if DataManager.DailyTaskData:isTaskFinished(self.taskId) then
			self.getBtnTx:setText(I18N:getGlobalText(I18N.GlobalConst.BTN_CLAIM))
			self.getBtn:setSprite(GConst.ATLAS_PATH.COMMON, "common_btn_blue_1")
		else
			self.getBtnTx:setText(I18N:getGlobalText(I18N.GlobalConst.EQUIP_DESC_21))
			self.getBtn:setSprite(GConst.ATLAS_PATH.COMMON, "common_btn_yellow_1")
		end
		self.baseObject:setSprite(GConst.ATLAS_PATH.UI_TASK, "task_bg_2")
	end
end

return DailyTaskCell