/**
 * 是否空对象
 * @param {Object} value
 * @return {Boolean}
 */
export function isEmptyObject(value) {
  return JSON.stringify(value) == '{}';
}

/**
 * This is just a simple version of deep copy
 * Has a lot of edge cases bug
 * If you want to use a perfect deep copy, use lodash's _.cloneDeep
 * @param {Object} source
 * @returns {Object}
 */
export function deepClone(source) {
  if (!source && typeof source !== 'object') {
    throw new Error('error arguments', 'deepClone')
  }
  const targetObj = source.constructor === Array ? [] : {}
  Object.keys(source).forEach(keys => {
    if (source[keys] && typeof source[keys] === 'object') {
      targetObj[keys] = deepClone(source[keys])
    } else {
      targetObj[keys] = source[keys]
    }
  })
  return targetObj
}

/**
 * author: hyw
 * 修改二维数组键名
 * @param {*} arr 
 * @param {*} pool 
 * 示例：{
 *    id:'product_type_guid',
 *    parent_id:'product_type_parent_guid'
 * }
 */
 export function changeDataPropertyName(arr,pool,isRecursion){
  arr.map((objItem,idx)=>{
    for(let key in pool){
      objItem[pool[key]] = objItem[key]
      if(isRecursion) changeDataPropertyName(objItem['children'],pool)
    }
  })
}

