local SideBarBaseCellComp = require "app/ui/main_city/cell/side_bar_base_cell"
local SideBarArmorGiftCell = class("SideBarArmorGiftCell", SideBarBaseCellComp)
local GIFT_TYPE = PayManager.PURCHARSE_ACT_TYPE.ARMOR_UPGRADE_GIFT

function SideBarArmorGiftCell:getIsOpen()
    -- return DataManager.ShopData:hasGift(GIFT_TYPE)
    return #DataManager.EquipData:getGiftIdsByType(GIFT_TYPE) > 0
end

function SideBarArmorGiftCell:getSpineName()
    return "ui_main_equipgift"
end

function SideBarArmorGiftCell:getSpineAnimationName()
    return "animation"
end

function SideBarArmorGiftCell:onClick()
    -- local gift = DataManager.ShopData:getGift(GIFT_TYPE)
    -- if gift then
    --     ModuleManager.ShopManager:showGiftPopUI(PayManager.PURCHARSE_TYPE.ACT_GIFT, gift.id, true, BIReport.PAY_UI_SHOW_TYPE.CLICK_SHOW)
    -- end

    local ids = DataManager.EquipData:getGiftIdsByType(GIFT_TYPE)
    if #ids > 0 then
        ModuleManager.ShopManager:showGiftPopUI(PayManager.PURCHARSE_TYPE.ACT_GIFT, ids, true, BIReport.PAY_UI_SHOW_TYPE.CLICK_SHOW)
    end
end

function SideBarArmorGiftCell:getIsShowRedPoint()
    return false
end

function SideBarArmorGiftCell:onRefresh()
    self.timeBg:setVisible(true)
    self:_refreshTime()
end

function SideBarArmorGiftCell:updateTime()
    if self:getIsOpen() then
        self:_refreshTime()
    else
        self:closeBtn()
    end
end

function SideBarArmorGiftCell:_refreshTime()
    -- local gift = DataManager.ShopData:getGift(GIFT_TYPE)
    -- if gift then
    --     local cfgInfo = DataManager.ShopData:getActGiftConfig()[gift.id]
    --     if cfgInfo then
    --         local remainTime = DataManager.ShopData:getGiftRemainTime(GIFT_TYPE)
    --         if remainTime >= 0 then
    --             self.timeTx:setText(GFunc.getTimeStr(remainTime))
    --         else
    --             self.timeTx:setText("00:00:00")
    --         end
    --     else
    --         self.timeTx:setText("00:00:00")
    --     end
    -- else
    --     self.timeTx:setText("00:00:00")
    -- end

    local remainTime = DataManager.EquipData:getGiftNearestRemainTime(GIFT_TYPE)
    if remainTime >= 0 then
        self.timeTx:setText(GFunc.getTimeStr(remainTime))
    else
        self.timeTx:setText("00:00:00")
    end
end

return SideBarArmorGiftCell