import defaultProcess from "./defaultProcess.js";

export default function wardrobeItemsTypes(code,options){
    const twineCode = defaultProcess(code);

    let tsCode = 'setup.wardrobeItemVars ??= {};\n';

    const regexes = {
        'bras': /if (\w+)S\[i\] = metka_bras and \1\[i\] = 1:/gm,
        'clothes': /if (\w+)\[i\] = 1 and \(\$clothingworntype ! '\1' or clothingwornnumber ! i\):/gm,
        'coats': /if (\w+)_s\[i\] = coat_loc and \1\[i\] = 1:/gm,
        'panties': /if (\w+)S\[i\] = metka_panties and \1\[i\] = 1:/gm,
        'shoes': /if (\w+)_s\[i\] = sloc and \1\[i\] = 1:/gm,
    };

    let result;

    for(const[type, regex] of Object.entries(regexes)){
        let i = 0;

        while(result = regex.exec(code)) {
            if(i++ == 0)
                tsCode += `setup.wardrobeItemVars['${type}'] ??= [];\n`;
            tsCode += `setup.wardrobeItemVars['${type}'].push('${result[1]}');\n`;
        }

    }

    return [twineCode,tsCode];
}
