local this = class("modulePetGameplayStatus", G_UIModuleBase)
local _homeLaborCapacityTpl = L_GameTpl:getHomeLaborCapacityTpl()
local petTpl = L_GameTpl:getPetTpl()
local Color = {
  [L_Const.PetState.PET_WORKING] = C_Color(0.7764706, 0.4196078, 0.4627451, 1),
  [L_Const.PetState.PET_RESTING] = C_Color(0.7764706, 0.4196078, 0.4627451, 1),
  [L_Const.PetState.PET_HUB] = C_Color(0.2, 0.6862745, 0.5764706, 1),
  [L_Const.PetState.PET_ROULETTE] = C_Color(0.4352941, 0.4470588, 0.682353, 1),
  [L_Const.PetState.PET_HERO] = C_Color(0.3294117, 0.6705882, 0.6039215, 1),
  Place = C_Color(0.2, 0.6862745, 0.5764706, 1),
  Special = C_Color(0.9529411, 0.5686275, 0.1176471, 1),
  curWork = C_Color(0.2, 0.6862745, 0.5764706, 1),
  curPlace = C_Color(0.2, 0.6862745, 0.5764706, 1),
  curMount = C_Color(0.2, 0.6862745, 0.5764706, 1),
  inCanteen = C_Color(0.7764706, 0.4196078, 0.4627451, 1)
}
local Name = {
  [L_Const.PetState.PET_WORKING] = L_WordsTpl:getValue("notice_qibo_mutex_working"),
  [L_Const.PetState.PET_RESTING] = L_WordsTpl:getValue("notice_qibo_mutex_rest"),
  [L_Const.PetState.PET_HUB] = L_WordsTpl:getValue("ui_cellFastProductQueue_02"),
  [L_Const.PetState.PET_ROULETTE] = L_WordsTpl:getValue("notice_qibo_mutex_mount"),
  [L_Const.PetState.PET_HERO] = L_WordsTpl:getValue("notice_qibo_mutex_hero"),
  Place = L_WordsTpl:getValue("notice_qibo_mutex_ranch"),
  Special = L_WordsTpl:getValue("notice_qibo_mutex_special"),
  curWork = L_WordsTpl:getValue("notice_qibo_current_rest"),
  curPlace = L_WordsTpl:getValue("notice_qibo_current_ranch"),
  curMount = L_WordsTpl:getValue("notice_qibo_current_mount"),
  inCanteen = L_WordsTpl:getValue("notice_qibo_mutex_rest")
}
local Name_e = {
  [L_Const.PetState.PET_WORKING] = "WORKING",
  [L_Const.PetState.PET_RESTING] = "RESTING",
  [L_Const.PetState.PET_HUB] = "IDLE",
  [L_Const.PetState.PET_ROULETTE] = "RIDING",
  [L_Const.PetState.PET_HERO] = "HERO",
  Place = "PLACING",
  Special = "SPECIAL",
  curWork = "CUR WORKING",
  curPlace = "CUR PLACE",
  curMount = "CUR RIDING",
  InCanteen = "CANTEEN"
}
local Icon = {
  [L_Const.PetState.PET_ROULETTE] = "UI/Atlas/PetBox/tex_pet_icon_ing_ride.png",
  [L_Const.PetState.PET_HERO] = "UI/Atlas/PetBox/tex_objectreturn_icon_xd_temp.png",
  Special = "UI/Atlas/PetBox/tex_objectreturn_icon_qb_temp.png",
  curMount = "UI/Atlas/PetBox/tex_pet_icon_ing_ride.png",
  InCanteen = "UI/Atlas/HomeLaborItem/tex_icon_homesift_shitang1.png"
}

function this.bind()
  return {
    go_content = false,
    txt_name = nil,
    txt_name_e = nil,
    img_icon = nil,
    color_bg = nil
  }
end

function this.methods()
  return {}
end

