-- Paste into a separate Script, compile, and enable it.
-- This single Script creates two independent windows with temporary logs.
local channels = ui.window("channels")
local tells = ui.window("tells")

local function logTree(kind)
  return { type = "column", id = "root", style = { gap = 8 }, children = {
    { type = "log", id = "messages", style = { height = 130, grow = 1 } },
    { type = "row", id = "controls", style = { gap = 6 }, children = {
      { type = "button", id = "sample", text = "Add sample", action = "sample", actionValue = kind },
      { type = "button", id = "clear", text = "Clear", action = "clear" },
    } },
  } }
end

function onLoad()
  channels:create({ title = "Demo channels", x = 24, y = 400, width = 380, height = 240 })
  channels:render(logTree("channel"))
  tells:create({ title = "Demo tells", x = 430, y = 400, width = 320, height = 240 })
  tells:render(logTree("tell"))
  DemoChannelLine("[demo-channel] Aster: Ready when you are.")
  DemoTellLine("Aster tells you: These are sample messages.")
end

-- Call these from Lua triggers or aliases; do not create the windows there.
function DemoChannelLine(text)
  channels:append("messages", tostring(text or ""))
end

function DemoTellLine(text)
  tells:append("messages", tostring(text or ""))
end

function onUI(event)
  if event.action == "clear" then
    if event.window == "channels" then channels:clear("messages") end
    if event.window == "tells" then tells:clear("messages") end
  elseif event.action == "sample" then
    if event.value == "channel" then
      DemoChannelLine("[demo-channel] Birch: Another sample channel line.")
    elseif event.value == "tell" then
      DemoTellLine("Birch tells you: Another sample private line.")
    end
  end
end
