define('package/quiqqer/tour/bin/guides/ProjectSettings', [

    'qui/QUI',
    'package/quiqqer/tour/bin/classes/Tour',
    'utils/Panels',
    'Locale'

], function (QUI, Tour, PanelUtils, QUILocale) {
    "use strict";

    var ProjectSettings = new Tour();
    var lg = 'quiqqer/tour';
    var SettingsMenu;
    var MenuEntries;
    var EntryProjectSettings;
    var MainProjectSettingsButton;
    var Panel;
    var panels = QUI.Controls.getByType('controls/projects/project/Settings');

    ProjectSettings.addStep({
        title  : QUILocale.get(lg, 'ProjectSettings.Step1.Title'),
        text   : QUILocale.get(lg, 'ProjectSettings.Step1.Text'),
        buttons: [
            {
                text  : QUILocale.get(lg, 'ProjectSettings.Button.Abbruch'),
                action: function () {
                    ProjectSettings.cancel();
                }
            },
            {
                text  : QUILocale.get(lg, 'ProjectSettings.Button.LosGehts'),
                action: function () {
                    var settingsMenuID = document.getElement('[data-name = "settings"]').getAttribute('data-quiid');
                    SettingsMenu = QUI.Controls.getById(settingsMenuID);
                    MenuEntries = SettingsMenu.getChildren();
                    ProjectSettings.next();
                }
            }
        ]

    });

    ProjectSettings.addStep({
        title        : QUILocale.get(lg, 'ProjectSettings.Step1.Title'),
        text         : QUILocale.get(lg, 'ProjectSettings.Step2.Text'),
        tetherOptions: {
            constraints: null // this disables pinning (which breaks the arrows)
        },
        attachTo     : {
            element: function () {
                return SettingsMenu.getElm();
            },
            on     : 'bottom'
        },
        buttons      : false,
        when         : {
            show: function () {
                var Button = SettingsMenu.getElm();
                Button.addEvent('click', ProjectSettings.next);
            },
            hide: function () {
                var Button = SettingsMenu.getElm();
                Button.removeEvent('click', ProjectSettings.next);
            }
        }
    });

    ProjectSettings.addStep({
        title  : QUILocale.get(lg, 'ProjectSettings.Step1.Title'),
        text   : QUILocale.get(lg, 'ProjectSettings.Step3.Text'),
        buttons: false,
        when   : {
            show: function () {
                MenuEntries.forEach(function (Entry) {
                    if (Entry.options.name === 'projects') {
                        EntryProjectSettings = Entry;
                    }
                });

                var Button = EntryProjectSettings.getElm();
                Button.addEvent('mouseenter', ProjectSettings.next);

            },
            hide: function () {
                var Button = EntryProjectSettings.getElm();
                Button.removeEvent('mouseenter', ProjectSettings.next);
            }
        }
    });

    ProjectSettings.addStep({
        title  : QUILocale.get(lg, 'ProjectSettings.Step1.Title'),
        text   : QUILocale.get(lg, 'ProjectSettings.Step4.Text'),
        when   : {
            show: function () {
                MainProjectSettingsButton = EntryProjectSettings.getChildren()[0];
                MainProjectSettingsButton.addEvent('click', function () {
                    ProjectSettings.next();
                });
            }
        },
        buttons: {
            text  : QUILocale.get(lg, 'ProjectSettings.Button.Weiter'),
            action: function () {
                ProjectSettings.next();
            }
        }
    });

    ProjectSettings.addWaitingStepByType('controls/projects/project/Settings');

    ProjectSettings.execute(function () {
        panels = QUI.Controls.getByType('controls/projects/project/Settings');

        if (panels.length >= 1) {
            Panel = panels[panels.length - 1];
        }
        ProjectSettings.next();
    });


    ProjectSettings.addStep({
        title  : QUILocale.get(lg, 'ProjectSettings.Step1.Title'),
        text   : QUILocale.get(lg, 'ProjectSettings.Step5.Text'),
        buttons: {
            text  : QUILocale.get(lg, 'ProjectSettings.Button.Weiter'),
            action: function () {
                Panel.getCategory()[0].click();
                ProjectSettings.next();
            }
        }
    });

    ProjectSettings.addStep({
        title        : QUILocale.get(lg, 'ProjectSettings.Step1.Title'),
        text         : QUILocale.get(lg, 'ProjectSettings.Step6.Text'),
        attachTo: {
            element: function () {
                return document.getElement('button[name = "settings"]');
            },
            on     : 'right'
        },
        buttons      : {
            text  : QUILocale.get(lg, 'ProjectSettings.Button.Weiter'),
            action: function () {
                Panel.getElm().getElement('button[name = "adminSettings"]').fireEvent('click');
                ProjectSettings.next();
            }
        }

    });

    ProjectSettings.addStep({
        title   : QUILocale.get(lg, 'ProjectSettings.Step1.Title'),
        text    : QUILocale.get(lg, 'ProjectSettings.Step7.Text'),
        attachTo: {
            element: function () {
                return Panel.getElm().getElement('button[name = "adminSettings"]');
            },
            on     : 'right'
        },
        buttons : [{
            text  : QUILocale.get(lg, 'ProjectSettings.Step7.Button.Sitemap'),
            action: function () {
                ProjectSettings.next();
            }
        }, {
            text  : QUILocale.get(lg, 'ProjectSettings.Button.Weiter'),
            action: function () {
                Panel.getElm().getElement('button[name = "mediaSettings"]').fireEvent('click');
                ProjectSettings.skip(1);
            }
        }]

    });

    ProjectSettings.addStep({
        title   : QUILocale.get(lg, 'ProjectSettings.Step1.Title'),
        text    : QUILocale.get(lg, 'ProjectSettings.Step8.Text'),
        attachTo: {
            element: function () {
                var ProjektBar = document.getElements('.project-container');
                var ProjektPanel = QUI.Controls.getById(
                    ProjektBar.getParent('.qui-panel').get('data-quiid')
                );
                ProjektPanel.open();

                return ProjektPanel.getContent();
            },
            on     : 'right'
        },
        buttons : {
            text  : QUILocale.get(lg, 'ProjectSettings.Button.Weiter'),
            action: function () {
                Panel.getElm().getElement('button[name = "mediaSettings"]').fireEvent('click');
                ProjectSettings.next();
            }
        }

    });

    ProjectSettings.addStep({
        title   : QUILocale.get(lg, 'ProjectSettings.Step1.Title'),
        text    : QUILocale.get(lg, 'ProjectSettings.Step9.Text'),
        attachTo: {
            element: function () {
                return Panel.getElm().getElement('button[name = "mediaSettings"]');
            },
            on     : 'right'
        },
        buttons : {
            text  : QUILocale.get(lg, 'ProjectSettings.Button.Weiter'),
            action: function () {
                Panel.getElm().getElement('button[name = "customCSS"]').fireEvent('click');
                ProjectSettings.next();
            }
        }

    });

    ProjectSettings.addStep({
        title   : QUILocale.get(lg, 'ProjectSettings.Step1.Title'),
        text    : QUILocale.get(lg, 'ProjectSettings.Step10.Text'),
        attachTo: {
            element: function () {
                return Panel.getElm().getElement('button[name = "customCSS"]');
            },
            on     : 'right'
        },
        buttons : {
            text  : QUILocale.get(lg, 'ProjectSettings.Button.Weiter'),
            action: function () {
                ProjectSettings.next();
            }
        }

    });

    ProjectSettings.addStep({
        title   : QUILocale.get(lg, 'ProjectSettings.Step1.Title'),
        text    : QUILocale.get(lg, 'ProjectSettings.Step11.Text'),
        attachTo: {
            element: function () {
                return document.getElement('[name="save"]');
            },
            on     : 'right'
        },
        buttons : {
            text  : QUILocale.get(lg, 'ProjectSettings.Button.Weiter'),
            action: function () {
                ProjectSettings.next();
            }
        }
    });

    ProjectSettings.addStep({
        title  : QUILocale.get(lg, 'ProjectSettings.Step1.Title'),
        text   : QUILocale.get(lg, 'ProjectSettings.Step12.Text'),
        buttons: {
            text  : QUILocale.get(lg, 'ProjectSettings.Button.Ende'),
            action: function () {
                ProjectSettings.cancel();
            }
        }
    });


    return ProjectSettings;
});