//ScriptUI通过radioButton切换面板组 v1.0 2022-04-20
//Raymond Yan 2022 (RaymondClr@outlook.com / QQ: 1107677019)

var mainWindow = new Window("palette", undefined, undefined, { resizeable: true });
mainWindow.onResizing = function () {
    this.layout.resize();
};

mainWindow.preferredSize = [300, 200];
mainWindow.alignChildren = ["fill", "top"];

var group1 = mainWindow.add("group");
var group2 = mainWindow.add("group");
group1.alignChildren = ["center", "top"];

var radioButton1 = group1.add("radiobutton", undefined, "A");
var radioButton2 = group1.add("radiobutton", undefined, "B");
var radioButton3 = group1.add("radiobutton", undefined, "C");
var radioButton4 = group1.add("radiobutton", undefined, "D");

group2.orientation = "stack";
group2.alignChildren = group2.parent.alignChildren;

var group3 = group2.add("group");
var group4 = group2.add("group");
var group5 = group2.add("group");
var group6 = group2.add("group");
group3.alignChildren = group3.parent.alignChildren;
group4.alignChildren = group4.parent.alignChildren;
group5.alignChildren = group5.parent.alignChildren;
group6.alignChildren = group6.parent.alignChildren;

group3.add("listbox", undefined, ["1", "2", "3", "4"]);

group4.orientation = "column";
group4.add("checkbox", undefined, "enabled");
group4.add("checkbox", undefined, "enabled");
group4.add("checkbox", undefined, "enabled");
group4.add("button", undefined, "Click1");

group5.add("button", undefined, "Click2");

group6.add("button", undefined, "Click3");

mainWindow.show();

function handleEvent() {
    group3.visible = radioButton1.value;
    group4.visible = radioButton2.value;
    group5.visible = radioButton3.value;
    group6.visible = radioButton4.value;
}

(function initGroupState() {
    radioButton1.value = true;
    handleEvent();
})();

radioButton4.onClick = radioButton3.onClick = radioButton2.onClick = radioButton1.onClick = handleEvent;