"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.deprecatedOptionsHandler = deprecatedOptionsHandler;

var _buildToolLoggers = require("../../buildToolLoggers");

function selectn(obj, key) {
  let temp = obj;
  const keys = key.split('.');

  for (let i = 0; i < keys.length; i++) {
    const element = keys[i];
    temp = temp && temp[element];
  }

  return temp;
}

function selectnu(obj, key, value) {
  let temp = obj;
  const keys = key.split('.');
  let i = 0;

  for (; i < keys.length - 1; i++) {
    const element = keys[i];
    temp = temp && temp[element];
  }

  temp[keys[i]] = value;
}

function deprecatedOptionsHandler(options) {
  function checkAndupdateAndPrintWaring(oldKey, newkey) {
    const oldVal = selectn(options, oldKey);
    const newVal = selectn(options, newkey); // console.log({ oldVal, newVal });

    if (oldVal !== undefined && newVal === undefined) {
      selectnu(options, newkey, newVal);
      (0, _buildToolLoggers.warnLogger)(`"${oldKey}" deprecated use "${newkey}" instead`);
    }
  } // return;


  checkAndupdateAndPrintWaring('app.context', 'context'); // TODO handle deprecations  here
  // we will finish this logic later when options are confirmed

  if (selectn(options, 'app.hasRTL') === true) {
    options.app.plugins.hasRTL = true;
  }

  if (selectn(options, 'docs.hasRTL') === true) {
    options.docs.plugins.hasRTL = true;
  }

  if (selectn(options, 'app.rtlExclude.length') > 0) {
    options.app.exclude.rtl = selectn(options, 'app.rtlExclude');
  }

  if (selectn(options, 'docs.rtlExclude.length') > 0) {
    options.docs.exclude.rtl = selectn(options, 'docs.rtlExclude');
  }
}