<commit_before>import '/resources/components/tg-paper-toast.js';

import { TgToastBehavior } from '/resources/components/tg-toast-behavior.js';

import { html, PolymerElement } from '/resources/polymer/@polymer/polymer/polymer-element.js';
import { mixinBehaviors } from '/resources/polymer/@polymer/polymer/lib/legacy/class.js';

const template = html`
    <tg-paper-toast id="actionToast" text="[[text]]" allow-click-through always-on-top duration="0">
        <div id='btnAction' hidden$="[[!_actionVisible(countdown)]]" class="toast-btn" on-tap="_actionHandler">[[actionText]]</div>
        <div id='btnCancel' class="toast-btn" on-tap="_cancelHandler">[[cancelText]]</div>
    </tg-paper-toast>`; 

class TgDelayedActionToast extends mixinBehaviors([TgToastBehavior], PolymerElement) {

    static get template() { 
        return template;
    }

    static get properties() {
        return {
            countdown: Number,

            actionText: {
                type: String,
                value: 'RUN'
            },

            cancelText: {
                type: String,
                value: 'CANCEL'
            },
             
            text: {
                type: String,
                value: ''
            },
            
            context: {
                type: Object,
                value: null
            } 
        };
    }

    ready() {
        super.ready();
        this.$.actionToast.refit = function(){};
    }

    get opened() {
        return this.$.actionToast.opened;
    }

    show() {
        //Append action toast if it is not yet present
        const paperToast = this.getDocumentToast('actionToast');
        const toastContainer = this.getToastContainer();
        if (!paperToast) {
            toastContainer.prepend(this.$.actionToast);
        }

        if (toastContainer.firstChild !== this.$.actionToast) {
            toastContainer.prepend(this.$.actionToast);
        }
        this.$.actionToast.open();
    }

    hide() {<commit_msg>#1854 Adde click event to bring data changed toast to front if it was hidden by another dialog.<commit_after>import '/resources/components/tg-paper-toast.js';

import { TgToastBehavior } from '/resources/components/tg-toast-behavior.js';

import { html, PolymerElement } from '/resources/polymer/@polymer/polymer/polymer-element.js';
import { mixinBehaviors } from '/resources/polymer/@polymer/polymer/lib/legacy/class.js';

const template = html`
    <tg-paper-toast id="actionToast" text="[[text]]" allow-click-through always-on-top duration="0">
        <div id='btnAction' hidden$="[[!_actionVisible(countdown)]]" class="toast-btn" on-tap="_actionHandler">[[actionText]]</div>
        <div id='btnCancel' class="toast-btn" on-tap="_cancelHandler">[[cancelText]]</div>
    </tg-paper-toast>`; 

class TgDelayedActionToast extends mixinBehaviors([TgToastBehavior], PolymerElement) {

    static get template() { 
        return template;
    }

    static get properties() {
        return {
            countdown: Number,

            actionText: {
                type: String,
                value: 'RUN'
            },

            cancelText: {
                type: String,
                value: 'CANCEL'
            },
             
            text: {
                type: String,
                value: ''
            },
            
            context: {
                type: Object,
                value: null
            } 
        };
    }

    ready() {
        super.ready();
        this.$.actionToast.refit = function(){};
        this.$.actionToast.addEventListener

        this._onCaptureClick = this._onCaptureClick.bind(this);
    }

    connectedCallback () {
        super.connectedCallback();
        const clickEvent = ('ontouchstart' in window) ? 'touchstart' : 'mousedown';
        this.$.actionToast.addEventListener(clickEvent, this._onCaptureClick, true);
    }

    disconnectedCallback() {
        super.disconnectedCallback();
        const clickEvent = ('ontouchstart' in window) ? 'touchstart' : 'mousedown';
        this.$.actionToast.removeEventListener(clickEvent, this._onCaptureClick, true);
    }

    _onCaptureClick (event) {
        const manager = this.$.actionToast._manager;
        // bring current toast to front if it is not in front already
        if (manager.currentOverlay() !== this.$.actionToast) {
            manager.addOverlay(this.$.actionToast);
        }
    }

    get opened() {
        return this.$.actionToast.opened;
    }

    show() {
        //Append action toast if it is not yet present
        const paperToast = this.getDocumentToast('actionToast');
        const toastContainer = this.getToastContainer();
        if (!paperToast) {
            toastContainer.prepend(this.$.actionToast);
        }

        if (toastContainer.firstChild !== this.$.actionToast) {
            toastContainer.prepend(this.$.actionToast);
        }
        this.$.actionToast.open();
    }

    hide() {
{'fraction_non_alphanumeric': 0.12957010847730013, 'fraction_numerical': 0.0012053033346725592, 'mean_word_length': 2.0677757239679604, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '2658887', 'n_tokens_mistral': 1459, 'n_tokens_neox': 1376, 'n_words': 269}