<?php

namespace Plainwork\Ui\Component;

use Plainwork\Ui\Html;

final class Badge extends AbstractTag
{
    private $content;

    public function __construct($content = null)
    {
        $this->content = $content;
    }

    public function alert(): self
    {
        $this->content = '!';
        $this->withAttr('style', ['color' => '#fff', 'background-color' => '#c00', 'width' => '1em', 'display' => 'inline-block']);

        return $this;
    }

    public function ok(): self
    {
        $this->content = '&check;';
        $this->withAttr('style', ['color' => '#060', 'background-color' => 'transparent', 'width' => '1em', 'display' => 'inline-block']);

        $this->content = '✓';
        // $this->withAttr('style', ['color' => '#fff', 'background-color' => '#060', 'width' => '1em', 'display' => 'inline-block']);

        return $this;
    }

    public function quest(): self
    {
        $this->content = '?';
        $this->withAttr('style', ['color' => '#fff', 'background-color' => '#f93', 'width' => '1em']);

        return $this;
    }

    public function render()
    {
        $html = new Html();

        $attr = $this->getAttr() ?? [];
        $style = $this->getAttr('style') ?? [];

        $ret = $html->el('i')
            ->withAttr('class', 'pw-badge')
            ->withAttr('style', $style)
            ->append($this->content)
            ;

        foreach ($attr as $k => $v) {
            $ret->withAttr($k, $v);
        }

        return $ret;
    }
}
