1<?php
2
3namespace ComboStrap;
4
5
6
7/**
8 * Implementation of a inline note
9 * called an alert in <a href="https://getbootstrap.com/docs/4.0/components/badge/">bootstrap</a>
10 *
11 * Quickly created with a copy of a badge
12 */
13class NoteTag
14{
15
16
17    public const ATTRIBUTE_ROUNDED = "rounded";
18    public const INOTE_CONF_DEFAULT_ATTRIBUTES_KEY = 'defaultInoteAttributes';
19    public const TAG_INOTE = "inote";
20
21    const KNOWN_TYPES = [
22        \syntax_plugin_combo_note::WARNING_TYPE,
23        \syntax_plugin_combo_note::IMPORTANT_TYPE,
24        \syntax_plugin_combo_note::TIP_TYPE,
25        \syntax_plugin_combo_note::INFO_TYPE,
26    ];
27
28
29    public static function renderEnterInlineNote(TagAttributes $tagAttributes): string
30    {
31        $tagAttributes->addClassName("badge");
32
33        PluginUtility::getSnippetManager()->attachCssInternalStyleSheet(NoteTag::TAG_INOTE);
34
35        $type = $tagAttributes->getValue(TagAttributes::TYPE_KEY);
36
37        // Switch for the color
38        switch ($type) {
39            case "important":
40                $type = "warning";
41                break;
42            case "warning":
43                $type = "danger";
44                break;
45        }
46
47        if ($type != "tip") {
48            $bootstrapVersion = Bootstrap::getBootStrapMajorVersion();
49            if ($bootstrapVersion == Bootstrap::BootStrapFiveMajorVersion) {
50                /**
51                 * We are using
52                 */
53                $tagAttributes->addClassName("alert-" . $type);
54            } else {
55                $tagAttributes->addClassName("badge-" . $type);
56            }
57        } else {
58            if (!$tagAttributes->hasComponentAttribute("background-color")) {
59                $tagAttributes->addStyleDeclarationIfNotSet("background-color", "#fff79f"); // lum - 195
60                $tagAttributes->addClassName("text-dark");
61            }
62        }
63        $rounded = $tagAttributes->getValueAndRemove(NoteTag::ATTRIBUTE_ROUNDED);
64        if (!empty($rounded)) {
65            $tagAttributes->addClassName("badge-pill");
66        }
67
68        return $tagAttributes->toHtmlEnterTag("span");
69    }
70
71    public static function renderClosingInlineNote(): string
72    {
73        return '</span>';
74    }
75
76}
77