{{!
    This file is part of Moodle - https://moodle.org/

    Moodle is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Moodle is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
}}
{{!
    @template file/tiny/plugin_js

    AMD amd/src/plugin.js file.

    Context variables required for this template:
    * component
    * copyright

    Example context (json):
    {
        "component": "tiny_example",
        "copyright": "2022 Andrew Lyons <andrew@nicols.co.uk>"
    }
}}
{{< common/boilerplate_amd_js }}
    {{$ description }}Tiny {{ component }} for Moodle.{{/ description }}
    {{$ modulename }}plugin{{/ modulename }}
    {{$ copyright }}{{ copyright }}{{/ copyright }}
{{/ common/boilerplate_amd_js  }}

import {
{{# self.commandnames }}
    {{ commandName }},
{{/ self.commandnames }}
} from './common';

import {
{{# self.defines_buttons }}
    addMenubarItem,
{{/ self.defines_buttons }}
{{# self.defines_menuitems }}
    addToolbarButtons,
{{/ self.defines_menuitems }}
} from 'editor_tiny/utils';

{{# self.defines_buttons }}
const getToolbarConfiguration = (instanceConfig) => {
    let toolbar = instanceConfig.toolbar;
{{# self.buttonsbycategory }}
    toolbar = addToolbarButtons(toolbar, '{{ category }}', [
{{# buttons }}
        {{ . }},
{{/ buttons }}
    ]);
{{/ self.buttonsbycategory }}

    return toolbar;
};
{{/ self.defines_buttons }}

{{# self.defines_menuitems }}
const getMenuConfiguration = (instanceConfig) => {
    let menu = instanceConfig.menu;
{{# self.menuitemsbycategory }}
    menu = addMenubarItem(menu, '{{ category }}', [
{{# menuitems }}
        {{ . }},
{{/ menuitems }}
    ].join(' '));
{{/ self.menuitemsbycategory }}

    return menu;
};
{{/ self.defines_menuitems }}

export const configure = (instanceConfig) => {
    return {
{{# self.defines_buttons }}
        toolbar: getToolbarConfiguration(instanceConfig),
{{/ self.defines_buttons }}
{{# self.defines_menuitems }}
        menu: getMenuConfiguration(instanceConfig),
{{/ self.defines_menuitems }}
    };
};
