
const Gtk = imports.gi.Gtk;

const Gettext = imports.gettext.domain('gnome-shell-extensions');
const _ = Gettext.gettext;
const N_ = function(e) { return e; };

let settings;

const SETTINGS_SCHEMA = 'org.gnome.shell.extensions.alternate-tab';
const SETTINGS_BEHAVIOUR_KEY = 'behaviour';
const SETTINGS_FIRST_TIME_KEY = 'first-time';

function init(metadata) {
    let convenience = metadata.importer.convenience;
    convenience.initTranslations(metadata);
    settings = convenience.getSettings(metadata, 'alternate-tab');
}

function setBehaviour(behaviour) {
    settings.set_string(SETTINGS_BEHAVIOUR_KEY, behaviour);
    settings.set_boolean(SETTINGS_FIRST_TIME_KEY, false);
}

function buildPrefsWidget() {
    let frame = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL,
                              border_width: 10 });
    let label = new Gtk.Label({ label: "<b>Mode</b>",
                                use_markup: true,
                                xalign: 0 });

    let vbox = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL,
                             margin_left: 20 });

    let allThumbnails = new Gtk.RadioButton({ label: _("All & Thumbnails") });
    let workspaceIcons = new Gtk.RadioButton({ label: _("Workspace & Icons"),
                                               group: allThumbnails });

    let behaviour = settings.get_string(SETTINGS_BEHAVIOUR_KEY);

    if (behaviour == 'all_thumbnails')
        allThumbnails.set_active(true);
    else if (behaviour == 'workspace_icons')
        workspaceIcons.set_active(true);

    allThumbnails.connect('toggled', function(button) {
        if (button.get_active())
            setBehaviour('all_thumbnails');
    });
    workspaceIcons.connect('toggled', function(button) {
        if (button.get_active())
            setBehaviour('workspace_icons');
    });

    vbox.add(allThumbnails);
    vbox.add(workspaceIcons);

    frame.add(label);
    frame.add(vbox);
    frame.show_all();
    return frame;
}
