import { Injectable, SkipSelf, Optional } from "@angular/core";
import { environment } from '../../../../environments/environment';
import { ICollapsableLoggerService, ILoggerService } from './LoggerService';

@Injectable()
export class LoggerService implements ICollapsableLoggerService {

    private logger = console
    
    constructor(
    ) { }

    log = (...args) => { this.LOG('log', args) }
    warn = (...args) => { this.LOG('warn', args) }
    error = (...args) => { this.LOG('error', args) }
    table = (...args) => { this.LOG('table', args) }
    collapsed = (groupname: string, type: keyof ILoggerService, ...args) => {
        if (!environment.production) {
            console.groupCollapsed(groupname)
            this[type].apply(this.logger, args)
            console.groupEnd()
        }
    }

    private LOG(type, ...args) {
        if (!environment.production) {
            this.logger[type].apply(this.logger, ...args)
        }
    }
}