local this = class("moduleTaskTip", G_UIModuleBase)

function this:bind()
  return {
    imgTaskType = "",
    imgTaskTypeBg = "",
    txtTaskName = "",
    txtTaskState = ""
  }
end

function this:methods()
end

function this:open(options)
  self.super.open(self, options)
  if not options then
    return
  end
  self.gameObject:SetActive(true)
  self.options = options
  if options.taskId then
    self.taskId = options.taskId
  end
  if options.isOver then
    self.isOver = true
    L_AudioUtil.playSound("Play_SFX_System_HUD_Mission_Complete")
  else
    self.isOver = false
    L_AudioUtil.playSound("Play_SFX_System_HUD_Mission_NewMission")
  end
  self:initPage()
  self:playAnimation(self.isOver and "anim_maincity_tasktip_complete" or "anim_maincity_tasktip_begin")
end

function this:close()
  self.gameObject:SetActive(false)
  if self.timer ~= nil then
    self.timer:stop()
    self.timer = nil
  end
  if self.closeCB then
    self.closeCB(self.options)
  end
end

function this:setCloseCB(closeCB)
  self.closeCB = closeCB
end

function this:initPage()
  local taskTpl = L_GameTpl:getTaskTpl()
  local taskData = taskTpl:getTplById(self.taskId)
  local autoClose = L_GameConstTpl:getValue("TASK_PAGE_AUTO_CLOSE_TIME", true, 2)
  if taskData == nil then
    self:close()
    return
  end
  local icon = taskTpl:getTypeImageIcon(taskData)
  self.bind.imgTaskType = icon
  self.bind.imgTaskTypeBg = icon
  self.bind.txtTaskName = taskTpl:getName(taskData)
  self.bind.txtTaskState = L_WordsTpl:getValue(self.isOver and "ui_task_main_finish" or "ui_task_main_start")
  if self.timer ~= nil then
    self.timer:stop()
  end
  self.timer = Timer.once(autoClose, self.doCloseAnim, self)
end

function this:doCloseAnim()
  self:playAnimation("anim_maincity_tasktip_out")
  self.timer = Timer.once(0.433, self.close, self)
end

return this