function this:setData(guid, isPetPlaceRanch)
  local pet = L_PetStore:getPetItem(guid)
  local gameplayStatus = pet:getGameplayStatus()
  local needShow = gameplayStatus ~= L_Const.PetState.PET_NORMAL and gameplayStatus ~= L_Const.PetState.PET_HERO
  self.bind.go_content = needShow
  if needShow then
    if isPetPlaceRanch then
      self.bind.txt_name = Name.Place
      self.bind.txt_name_e = Name_e.Place
      self.bind.color_bg = Color.Place
    else
      self.bind.txt_name = Name[gameplayStatus]
      self.bind.txt_name_e = Name_e[gameplayStatus]
      self.bind.color_bg = Color[gameplayStatus]
    end
    if gameplayStatus == L_Const.PetState.PET_RESTING or gameplayStatus == L_Const.PetState.PET_WORKING or gameplayStatus == L_Const.PetState.PET_HUB then
      if pet:isInCanteen() then
        self.bind.img_icon = Icon.InCanteen
      elseif gameplayStatus == L_Const.PetState.PET_HUB then
        self.bind.img_icon = ""
      elseif gameplayStatus == L_Const.PetState.PET_RESTING or gameplayStatus == L_Const.PetState.PET_WORKING then
        local tpl_capacity = _homeLaborCapacityTpl:getTplById(pet.capacity_id)
        if tpl_capacity then
          local icon = _homeLaborCapacityTpl:getIconLight(tpl_capacity)
          self.bind.img_icon = icon
        else
          errorf("\229\174\160\231\137\169\229\183\165\228\189\156\231\138\182\230\128\129\233\148\153\232\175\175" .. pet.guid .. " \229\183\165\228\189\156\231\138\182\230\128\129" .. pet.work_status .. " \229\183\165\228\189\156\229\187\186\231\173\145" .. pet.work_build)
        end
      end
    else
      self.bind.img_icon = Icon[gameplayStatus]
    end
    L_GameUtil.forceRebuildLayout(self.bindComponents.rect_modulePetGameplayStatus)
  end
end

function this:setPetReleaseData(guid)
  local gameplayStatus = L_Const.PetState.PET_NORMAL
  local pet = L_PetStore:getPetItem(guid)
  if pet then
    local tpl = petTpl:getTplById(pet.id)
    if not petTpl:getIsRename(tpl) then
      gameplayStatus = "Special"
    else
      gameplayStatus = pet:getGameplayStatus()
    end
  end
  local needShow = gameplayStatus ~= L_Const.PetState.PET_NORMAL
  self.bind.go_content = needShow
  if needShow then
    self.bind.txt_name = Name[gameplayStatus]
    self.bind.txt_name_e = Name_e[gameplayStatus]
    self.bind.color_bg = Color[gameplayStatus]
    if gameplayStatus == L_Const.PetState.PET_RESTING or gameplayStatus == L_Const.PetState.PET_WORKING or gameplayStatus == L_Const.PetState.PET_HUB then
      if pet:isInCanteen() then
        self.bind.img_icon = Icon.InCanteen
      else
        local tpl_capacity = _homeLaborCapacityTpl:getTplById(pet.capacity_id)
        if tpl_capacity then
          local icon = _homeLaborCapacityTpl:getIconLight(tpl_capacity)
          self.bind.img_icon = icon
        else
          errorf("\229\174\160\231\137\169\229\183\165\228\189\156\231\138\182\230\128\129\233\148\153\232\175\175" .. pet.guid .. " \229\183\165\228\189\156\231\138\182\230\128\129" .. pet.work_status .. " \229\183\165\228\189\156\229\187\186\231\173\145" .. pet.work_build)
        end
      end
    else
      self.bind.img_icon = Icon[gameplayStatus]
    end
    L_GameUtil.forceRebuildLayout(self.bindComponents.rect_modulePetGameplayStatus)
  end
end

function this:setContentShow(show)
  self.bind.go_content = show
end

function this:setCurSelectForPlace()
  self.bind.txt_name = Name.curPlace
  self.bind.txt_name_e = Name_e.curPlace
  self.bind.color_bg = Color.curPlace
end

function this:setCurSelectForWorking(isPetPlaceRanch)
  if isPetPlaceRanch then
    self.bind.txt_name = Name.curPlace
    self.bind.txt_name_e = Name_e.curPlace
    self.bind.color_bg = Color.curPlace
  else
    self.bind.txt_name = Name.curWork
    self.bind.txt_name_e = Name_e.curWork
    self.bind.color_bg = Color.curWork
  end
end

function this:setCurSelectForMount()
  self.bind.txt_name = Name.curMount
  self.bind.txt_name_e = Name_e.curMount
  self.bind.color_bg = Color.curMount
  self.bind.img_icon = Icon.curMount
end

return this
