// =============================================
// oc_emergency_unleash.lsl
// Emergency Unleash - Nur für den Wearer
// Einfache Version für OpenCollar 8.4
// =============================================

string g_sSubMenu = "Emergency";
string g_sParentMenu = "Apps";

integer CMD_ZERO = 0;
integer CMD_WEARER = 503;
integer NOTIFY = 1002;

integer MENUNAME_REQUEST = 3000;
integer MENUNAME_RESPONSE = 3001;
integer DIALOG = -9000;
integer DIALOG_RESPONSE = -9001;

string UPMENU = "BACK";

key g_kWearer;

default
{
    state_entry()
    {
        g_kWearer = llGetOwner();
        llOwnerSay("Emergency Unleash Addon geladen.");
    }

    link_message(integer sender, integer num, string str, key id)
    {
        // Menü unter Apps registrieren
        if (num == MENUNAME_REQUEST && str == g_sParentMenu)
        {
            llMessageLinked(LINK_SET, MENUNAME_RESPONSE, g_sParentMenu + "|" + g_sSubMenu, "");
        }

        // Button-Klicks verarbeiten
        else if (num == DIALOG_RESPONSE)
        {
            list lParams = llParseString2List(str, ["|"], []);
            string sButton = llList2String(lParams, 1);
            key kAv = llList2Key(lParams, 0);

            if (kAv != g_kWearer) return;

            // DEBUG - zeigt im Chat was geklickt wurde
            llOwnerSay("DEBUG: Button geklickt → " + sButton);

            if (sButton == g_sSubMenu) // "Emergency" wurde geklickt
            {
                // Submenü mit Unleash-Button öffnen
                llMessageLinked(LINK_SET, DIALOG,
                    (string)kAv + "|⚠ Emergency Unleash|0|Unleash`" + UPMENU + "| |" + (string)CMD_WEARER,
                    "EmergencyMenu");
            }
            else if (sButton == "Unleash")
            {
                llMessageLinked(LINK_SET, CMD_ZERO, "unleash", kAv);
                llMessageLinked(LINK_SET, NOTIFY, "0⚠ Emergency Unleash ausgelöst!", kAv);
            }
            else if (sButton == UPMENU)
            {
                llMessageLinked(LINK_SET, CMD_WEARER, "menu Apps", kAv);
            }
        }
    }
}