<?php

namespace Sowmedia\Repo\Frontend;

class AdminNotices {
    private static $instance;

    private $notices;

    function __construct(){
        $this->notices = array();
        $this->add_hooks();
    }

    function add_hooks(){
        add_action("admin_notices", array($this, "render_notices"));
    }

    function add_notice($text, $type = "success"){
        $this->notices[] = array($text, $type);
    }

    function render_notices(){
        foreach($this->notices as $notice){
            printf("<div class='notice notice-%s'><p>%s</p></div>", $notice[1], $notice[0]);
        }
    }

    static function get(){
        if(self::$instance == null)
            self::$instance = new AdminNotices();
        return self::$instance;
    }

    static function setup(){
        // Make sure hooks are added
        self::get();
    }

}
