import * as i0 from '@angular/core';
import { Directive, Inject, Input, HostListener, NgModule } from '@angular/core';
import { DOCUMENT, CommonModule } from '@angular/common';
import { isFunction } from '@ironsource/fusion-ui/utils';

class CopyToClipboardDirective {
    constructor(document, // todo: Document (open issue https://github.com/angular/angular/issues/20351)
    renderer, elementRef) {
        this.document = document;
        this.renderer = renderer;
        this.elementRef = elementRef;
        this._document = document;
    }
    onClick($event) {
        $event.preventDefault();
        $event.stopPropagation();
        const textToCopy = isFunction(this.fusionCopyToClipboard)
            ? this.fusionCopyToClipboard(this.elementRef)
            : this.elementRef.nativeElement.innerHTML;
        this.copyText(textToCopy);
    }
    copyText(textToCopy) {
        const elem = this.renderer.createElement('input');
        this.renderer.setAttribute(elem, 'type', 'text');
        this.renderer.setAttribute(elem, 'value', textToCopy);
        this.renderer.appendChild(this._document.body, elem);
        elem.focus();
        elem.select();
        this._document.execCommand('Copy');
        this.renderer.removeChild(this._document.body, elem);
    }
    static { this.ɵfac = function CopyToClipboardDirective_Factory(t) { return new (t || CopyToClipboardDirective)(i0.ɵɵdirectiveInject(DOCUMENT), i0.ɵɵdirectiveInject(i0.Renderer2), i0.ɵɵdirectiveInject(i0.ElementRef)); }; }
    static { this.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: CopyToClipboardDirective, selectors: [["", "fusionCopyToClipboard", ""]], hostBindings: function CopyToClipboardDirective_HostBindings(rf, ctx) { if (rf & 1) {
            i0.ɵɵlistener("click", function CopyToClipboardDirective_click_HostBindingHandler($event) { return ctx.onClick($event); });
        } }, inputs: { fusionCopyToClipboard: "fusionCopyToClipboard" } }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(CopyToClipboardDirective, [{
        type: Directive,
        args: [{
                selector: '[fusionCopyToClipboard]'
            }]
    }], () => [{ type: undefined, decorators: [{
                type: Inject,
                args: [DOCUMENT]
            }] }, { type: i0.Renderer2 }, { type: i0.ElementRef }], { fusionCopyToClipboard: [{
            type: Input
        }], onClick: [{
            type: HostListener,
            args: ['click', ['$event']]
        }] }); })();

class CopyToClipboardModule {
    static { this.ɵfac = function CopyToClipboardModule_Factory(t) { return new (t || CopyToClipboardModule)(); }; }
    static { this.ɵmod = /*@__PURE__*/ i0.ɵɵdefineNgModule({ type: CopyToClipboardModule }); }
    static { this.ɵinj = /*@__PURE__*/ i0.ɵɵdefineInjector({ imports: [CommonModule] }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(CopyToClipboardModule, [{
        type: NgModule,
        args: [{
                imports: [CommonModule],
                declarations: [CopyToClipboardDirective],
                exports: [CopyToClipboardDirective]
            }]
    }], null, null); })();
(function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0.ɵɵsetNgModuleScope(CopyToClipboardModule, { declarations: [CopyToClipboardDirective], imports: [CommonModule], exports: [CopyToClipboardDirective] }); })();

/**
 * Generated bundle index. Do not edit.
 */

export { CopyToClipboardDirective, CopyToClipboardModule };
//# sourceMappingURL=ironsource-fusion-ui-directives-copy-to-clipboard.mjs.map
