<?php

    class Balloon {

        private $balloonStatus = null;
        private $balloonMessage = null;
        private $balloonRedirect = null;
        private $show = false;

        public function isToShow() {
            return $this->show;
        }

        public function getBalloonStatus() {
            return $this->balloonStatus;
        }

        public function getBalloonMessage() {
            return $this->balloonMessage;
        }

        public function getBalloonRedirect() {
            return $this->balloonRedirect;
        }

        public function setBalloonSuccess($status = true) {
            $this->balloonStatus = $status ? 'success' : 'error';
        }

        public function setBalloonMessage($msg) {
            $this->balloonMessage = $msg;
        }

        public function setBalloonRedirect($path, $delay) {
            $this->balloonRedirect = array($path, $delay);
        }

        public function showBalloon($show = true) {
            $this->show = $show;
        }

        public function newBalloon($status = true, $msg = null, $show = true) {
            if(empty($msg)){
                if($status)
                    $msg = "Operação realizada com sucesso!";
                else
                    $msg = "Houve um erro ao realizar o operação";
            }
            $this->setBalloonSuccess($status);
            $this->setBalloonMessage($msg);
            $this->showBalloon($show);
        }

        public static function draw($class = null) {
            
            if($class){

                if($class->isToShow()){
                    $cssClass = $class->getBalloonStatus();
                    $msg = $class->getBalloonMessage();
                    $redir = $class->getBalloonRedirect();

                    $icon = $cssClass == "success" ? "check" : "times";
                    
                    echo '<div class="alert ' . $cssClass . '"><i class="fa fa-' . $icon . '"></i><span>' . $msg . '</span></div>';

                    if($redir) {
                        echo "<meta http-equiv='refresh' content='{$redir[1]}, url={$redir[0]}'>";
                    }
                }
            }
        }

    }
