/**
 * @license
 * Copyright renie.tech, all Rights Reserved.
 * Licensed under the MIT License. See LICENSE in the project root for more information.
 */
import { Component, forwardRef, Input } from '@angular/core';
import { FormControl, NG_VALUE_ACCESSOR } from '@angular/forms';
const CONTROL_VALUE_ACCESSOR = {
    provide: NG_VALUE_ACCESSOR,
    useExisting: forwardRef(() => RFileInput),
    multi: true
};
export class RFileInput {
    constructor() {
        this.status = 'basic';
        this.shape = 'rectangle';
        this.size = 'medium';
        this.name = new FormControl(null);
        this.propagateChange = (_) => { };
        this.onTouch = () => { };
        this.name.disable();
    }
    onChange($event) {
        if ($event.target.files && $event.target.files.length > 0) {
            const file = $event.target.files[0];
            this.name.patchValue((file === null || file === void 0 ? void 0 : file.name) || '');
            this.propagateChange(file);
            /**
             * TODO
             * @Subbre
             */
            // if (file.size > 3200000) {
            //   this.notificationService.warning(this.translateService.translateWithoutPipe(lang.fileSize), this.translateService.translateWithoutPipe(lang.warning));
            // }
        }
    }
    writeValue(input) {
        console.log(input);
    }
    registerOnChange(fn) {
        this.propagateChange = fn;
    }
    registerOnTouched(fn) {
        this.onTouch = fn;
    }
    setDisabledState(isDisabled) { }
}
RFileInput.decorators = [
    { type: Component, args: [{
                selector: 'r-file-input',
                template: "<!-- hidden input with reference to click on button click\r\nthis way we avoid styling label -->\r\n<input (change)=\"onChange($event)\" #fileInput hidden type=\"file\">\r\n\r\n<div class=\"file-input-wrap\">\r\n  <button [status]=\"status\" (click)=\"fileInput.click()\" r-icon-button>\r\n    <r-icon icon=\"file-add-outline\"></r-icon>\r\n  </button>\r\n  <input [formControl]=\"name\" [status]=\"status\" [shape]=\"shape\" type=\"text\" rInput>\r\n</div>",
                providers: [CONTROL_VALUE_ACCESSOR],
                styles: [":host{display:block;margin-bottom:8px}:host [rInput]{margin-bottom:6px}:host .file-input-wrap{display:flex;align-items:center}:host .file-input-wrap input{margin-left:4px}"]
            },] }
];
RFileInput.ctorParameters = () => [];
RFileInput.propDecorators = {
    status: [{ type: Input }],
    shape: [{ type: Input }],
    size: [{ type: Input }]
};
//# sourceMappingURL=file-input.js.map