<?php

class Message
{
    private $ci;

    public function __construct()
    {
        $this->ci = get_instance();
        $this->ci->load->library('ciext/js_css');
        $this->ci->js_css->add_js('https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js');
        $this->ci->js_css->add_css('https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.min.css');
        $this->ci->js_css->add_js_string('toastr.options={"closeButton": true}');
    }

    public function success($message)
    {
        return $this->add_message('success', $message);
    }

    public function error($message)
    {
        return $this->add_message('error', $message);
    }

    public function info($message)
    {
        return $this->add_message('info', $message);
    }

    public function warning($message)
    {
        return $this->add_message('warning', $message);
    }

    public function add_message($type, $message)
    {
        $this->ci->js_css->add_js_string('toastr.' . $type . '("' . $message . '");');
        return $this;
    }
}