
const moment = require('moment')
const _ =require('lodash')
async function computedFx(extensions,config){


    for await (col of config.collections.schemas){


        for await (f of col.fields){


            // Build extensions


            if(f.type=='computed' && f.computedFx.active){
                var needs ={}
                var result ={} 
                var fx =f.computedFx?.fx || null
               // console.log(fx)
                eval(`var  compute =function compute(item){
                    ${fx}
                } `)
                f.computedFx.needs?.map(need=>{
                    needs[need]=true
                })

                

               result[col.slug]={}
               result[col.slug][f.name]={
                needs:needs,
                compute:compute

               }
               var extension ={
                result:result
               }
               extensions.push(extension)
            }


            
        }
    }



}

module.exports={
    computedFx
}