/* eslint-disable class-methods-use-this */
/* eslint-disable prefer-rest-params */
/* eslint-disable import/prefer-default-export */

import { en } from 'vuetify/lib/locale'
import { mergeDeep } from '../../utils/helpers'
import { Service } from '../service'

export class Presets extends Service {
  constructor (parentPreset, parent) {
    super() // The default preset
    const defaultPreset = mergeDeep({}, {
      breakpoint: {
        // TODO: update to MD2 spec in v3 - 1280
        mobileBreakpoint: 1264,
        scrollBarWidth: 16,
        thresholds: {
          xs: 600,
          sm: 960,
          md: 1280,
          lg: 1920
        }
      },
      icons: {
        // TODO: remove v3
        iconfont: 'mdi',
        values: {}
      },
      lang: {
        current: 'en',
        locales: {
          en
        },
        t: undefined
      },
      rtl: false,
      theme: {
        dark: false,
        default: 'light',
        disable: false,
        options: {
          cspNonce: undefined,
          customProperties: true,
          minifyTheme: undefined,
          themeCache: undefined,
          variations: true
        },
        themes: {
          light: {
            primary: '#1976D2',
            secondary: '#424242',
            accent: '#82B1FF',
            error: '#FF5252',
            info: '#2196F3',
            success: '#4CAF50',
            warning: '#FB8C00'
          },
          dark: {
            primary: '#2196F3',
            secondary: '#424242',
            accent: '#FF4081',
            error: '#FF5252',
            info: '#2196F3',
            success: '#4CAF50',
            warning: '#FB8C00'
          }
        }
      }
    }) // The user provided preset
    const {
      userPreset
    } = parent // The user provided global preset

    const {
      preset: globalPreset = {},
      ...preset
    } = userPreset

    if (globalPreset.preset != null) {
      console.warn('Global presets do not support the **preset** option, it can be safely omitted')
    }

    // eslint-disable-next-line no-param-reassign
    parent.preset = mergeDeep(mergeDeep(defaultPreset, globalPreset), preset)
  }
}
Presets.property = 'presets'
