import { ClipboardModule } from '@angular/cdk/clipboard';
import { ChangeDetectionStrategy, Component, inject, Input } from '@angular/core';
import { toSignal } from '@angular/core/rxjs-interop';
import { TUI_FALSE_HANDLER } from '@taiga-ui/cdk/constants';
import { TuiCopyProcessor } from '@taiga-ui/cdk/directives/copy-processor';
import { tuiIsString } from '@taiga-ui/cdk/utils/miscellaneous';
import { TuiButton } from '@taiga-ui/core/components/button';
import { TuiIcon } from '@taiga-ui/core/components/icon';
import { TUI_NOTIFICATION_OPTIONS } from '@taiga-ui/core/components/notification';
import { TuiHint } from '@taiga-ui/core/directives/hint';
import { TUI_COPY_TEXTS } from '@taiga-ui/kit/tokens';
import { BehaviorSubject, map, startWith, switchMap, timer } from 'rxjs';
import { TUI_COPY_OPTIONS } from './copy.options';
import * as i0 from "@angular/core";
import * as i1 from "@angular/cdk/clipboard";
import * as i2 from "@taiga-ui/core/directives/hint";
class TuiCopyComponent {
    constructor() {
        this.processor = inject(TuiCopyProcessor, { optional: true });
        this.notification = inject(TUI_NOTIFICATION_OPTIONS);
        this.options = inject(TUI_COPY_OPTIONS);
        this.copied$ = new BehaviorSubject(false);
        this.texts = toSignal(inject(TUI_COPY_TEXTS));
        this.hint = toSignal(this.copied$.pipe(switchMap((copied) => timer(2000).pipe(map(TUI_FALSE_HANDLER), startWith(copied)))));
        this.size = 'm';
    }
    get icon() {
        return tuiIsString(this.options.icon)
            ? this.options.icon
            : this.options.icon(this.size);
    }
    get check() {
        return tuiIsString(this.notification.icon)
            ? this.notification.icon
            : this.notification.icon('positive');
    }
    process(value) {
        const source = value ?? '';
        return this.processor?.tuiCopyProcessor(source) ?? source.trim();
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TuiCopyComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: TuiCopyComponent, isStandalone: true, selector: "tui-copy", inputs: { size: "size" }, host: { listeners: { "pointerdown": "copied$.next(false)" }, properties: { "attr.data-size": "size" } }, ngImport: i0, template: "<span\n    #content\n    tuiHintAppearance=\"dark\"\n    tuiHintDirection=\"top\"\n    class=\"t-content\"\n    [cdkCopyToClipboard]=\"process(content.textContent)\"\n    [tuiHint]=\"template\"\n    [tuiHintManual]=\"!!hint()\"\n    (cdkCopyToClipboardCopied)=\"copied$.next($event)\"\n>\n    <ng-content />\n</span>\n<button\n    appearance=\"icon\"\n    size=\"xs\"\n    tuiIconButton\n    type=\"button\"\n    class=\"t-button\"\n    [attr.aria-label]=\"texts()?.[0]\"\n    [cdkCopyToClipboard]=\"process(content.textContent)\"\n    [iconStart]=\"icon\"\n    (cdkCopyToClipboardCopied)=\"copied$.next($event)\"\n></button>\n<ng-template #template>\n    <tui-icon\n        class=\"t-icon\"\n        [icon]=\"check\"\n    />\n    {{ texts()?.[1] }}\n</ng-template>\n", styles: [":host{cursor:pointer}:host[data-size=m]{--t-size: min( calc(1em + 1px) , 1rem)}:host[data-size=l]{--t-size: max(calc(1em / 1.57), min(max(calc(1em / 1.18), 1.25rem), 1.5rem))}@media (hover: hover) and (pointer: fine){:host:hover .t-content{opacity:var(--tui-disabled-opacity);-webkit-mask-position:0;mask-position:0}:host:hover .t-button{opacity:1}}:host:has(.t-button:focus-visible) .t-content{opacity:var(--tui-disabled-opacity);-webkit-mask-position:0;mask-position:0}.t-content{transition-property:opacity,-webkit-mask;transition-property:opacity,mask;transition-property:opacity,mask,-webkit-mask;transition-duration:var(--tui-duration, .3s);transition-timing-function:ease-in-out;-webkit-mask:linear-gradient(to var(--tui-inline-start),transparent calc(1.25 * var(--t-size)),black calc(2 * var(--t-size))) no-repeat,linear-gradient(to var(--tui-inline-end),black,black calc(2 * var(--t-size)),transparent calc(2 * var(--t-size))) no-repeat;mask:linear-gradient(to var(--tui-inline-start),transparent calc(1.25 * var(--t-size)),black calc(2 * var(--t-size))) no-repeat,linear-gradient(to var(--tui-inline-end),black,black calc(2 * var(--t-size)),transparent calc(2 * var(--t-size))) no-repeat;-webkit-mask-position:calc(var(--tui-inline) * 2 * var(--t-size)),0;mask-position:calc(var(--tui-inline) * 2 * var(--t-size)),0}.t-button{opacity:0;border-radius:0;font-size:inherit!important;margin-inline-start:calc(-1 * var(--t-size));--t-size: inherit}.t-button:before{font-size:var(--t-size)}.t-button:focus-visible{opacity:1}.t-icon{font-size:1rem;margin-inline-end:.25rem;vertical-align:sub;color:var(--tui-text-positive)}\n"], dependencies: [{ kind: "ngmodule", type: ClipboardModule }, { kind: "directive", type: i1.CdkCopyToClipboard, selector: "[cdkCopyToClipboard]", inputs: ["cdkCopyToClipboard", "cdkCopyToClipboardAttempts"], outputs: ["cdkCopyToClipboardCopied"] }, { kind: "directive", type: TuiButton, selector: "a[tuiButton],button[tuiButton],a[tuiIconButton],button[tuiIconButton]", inputs: ["size"] }, { kind: "directive", type: i2.TuiHintDirective, selector: "[tuiHint]:not(ng-container):not(ng-template)", inputs: ["tuiHintContext", "tuiHintAppearance", "tuiHint"], outputs: ["tuiHintVisible"] }, { kind: "directive", type: i2.TuiHintManual, selector: "[tuiHint][tuiHintManual]", inputs: ["tuiHintManual"] }, { kind: "component", type: TuiIcon, selector: "tui-icon", inputs: ["icon", "background"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
}
export { TuiCopyComponent };
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TuiCopyComponent, decorators: [{
            type: Component,
            args: [{ standalone: true, selector: 'tui-copy', imports: [ClipboardModule, TuiButton, TuiHint, TuiIcon], changeDetection: ChangeDetectionStrategy.OnPush, host: {
                        '[attr.data-size]': 'size',
                        '(pointerdown)': 'copied$.next(false)',
                    }, template: "<span\n    #content\n    tuiHintAppearance=\"dark\"\n    tuiHintDirection=\"top\"\n    class=\"t-content\"\n    [cdkCopyToClipboard]=\"process(content.textContent)\"\n    [tuiHint]=\"template\"\n    [tuiHintManual]=\"!!hint()\"\n    (cdkCopyToClipboardCopied)=\"copied$.next($event)\"\n>\n    <ng-content />\n</span>\n<button\n    appearance=\"icon\"\n    size=\"xs\"\n    tuiIconButton\n    type=\"button\"\n    class=\"t-button\"\n    [attr.aria-label]=\"texts()?.[0]\"\n    [cdkCopyToClipboard]=\"process(content.textContent)\"\n    [iconStart]=\"icon\"\n    (cdkCopyToClipboardCopied)=\"copied$.next($event)\"\n></button>\n<ng-template #template>\n    <tui-icon\n        class=\"t-icon\"\n        [icon]=\"check\"\n    />\n    {{ texts()?.[1] }}\n</ng-template>\n", styles: [":host{cursor:pointer}:host[data-size=m]{--t-size: min( calc(1em + 1px) , 1rem)}:host[data-size=l]{--t-size: max(calc(1em / 1.57), min(max(calc(1em / 1.18), 1.25rem), 1.5rem))}@media (hover: hover) and (pointer: fine){:host:hover .t-content{opacity:var(--tui-disabled-opacity);-webkit-mask-position:0;mask-position:0}:host:hover .t-button{opacity:1}}:host:has(.t-button:focus-visible) .t-content{opacity:var(--tui-disabled-opacity);-webkit-mask-position:0;mask-position:0}.t-content{transition-property:opacity,-webkit-mask;transition-property:opacity,mask;transition-property:opacity,mask,-webkit-mask;transition-duration:var(--tui-duration, .3s);transition-timing-function:ease-in-out;-webkit-mask:linear-gradient(to var(--tui-inline-start),transparent calc(1.25 * var(--t-size)),black calc(2 * var(--t-size))) no-repeat,linear-gradient(to var(--tui-inline-end),black,black calc(2 * var(--t-size)),transparent calc(2 * var(--t-size))) no-repeat;mask:linear-gradient(to var(--tui-inline-start),transparent calc(1.25 * var(--t-size)),black calc(2 * var(--t-size))) no-repeat,linear-gradient(to var(--tui-inline-end),black,black calc(2 * var(--t-size)),transparent calc(2 * var(--t-size))) no-repeat;-webkit-mask-position:calc(var(--tui-inline) * 2 * var(--t-size)),0;mask-position:calc(var(--tui-inline) * 2 * var(--t-size)),0}.t-button{opacity:0;border-radius:0;font-size:inherit!important;margin-inline-start:calc(-1 * var(--t-size));--t-size: inherit}.t-button:before{font-size:var(--t-size)}.t-button:focus-visible{opacity:1}.t-icon{font-size:1rem;margin-inline-end:.25rem;vertical-align:sub;color:var(--tui-text-positive)}\n"] }]
        }], propDecorators: { size: [{
                type: Input
            }] } });
//# sourceMappingURL=data:application/json;base64, 