/**
* This source file is available under the terms of the
* Pimcore Open Core License (POCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
*  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.com)
*  @license    Pimcore Open Core License (POCL)
*/

pimcore.registerNS("pimcore.asset.metadata.editor");
/**
 * @private
 */
pimcore.asset.metadata.editor = Class.create({

    initialize: function(asset) {
        this.asset = asset;

        var dataProvider = new pimcore.asset.metadata.dataProvider();

        var eventData = {
            dataProvider: dataProvider,
            asset: asset,
            instance: null
        };

        // hook for providing a custom implementation of the asset metadata tab
        // e.g. https://github.com/pimcore/asset-metadata-class-definitions

        const preCreateAssetMetadataEditor = new CustomEvent(pimcore.events.preCreateAssetMetadataEditor, {
            detail: {
                editor: this,
                eventParams: eventData
            }
        });

        document.dispatchEvent(preCreateAssetMetadataEditor);

        this.editorInstance = eventData.instance;

        if (!this.editorInstance) {
            // if no panel has been defined by event handler then use the standard grid
            this.editorInstance = new pimcore.asset.metadata.grid({
                asset: this.asset,
                dataProvider: eventData.dataProvider
            });
        }
    },

    getLayout: function() {
        return this.editorInstance.getLayout();
    },

    getValues: function() {
        var values = this.editorInstance.getValues();
        return values;
    }
});