local SideBarBaseCellComp = require "app/ui/main_city/cell/side_bar_base_cell"
local SideBarGrowUpGiftCell = class("SideBarGrowUpGiftCell", SideBarBaseCellComp)

function SideBarGrowUpGiftCell:getIsOpen()
    return DataManager.ShopData:hasGrowUpGift()
end

function SideBarGrowUpGiftCell:getSpineName()
    return "ui_main_btn_gift_grow"
end

function SideBarGrowUpGiftCell:onClick()
    local gift = DataManager.ShopData:getGrowUpGift()
    if gift then
        ModuleManager.ShopManager:showGiftPopUI(PayManager.PURCHARSE_TYPE.GROW_UP_GIFT_NEW, gift.current_grow_up_id, true, BIReport.PAY_UI_SHOW_TYPE.CLICK_SHOW)
    end
end

function SideBarGrowUpGiftCell:getIsShowRedPoint()
    return false
end

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

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

function SideBarGrowUpGiftCell:_refreshTime()
    local gift = DataManager.ShopData:getGrowUpGift()
    if gift then
        local cfgInfo = DataManager.ShopData:getActGrowUpGiftConfig()[gift.current_grow_up_id]
        if cfgInfo then
            local remainTime = DataManager.ShopData:getGrowUpGiftRemainTime()
            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
end

return SideBarGrowUpGiftCell