local this = class("cellReplaceAccessory", G_UIModuleBase)

function this.bind()
  return {
    go_btn_remove = false,
    go_item = true,
    cellIcon_item = L_Const.ModuleInfo.CellIconBag,
    go_multiSelect = false,
    txt_selectNum = nil,
    alpha = 1
  }
end

function this.methods()
  return {
    onClick_remove = function(self)
      self:emit("onClick_remove", 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:initCell()
  if not self.isBind then
    return
  end
  self:refreshView()
  self:setSingleSelect(self.bind.selected == true)
  self:setMulSelect(self.bind.selectNum)
end

function this:getIsSingleSelect()
  return self.bind.selected
end

function this:getIsMulSelect()
  return self.bind.go_multiSelect
end

function this:setMulSelect(num)
  local active = not math.isEmpty(num)
  self.bind.go_multiSelect = active
  if active then
    self.bind.txt_selectNum = tostring(num)
  end
end

function this:setSingleSelect(active)
  self.bind.selected = active
  if not self.isBind then
    return
  end
  if self.bind.go_item then
    self.modules.cellIcon_item:setSel(self.bind.selected)
  end
end

function this:refreshView()
  if not self.isBind then
    return
  end
  if self.bind.go_item then
    self.modules.cellIcon_item:setDataContent(L_Const.resType.accessory, self.bind.guid, nil, {
      callback = function()
        self:emit("onClick_item", self.bind)
      end,
      longPressCallback = function()
        self:emit("onLongClick", self.bind)
      end
    })
  end
end

function this:playCellOutVFX()
  self.bind.alpha = 0
  L_TimerManager:stopTimer(self, "delayCallback")
end

function this:playCellInVFX(callback)
  self.bind.alpha = 1
  if not self.isBind then
    L_TimerManager:stopTimer(self, "delayCallback")
    if callback then
      callback()
    end
    return
  end
  self.bindComponents.cellAni:Stop()
  self.bindComponents.cellAni:Play("anim_bag_module_cell_in")
  L_TimerManager:newOrResetTimer(self, "delayCallback", callback, 0.1)
end

return this
