/// class PD.Web.UI.Controls.ContextMenuItemTemplate

PD.Web.UI.Controls.ContextMenuItemTemplate = Class.extend({

    apply: function (e) {

        var frame = [""];

        if (e.separator) {

            frame = [
                "<div style='height:1px;border-width:0;border-top:1px solid #CCCCCC;margin-width:0 0 0 30px;position:absolute;top:0;left:36px;right:0;'>&nbsp;</div>"
            ];

        }
        else {

            let icon = this.getIcon(e.imageUrl);

            frame = [
                "<span data-id='" + e.id + "' class='-pd-menu-item'>",
                    "<span class='-pd-menu-icon'>",
                        icon,
                    "</span>",
                    "<span class='-pd-menu-text'>",
                        e.text,
                    "</span>",
                "</span>"
            ];

        }

        return frame.join("");

    },

    getIcon: function (imageUrl) {

        if (imageUrl == null) return "";

        imageUrl = imageUrl.toLowerCase();
        
        if (!this.isFontIcon(imageUrl)) {
            return `<img src="${imageUrl}">`;
        }

        return this.getFontIcon(imageUrl);

    },

    getFontIcon: function (imageUrl) {
        
        let name = Jade.Path.getFileNameWithoutExtension(imageUrl);
        let size = Jade.Path.getFileExtension(name).replace(".", "");

        if (!Jade.String.isNullOrWhiteSpace(size)) {
            name = Jade.Path.getFileNameWithoutExtension(name);
            size = size;
        }
        else {
            size = "12px";
        }

        return `<i class="icofont-${name}" style="font-size:${size};"></i>`;

    },

    isFontIcon: function (name) {
        return Jade.Path.getFileExtension(name) == ".font";
    }

});