just read
using System.Collections.Generic;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;

namespace Oxide.Plugins
{
    [Info("QuarryComputerUi", "Marte6", "1.0.11")]
    public class QuarryComputerUi : RustPlugin
    {
        private static readonly string[] UiElements = { "QuarryUi_Background", "QuarryUi_CloseButton" };

        private readonly Dictionary<string, string> colorOptions = new Dictionary<string, string>
        {
            { "Gray", "0.5 0.5 0.5 0.9" },
            { "LightGray", "0.75 0.75 0.75 1" },
            { "DarkGray", "0.25 0.25 0.25 1" },
            { "Red", "1 0 0 1" },
            { "DarkRed", "0.55 0 0 1" }, // Vermelho escuro
            { "FireBrick", "0.7 0.13 0.13 1" }, // Encarnado profundo
            { "Crimson", "0.86 0.08 0.24 1" },
            { "Maroon", "0.5 0 0 1" }, // Marrom avermelhado
            { "Burgundy", "0.5 0 0.13 1" }, // Vinho intenso
            { "DeepPink", "1 0.08 0.58 1" },
            { "Fuchsia", "1 0 1 1" },
            { "Magenta", "1 0 1 1" },
            { "Brown", "0.6 0.3 0 1" },
            { "DarkMagenta", "0.55 0 0.55 1" },
            { "IndianRed", "0.8 0.36 0.36 1" },
            { "RosyBrown", "0.74 0.56 0.56 1" },
            { "MediumVioletRed", "0.78 0.08 0.52 1" },
            { "Purple", "0.5 0 0.5 1" },
            { "Blue", "0 0 1 1" },
            { "Green", "0 1 0 1" },
            { "Yellow", "1 1 0 1" },
            { "Cyan", "0 1 1 1" },
            { "Orange", "1 0.5 0 1" },
            { "Pink", "1 0.75 0.8 1" },
            { "Lime", "0.75 1 0 1" },
            { "Teal", "0 0.5 0.5 1" },
            { "Lavender", "0.9 0.9 0.98 1" },
            { "White", "1 1 1 1" },
            { "Black", "0 0 0 1" },
            { "SkyBlue", "0.53 0.81 0.98 1" },
            { "Ivory", "1 1 0.94 1" },
            { "Goldenrod", "0.85 0.65 0.13 1" },
            { "Coral", "1 0.5 0.31 1" },
            { "Salmon", "0.98 0.5 0.45 1" },
            { "Navy", "0 0 0.5 1" },
            { "Turquoise", "0.25 0.88 0.82 1" },
            { "Chartreuse", "0.5 1 0 1" },
            { "SlateGray", "0.44 0.5 0.56 1" },
            { "ForestGreen", "0.13 0.55 0.13 1" },
            { "Khaki", "0.94 0.9 0.55 1" },
        };

        private void Init() => RemoveUiFromAllPlayers();

        [ChatCommand("ui")]
        private void HandleOpenUiCommand(BasePlayer player)
        {
            RemoveUiFromPlayer(player);
            var container = new CuiElementContainer();

            AddPanel(
                container,
                "0 0",
                "1 1",
                "QuarryUi_Background",
                color: colorOptions["Gray"],
                isBackground: true,
                cursorEnabled: true
            );
            AddPanel(container, "0.235 0.26", "0.4985 0.724", "QuarryUi_Full_Left", parent: "QuarryUi_Background");
            AddPanel(container, "0.4995 0.26", "0.765 0.724", "QuarryUi_Full_Right", parent: "QuarryUi_Background");

            AddInnerSquare(container, "QuarryUi_Full_Left", "0.05 0.05", "0.95 0.95", colorOptions["FireBrick"]);
            AddInnerSquare(container, "QuarryUi_Full_Left", "0.06 0.06", "0.94 0.94", colorOptions["Blue"]);
            AddInnerSquare(container, "QuarryUi_Full_Right", "0.05 0.05", "0.95 0.95", colorOptions["FireBrick"]);
            AddInnerSquare(container, "QuarryUi_Full_Right", "0.06 0.06", "0.94 0.94", colorOptions["Blue"]);
            AddCloseButton(container, "QuarryUi_Full_Right");

            CuiHelper.AddUi(player, container);
            player.SetPlayerFlag(BasePlayer.PlayerFlags.Spectating, true);
        }

        [ConsoleCommand("ui.close")]
        private void HandleCloseUiCommand(ConsoleSystem.Arg args)
        {
            var player = args?.Player();
            if (player != null)
                RemoveUiFromPlayer(player);
        }

        private void RemoveUiFromPlayer(BasePlayer player)
        {
            if (player == null)
                return;
            foreach (var element in UiElements)
                CuiHelper.DestroyUi(player, element);
            player.SetPlayerFlag(BasePlayer.PlayerFlags.Spectating, false);
            player.UpdateActiveItem(default);
        }

        private void RemoveUiFromAllPlayers()
        {
            foreach (var player in BasePlayer.activePlayerList)
                RemoveUiFromPlayer(player);

            foreach (var player in BasePlayer.activePlayerList)
                HandleOpenUiCommand(player);
        }

        private void AddPanel(
            CuiElementContainer container,
            string anchorMin,
            string anchorMax,
            string panelName,
            string parent = "Overlay",
            string color = "0 0 0 1",
            bool isBackground = false,
            bool cursorEnabled = false
        )
        {
            var panel = new CuiPanel
            {
                Image = { Color = color },
                RectTransform = { AnchorMin = anchorMin, AnchorMax = anchorMax },
                CursorEnabled = cursorEnabled,
            };

            if (isBackground)
            {
                panel.Image.Material = "assets/content/ui/uibackgroundblur.mat";
                panel.Image.Sprite = "assets/content/ui/ui.background.transparent.radial.psd";
            }

            container.Add(panel, parent, panelName);
        }

        private void AddInnerSquare(
            CuiElementContainer container,
            string parent,
            string anchorMin,
            string anchorMax,
            string color
        )
        {
            container.Add(
                new CuiPanel
                {
                    Image = { Color = color },
                    RectTransform = { AnchorMin = anchorMin, AnchorMax = anchorMax },
                },
                parent
            );
        }

        private void AddCloseButton(CuiElementContainer container, string parent)
        {
            container.Add(
                new CuiButton
                {
                    Button =
                    {
                        Color = colorOptions["Red"],
                        Command = "ui.close",
                        Close = "QuarryUi_Background",
                    },
                    RectTransform = { AnchorMin = "0.95 0.95", AnchorMax = "1 1" },
                    Text =
                    {
                        Color = "1 1 1 0.5",
                        Font = "robotocondensed-regular.ttf",
                        Text = "✖",
                        FontSize = 13,
                        Align = TextAnchor.MiddleCenter,
                    },
                },
                parent,
                "QuarryUi_CloseButton"
            );
        }
    }
}