import { formatDate } from '@angular/common';
import { ɵDEFAULT_LOCALE_ID } from '@angular/core';
import * as moment_ from 'moment';

export const cnst_IP_ADDRESS_SOURCE_URL = 'https://api.ipify.org/?format=json';
export const cnst_HEADER_KEY_LOGINNAME = 'Loginname';
export const cnst_LoginAuth_URL = 'LoginWithAuthorization';
export const cnst_LoginJWT_URL = 'LoginWithJWT';
export const cnst_LoginPassw_URL = 'LoginWithNameAndPassword';
export const cnst_JWT_Expired = 'Benutzerauthentifizierung ist abgelaufen!';
export const cnst_CANCEL_ERROR = 'cancel_error';
export const cnst_ErrorCode4Unauthorized = 401;

export enum EN_AppColors {
  returnRequestColor = 'green',
  startRequestColor = 'blue',

  showSpinnerColor = 'gray',
  hideSpinnerColor = 'red',
}


export const DATE_FORMATS = {
  parse: {
    dateInput: 'DD.MM.YYYY',
  },
  display: {
    dateInput: 'DD.MM.YYYY',
    monthYearLabel: 'MMM YYYY',
    dateA11yLabel: 'LL',
    monthYearA11yLabel: 'MMMM YYYY',
    monthShortName: 'MMM',
    date4WebAPI: 'yyyy-MM-dd',
    dateTime4JSON: 'yyyy-MM-ddTHH:mm:ss.SSS',
    dateFormat: 'dd.MM.yyyy',
    dateTimeFormat: 'dd.MM.yyyy HH:mm',
    dateFormatHensel: 'd MMM YYYY',
    momentFormat: {
      date4WebAPI: 'YYYY-MM-DD',
      dateTime4JSON: 'YYYY-MM-DDTHH:mm:ss.SSS',
      dateFormat: 'DD.MM.YYYY',
      dateTimeFormat: 'DD.MM.YYYY HH:mm',
    },
    timeFormat: 'HH:mm',
  },
};



//Date format for dates in Web API
// Values for All/None in filter drop down list
export const enum EN_DropDownConst4Filter {
  AllCaption = 'core.dropdown-option.all',
  AllValueString = '*',
  AllValueInt = 0,
  NoneCaption = 'core.dropdown-option.none',
  NoneValueString = '_',
  NoneValueInt = -1
}


export const enum EN_EntityEditingStates {
  View = 0,
  Edit = 1,
  New = 2,
  EditKey = 3,
  Idle = 4
}

export const enum EN_EntityBeforeSaveCallBackResults {
  Ok_Continue = 0,
  Ok_Break = 1,
  Error_Continue = 2,
  Error_Break = 3
}

export const enum EN_Error {
  Save = 'Saving unsucceeded'
}

export enum EN_LogType {
  message = 'Message',
  warning = 'Warning',
  error = 'Error',
  confirmation = 'Question',
  guid_message = 'HTTPtiming',

  debug_message = 'Debug',
}

export enum EN_LoginStatus {
  unknown = 0,
  loginWithNameAndPassword = 1,
  jwt = 2,
  windowsAuthorizatoin = 3
}

export enum EN_DateFormats {
  WebAPI = 0,
  Date = 1,
  DateTime = 2,
  JSON = 3
}

Date.prototype.toJSON = function () { return formatDate(this, DATE_FORMATS.display.dateTime4JSON, ɵDEFAULT_LOCALE_ID /* does not matter a culture, we are using explicit date format*/); };

moment_.fn.toJSON = function () { return this.format(DATE_FORMATS.display.momentFormat.dateTime4JSON); };

export const GridExportButtonWidth = 21;

export interface SupportedCulture {
  culture: string;
  country: string;
  languageName: string;
  flag?: string;
}


export interface SupportedLanguage {
  langCode: string;
  languageName: string;
}

export const SUPPORTED_CULTURES: SupportedCulture[] = [
  {culture: 'de-DE', country: 'core.caption.country-ge', languageName: 'core.caption.lang-ge'},
  {culture: 'de-AT', country: 'core.caption.country-at', languageName: 'core.caption.lang-at'},
  {culture: 'en-GB', country: 'core.caption.country-gb', languageName: 'core.caption.lang-gb'},
  {culture: 'en-US', country: 'core.caption.country-us', languageName: 'core.caption.lang-us'},
  {culture: 'en-AU', country: 'core.caption.country-au', languageName: 'core.caption.lang-au'},
  {culture: 'fr-FR', country: 'core.caption.country-fr', languageName: 'core.caption.lang-fr'},
  {culture: 'en-MY', country: 'core.caption.country-my', languageName: 'core.caption.lang-my'},
  // {culture: 'ko-KR', country: 'core.caption.country-kr', languageName: 'core.caption.lang-kr'},
];

export const SUPPORTED_LANGUAGES: SupportedLanguage[] = [
  {langCode: 'de', languageName: 'core.caption.lang-ge'},
  {langCode: 'en', languageName: 'core.caption.lang-us'},
  {langCode: 'fr', languageName: 'core.caption.lang-fr'},
  // {langCode: 'ko', languageName: 'core.caption.lang-kr'},
];
