<commit_before>import * as $ from "jquery";
import MediaItemMeta from "@enhavo/media/Type/MediaItemMeta";
import MediaRow from "@enhavo/media/Type/MediaRow";

export default class MediaItem
{
    private $element: JQuery;

    private meta: MediaItemMeta;

    private row: MediaRow;

    constructor(element:HTMLElement, meta:MediaItemMeta, row:MediaRow)
    {
        this.$element = $(element);
        this.meta = meta;
        this.row = row;
        this.addHandler();
    }

    private addHandler()
    {
        let self = this;

        if(this.row.getMedia().getConfig().edit) {
            this.$element.click(function() {
                self.openEdit();
            });
        }

        this.$element.find('[data-media-item-delete]').click(function(event) {
            event.stopPropagation();
            event.preventDefault();
            self.remove();
        });
    }

    inactive()
    {
        this.$element.removeClass('active');
    }

    active()
    {
        this.$element.addClass('active');
    }

    remove()
    {
        this.$element.remove();
        this.row.closeEdit();
        this.row.setOrder();
    }

    getElement():HTMLElement
    {
        return <HTMLElement>this.$element.get(0);
    }

    getEditElements():Array<HTMLElement>
    {
        return <HTMLElement[]>this.$element.find('[data-media-edit]').children().toArray();
    }

    setEditElements(element:HTMLElement|Array<HTMLElement>)
    {
        return this.$element.find('[data-media-edit]').append(element);
    }

    setOrder(order:number)
    {
        this.meta.order = order;
        this.$element.find('[data-position]').val(order);
    }

    setFilename(filename:string)
    {
        this.meta.filename = filename;
        this.$element.find('[data-media-item-filename]').val(filename);
    }

    setId(id:number)
    {
        this.meta.id = id;
        this.$element.find('[data-media-item-id]').val(id);
    }

    getId(): number
    {
        return this.meta.id;
    }

    openEdit()
    {
        this.row.openEdit(this);
    }

    closeEdit()
    {
        this.row.closeEdit();
    }

    getRow(): MediaRow
    {
        return this.row;
    }

    getMeta(): MediaItemMeta
    {
        return this.meta;
    }

    updateThumb()
    {
        // reset
        this.$element.find('[data-media-thumb]').css('background-image', 'none');
        this.$element.find('[data-media-thumb-icon]').removeClass().addClass('icon');

        console.log(this.meta.mimeType);

        // set icon/image
        switch (this.meta.mimeType) {
            case 'image/png':<commit_msg>Removed debug console.log<commit_after>import * as $ from "jquery";
import MediaItemMeta from "@enhavo/media/Type/MediaItemMeta";
import MediaRow from "@enhavo/media/Type/MediaRow";

export default class MediaItem
{
    private $element: JQuery;

    private meta: MediaItemMeta;

    private row: MediaRow;

    constructor(element:HTMLElement, meta:MediaItemMeta, row:MediaRow)
    {
        this.$element = $(element);
        this.meta = meta;
        this.row = row;
        this.addHandler();
    }

    private addHandler()
    {
        let self = this;

        if(this.row.getMedia().getConfig().edit) {
            this.$element.click(function() {
                self.openEdit();
            });
        }

        this.$element.find('[data-media-item-delete]').click(function(event) {
            event.stopPropagation();
            event.preventDefault();
            self.remove();
        });
    }

    inactive()
    {
        this.$element.removeClass('active');
    }

    active()
    {
        this.$element.addClass('active');
    }

    remove()
    {
        this.$element.remove();
        this.row.closeEdit();
        this.row.setOrder();
    }

    getElement():HTMLElement
    {
        return <HTMLElement>this.$element.get(0);
    }

    getEditElements():Array<HTMLElement>
    {
        return <HTMLElement[]>this.$element.find('[data-media-edit]').children().toArray();
    }

    setEditElements(element:HTMLElement|Array<HTMLElement>)
    {
        return this.$element.find('[data-media-edit]').append(element);
    }

    setOrder(order:number)
    {
        this.meta.order = order;
        this.$element.find('[data-position]').val(order);
    }

    setFilename(filename:string)
    {
        this.meta.filename = filename;
        this.$element.find('[data-media-item-filename]').val(filename);
    }

    setId(id:number)
    {
        this.meta.id = id;
        this.$element.find('[data-media-item-id]').val(id);
    }

    getId(): number
    {
        return this.meta.id;
    }

    openEdit()
    {
        this.row.openEdit(this);
    }

    closeEdit()
    {
        this.row.closeEdit();
    }

    getRow(): MediaRow
    {
        return this.row;
    }

    getMeta(): MediaItemMeta
    {
        return this.meta;
    }

    updateThumb()
    {
        // reset
        this.$element.find('[data-media-thumb]').css('background-image', 'none');
        this.$element.find('[data-media-thumb-icon]').removeClass().addClass('icon');

        // set icon/image
        switch (this.meta.mimeType) {
            case 'image/png':
{'fraction_non_alphanumeric': 0.15581664098613252, 'fraction_numerical': 0.0003852080123266564, 'mean_word_length': 2.0565038257798705, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1686322', 'n_tokens_mistral': 1633, 'n_tokens_neox': 1602, 'n_words': 208}