import { APP_INITIALIZER, Provider } from '@angular/core'
import { ILoadScriptOptions, setDefaultOptions } from 'esri-loader'

import { ArcgisjsapiConfig } from './arcgisjsapi.config'
import { environment } from '../../environments/environment'


export const setDefaultOptionsInit = () => {
    return () => {
        const configure: ArcgisjsapiConfig = environment
        const options: ILoadScriptOptions = {
            url: configure.js,
            css: configure.css
        }
        setDefaultOptions(options)
    }
}


export const ArcgisjsapiProvider: Provider = {
    provide: APP_INITIALIZER,
    useFactory: setDefaultOptionsInit,
    multi: true
}
