import isArray from "../basic/isArray";
import isIndex from "./_isIndex";
import has from "../#has";
import isArguments from "../#isArguments";

/** Used to check objects for own properties. */
// const hasOwnProperty = Object.prototype.hasOwnProperty;

/**
 * Creates an array of the enumerable property names of the array-like `value`.
 *
 * @private
 * @param {*} value The value to query.
 * @param {boolean} inherited Specify returning inherited property names.
 * @returns {Array} Returns the array of property names.
 */
function arrayLikeKeys(value: any, inherited?: boolean): Array<string> {
    const isArr = isArray(value);
    const isArg = !isArr && isArguments(value);
    const skipIndexes = isArr || isArg;
    const length = value.length;
    const result = new Array(skipIndexes ? length : 0);
    let index = skipIndexes ? -1 : length;
    while (++index < length) {
        result[index] = `${index}`;
    }
    for (const key in value) {
        if ((inherited || has(value, key)) && !(skipIndexes && (key === "length" || isIndex(key, length)))) {
            result.push(key);
        }
    }
    return result;
}

export default arrayLikeKeys;
// import isArguments from "../isArguments.js";
// import isBuffer from "../isBuffer.js";
// import isIndex from "./isIndex.js";
// import isTypedArray from "../isTypedArray.js";

// /** Used to check objects for own properties. */
// const hasOwnProperty = Object.prototype.hasOwnProperty;

// /**
//  * Creates an array of the enumerable property names of the array-like `value`.
//  *
//  * @private
//  * @param {*} value The value to query.
//  * @param {boolean} inherited Specify returning inherited property names.
//  * @returns {Array} Returns the array of property names.
//  */
// function arrayLikeKeys(value, inherited) {
//     const isArr = Array.isArray(value);
//     const isArg = !isArr && isArguments(value);
//     const isBuff = !isArr && !isArg && isBuffer(value);
//     const isType = !isArr && !isArg && !isBuff && isTypedArray(value);
//     const skipIndexes = isArr || isArg || isBuff || isType;
//     const length = value.length;
//     const result = new Array(skipIndexes ? length : 0);
//     let index = skipIndexes ? -1 : length;
//     while (++index < length) {
//         result[index] = `${index}`;
//     }
//     for (const key in value) {
//         if (
//             (inherited || hasOwnProperty.call(value, key)) &&
//             !(
//                 skipIndexes &&
//                 // Safari 9 has enumerable `arguments.length` in strict mode.
//                 (key === "length" ||
//                     // Skip index properties.
//                     isIndex(key, length))
//             )
//         ) {
//             result.push(key);
//         }
//     }
//     return result;
// }
