import { Injectable } from '@angular/core';
import { ZuiF } from '@material-zui/core';
export class ZuiUtilityService {
    constructor() {
        // #uploadId: string = ZuiF.uuid()
        this.download = (option) => {
            const { href, fileName, target = '_blank' } = option;
            const link = document.createElement('a');
            link.download = fileName || ZuiF.uuid();
            link.href = href;
            link.target = target;
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
        };
        this.copyToClipboard = (text) => navigator.clipboard.writeText(text);
        // #upload = (option?: ZuiUtilityUpload, isMutiple: boolean = true): Promise<ZuiUtilityUploadFiles> =>
        //   new Promise<ZuiUtilityUploadFiles>(resolve => {
        //     const uploadId = `#${this.#uploadId}`
        //     const multiple = isMutiple ? 'multiple' : ''
        //     if ($(`${uploadId}`).length) $('body').children(uploadId).remove()
        //     $('body').append(`<input id="${this.#uploadId}" style="display: none" type="file" ${multiple} />`)
        //     const uploadEl = $(`${uploadId}`)
        //     uploadEl.on('change', (evt: any) => {
        //       const valid: File[] = []
        //       const inValid: ZuiUtilityInvalid[] = []
        //       const target: DataTransfer = evt.target
        //       const {files} = target
        //       const {extensions = [], maxSize = {}, validator} = option ?? {}
        //       const {byte = 0, Kb = 0, Mb = 0} = maxSize
        //       const max = byte + Kb * 1024 + Mb * 1024 * 1024
        //       Array.from(files).forEach(file => {
        //         const {name, size} = file
        //         const {extension} = ZuiFile.splitFileName(name)
        //         let isValid = true
        //         let message = ''
        //         if (extensions.length && !extensions.includes(extension)) {
        //           message = `Extension '.${extension}' is not support`
        //           isValid = false
        //         }
        //         if (max > 0 && size > max) {
        //           message = `File size ${ZuiN.format(size)} byte is not valid`
        //           isValid = false
        //         }
        //         if (validator) {
        //           const result = validator(file)
        //           if (ZuiS.isString(result)) {
        //             message = result
        //             isValid = false
        //           }
        //         }
        //         if (isValid) {
        //           valid.push(file)
        //         } else {
        //           inValid.push({file, message})
        //         }
        //       })
        //       resolve({valid, inValid})
        //     })
        //     uploadEl.trigger('click')
        //   })
        // uploadFile = async (option?: ZuiUtilityUpload): Promise<ZuiUtilityUploadFile> => {
        //   const {valid, inValid} = await this.#upload(option, false)
        //   const file = valid?.[0]
        //   const isValid = !inValid.length
        //   return {file, isValid}
        // }
        // uploadFiles = (option?: ZuiUtilityUpload): Promise<ZuiUtilityUploadFiles> => this.#upload(option)
    }
}
ZuiUtilityService.decorators = [
    { type: Injectable }
];
//# sourceMappingURL=index.service.js.map