"use strict";

requirejs('helpers/arrayDataSource');
requirejs('utils');

propertiesTabs.tabMyCustom.load = function (track, dialog) {

    var mainElement = window.qid('tabMyCustomContent');
    var lblMyCustom = qeid(mainElement, 'lblMyCustom');
    if (dialog.isGroup) {
        lblMyCustom.innerText = 'This works for single track only';
    } else {
        dialog.localPromise(app.getObject('album', {
            id: track.idalbum
        })).then(function (album) {
            if (album) {
                dialog.localPromise(album.getTracklist().whenLoaded()).then(function (tracklist) {
                    var total = tracklist.count;
                    lblMyCustom.innerText = 'This track belongs to album (' + album.title + ') including ' + total + ' tracks in total';
                });
            } else {
                lblMyCustom.innerText = 'This track does not belong to any album';
            }
        });
    }
}

propertiesTabs.tabMyCustom.saveAsync = function (track, dialog) {
    // save/modify track properties here
    return dummyPromise();
}

propertiesTabs.tabMyCustom.updateVisibility = function (trackType, dialog) {
    // if you want to adjust controls based on selected trackType ('music', 'video', ...)
    // this function is optional

    var mainElement = window.qid('tabMyCustomContent');
    var lblMyCustom = qeid(mainElement, 'lblMyCustom');

    if (trackType == 'video' || trackType == 'tv') {
        setVisibility(lblMyCustom, false);
    } else {
        setVisibility(lblMyCustom, true);
    }
}