var plugin = require('topsin.gengui');

var gui = plugin.newGui();


var r = gui.msgBox("mo", "info", "are you ok?", ["ok", "cancel"]);
console.log(r);

gui.confirm("are you ok?", ["yes", "no"], "question");

var selected = gui.selectFromTreeview({
    title: "test",
    size: [600, 400],
    selectmode: "single",
    columns: [
        {
            "name": "id",
            "display": "ID",
            "displayRole": "$id",
            "search": true,
            "resizeMode": "ResizeToContents"
        },
        {
            "name": "name",
            "display": "NAME",
            "displayRole": "$name",
            "search": true,
            "resizeMode": "ResizeToContents"
        }
    ],
    data: [
        {
            "id": 1,
            "name": "mo"
        },
        {
            "id": 2,
            "name": "ha"
        }
    ],
    returncols: ["id"]
});

console.log(selected);

r = gui.selectFile("choose something", "*", true, "file", "/home/abby/fast_io");
console.log(r);

var elder =[];
for(var i = 0; i < 100; ++i) {
    elder.push({"mo": "+1s"});
}

var xx = [
    {"mo": "too young too simple"},
    {"ha": "sometimes naive!"},
    {"elder": "+1s"}
];
r = gui.selectSingle({
    "title": "select your favar",
    "list": xx,
    "default": "",
    "columns": 2,
    "gen":{}
});
console.log(r);

r = gui.selectMultiple({
    "title": "select your favar",
    "list": xx,
    "defaultvalue": ["mo"],
    "columns": 2,
    "gen": {}
});
console.log(r);

// select_from_layer 
// select_from_job
r = gui.selectFromTable({
    title: "select from table example",
    multiple: true,
    list: [
        {
            "job": "too young",
            "name": "elder"
        },
        {
            "job": "too simple",
            "name": "elder"
        },
        {
            "job": "sometimes",
            "name": "elder"
        },
        {
            "job": "naive",
            "name": "elder"
        }
    ],
    gen: function() { function PAUSE() { return true; }}
});

console.log(r);

gui.snapScreen({
    file: "xxx",
    dir: "/tmp",
    type: "png",
    overwrite: true
});

gui.imageViewer({
    title: "screenshot",
    file: "/tmp/xxx.png",
    defaultsize: [800, 600]
});

r = gui.inputBox({
    title: "input box example",
    value: "are you ok?"
});
console.log(r);

// refer to ikm6 GUI.showForm
r = gui.showForm({
    title: "form example",
    ui: {
        type: 'ScrollArea',
        property: { widget_resizable: true, frame_shape: 'NoFrame', align: 'Top' },
        child: {
            type: 'VBoxLayout',
            property: { margin: 2, spacing: 20, align: 'Top' },
            pack: { stretch: 0 },
            child: [
                {
                    type: 'label'
                },
                {
                    type: 'label',
                    property: { text: ("Partnumber Info") }
                },
                {
                    type: "FormGridLayout",
                    property: { columns: 4, label_alignment: 'Top | Right', margin: 10, spacing: 20 },
                    pack: { stretch: 0 },
                    child: [
                        {
                            name: 'partnumber',
                            type: 'LineEdit',
                            pack: { label: ('Partnumber') },
                            property: { enabled: true }
                        },
                        {
                            name: 'attrs.iscross',
                            type: 'ComboBox',
                            property: { enabled: true, item_list: [] },
                            pack: { label: ('Is Cross') }
                        },
                        {
                            name: 'attrs.pthick',
                            type: 'DoubleLineEdit',
                            pack: { label: ('Part thickness') },
                            property: { enabled: true }
                        },
                        {
                            name: 'attrs.producttype',
                            type: 'ComboBox',
                            property: { enabled: true, item_list: [] },
                            pack: { label: ('Product type') }
                        },
                        {
                            name: 'attrs.weft_direction',
                            type: 'ComboBox',
                            property: { enabled: true, item_list: [] },
                            pack: { label: ('Longitude and latitude') }
                        },
                        {
                            name: 'attrs.structure_code',
                            type: 'LineEdit',
                            pack: { label: ('Structure') },
                            property: { enabled: true }
                        },
                        {
                            name: 'attrs.array_num_on_panel_y',
                            type: 'DoubleLineEdit',
                            pack: { label: ('Long edge typesetting') },
                            property: { enabled: true }
                        },
                        {
                            name: 'attrs.array_num_on_panel_x',
                            type: 'DoubleLineEdit',
                            pack: { label: ('Short edge typesetting') },
                            property: { enabled: true }
                        },
                        {
                            name: 'attrs.pre_partnumber',
                            type: 'Chips',
                            pack: { label: ('Front partnumber'), column_span: 2 },
                            property: { enabled: true }
                        },
                        {
                            name: 'attrs.erp_job_remark',
                            type: 'PlainTextEdit',
                            property: {
                                enabled: true,
                                min_row_count: 1,
                                vertical_scroll_bar_policy: 'ScrollBarAlwaysOff'
                            },
                            pack: { label: ('ERP Job Remark'), column_span: 2 },
                        }
                    ]
                },
                {
                    type: 'stretch'
                }
            ]
        }
    },
    data: {},
    runnow: true,
    includehide: false,
    gen: null
});

console.log(r);

r = gui.selectLayer({
    title: "+1s",
    filter: ".*", // regular expression
    selectmode: "single", // single, multiple
    context: "all", // all, board, misc
    layertype: "inner", // default type of layertypelist
    defaultsize: [600, 400], // window size
    layermatrix: {
        layer1: {
            row: 1,
            name: "layer1",
            layer_type: "inner"
        },
        layer2: {
            row: 2,
            name: "layer2",
            layer_type: "outer"
        }
    },
    layertypelist: [
        {name: "inner", display_name: "Inner", filter: function(x) { return x["layer_type"] === "inner"; }},
        {name: "outer", display_name: "Outer", filter: function(x) { return x["layer_type"] === "outer"; }}
    ],
    gen: null
});
console.log(r);

r = gui.lockUnlockLayer({
    "title": "+1s",
    "layermatrix": {
        "layer1": {
            "row": 1,
            "name": "layer1"
        },
        "layer2": {
            "row": 2,
            "name": "layer2"
        }
    }
});
console.log(r);

r = gui.passwordBox({
    title: "password box",
    password: "naive!"
});
console.log(r);

r = gui.selectJobLayer({
    layertypelist: [
        { name: "mo", display_name: "MO", filter: function (x) { return x.layer_type === "mo"; } },
        { name: "ha", display_name: "HA", filter: function (x) { return x.layer_type === "ha"; } }
    ],
    //defaultlayertype: "ha",
    joblist: ["job1", "job2"],
    defaultJob: ["job1"], // select by default
    steplist: ["step1", "step2", "step3", "step4"],
    // defaultstep: "step3",
    showstep: true,
    selectmode: "single", // single/multiple
    layermatrix: {
        "layer1": {
            name: "layer1",
            layer_type: "mo",
            row: 1
        },
        "layer2": {
            name: "layer2",
            layer_type: "ha",
            row: 2
        }
    },
    defaultlayer: ["layer1"]
});

console.log(r);