local this = class("cellReplaceSpirit", G_UIModuleBase)

function this.bind()
  return {
    go_btn_remove = false,
    go_item = true,
    cellIcon_item = L_Const.ModuleInfo.CellIconBag,
    selectActive = false,
    itemSelectNum = 1
  }
end

function this.methods()
  return {
    onClick_remove = function(self)
      self:emit("onClick_remove", self.bind)
    end,
    onPointEnter_item = function(self)
      self:emit("onPointEnter_item", self.bind)
    end,
    onPointExit_item = function(self)
      self:emit("onPointExit_item", self.bind)
    end,
    onLongClick = function(self)
      self:emit("onLongClick", self.bind)
    end,
    onClick_reduce = function(self)
      self:emit("onClick_reduce", self.bind)
    end
  }
end

function this:open()
  this.super.open(self)
  self:initCell()
end

function this:getGuid()
  return self.bind.guid
end

function this:setSelected(active)
  self.bind.selectActive = active
  if not active then
    self.bind.itemSelectNum = 1
  end
end

function this:initCell()
  if not self.isBind then
    return
  end
  self:refreshView()
  self:setActveState(self.bind.active)
end

function this:setActveState(active)
  self.bind.active = active
  if not self.isBind then
    return
  end
  if self.bind.go_item then
    self.modules.cellIcon_item:setActive(self.bind.active)
  end
end

function this:refreshView()
  if not self.isBind then
    return
  end
  if self.bind.go_item then
    if self.bind.itemType == L_Const.resType.commonItem then
      self.modules.cellIcon_item:setGeneralContent(self.bind.itemType, self.bind.itemId, {
        itemNum = self.bind.itemNum,
        noTip = true,
        callback = function()
          self:emit("onClick_item", self.bind)
        end
      })
    end
    if self.bind.itemType == L_Const.resType.spiritron then
      self.modules.cellIcon_item:setDataContent(L_Const.resType.spiritron, self.bind.guid, nil, {
        noTip = true,
        callback = function()
          self:emit("onClick_item", self.bind)
        end
      })
    end
  end
end

return this
