import dayjs from 'dayjs';
import _ from 'lodash';

export default {
    filesFormatter(arr) {
        if (!arr || !arr.length) return [];
        return arr.map((item) => item);
    },
    imageFormatter(arr) {
        if (!arr || !arr.length) return []
        return arr.map(item => ({
            publicUrl: item.publicUrl || ''
        }))
    },
    oneImageFormatter(arr) {
        if (!arr || !arr.length) return ''
        return arr[0].publicUrl || ''
    },
    dateFormatter(date) {
        if (!date) return ''
        return dayjs(date).format('YYYY-MM-DD')
    },
    dateTimeFormatter(date) {
        if (!date) return ''
        return dayjs(date).format('YYYY-MM-DD HH:mm')
    },
    booleanFormatter(val) {
        return val ? 'Yes' : 'No'
    },
    dataGridEditFormatter(obj) {
        return _.transform(obj, (result, value, key) => {
            if (_.isArray(value)) {
                result[key] = _.map(value, 'id');
            } else if (_.isObject(value)) {
                result[key] = value.id;
            } else {
                result[key] = value;
            }
        });
    },
    
        
        usersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.firstName)
        },
        usersOneListFormatter(val) {
            if (!val) return ''
            return val.firstName
        },
        usersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.firstName}
            });
        },
        usersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.firstName, id: val.id}
        },
        
    
        
        rolesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        rolesOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        rolesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        rolesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        permissionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        permissionsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        permissionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        permissionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        organizationsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        organizationsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        organizationsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        organizationsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
    
        
        artist_profilesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.artist_name)
        },
        artist_profilesOneListFormatter(val) {
            if (!val) return ''
            return val.artist_name
        },
        artist_profilesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.artist_name}
            });
        },
        artist_profilesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.artist_name, id: val.id}
        },
        
    
        
        teamsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        teamsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        teamsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        teamsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
    
        
        plansManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        plansOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        plansManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        plansOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
    
        
        distribution_platformsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        distribution_platformsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        distribution_platformsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        distribution_platformsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        genresManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        genresOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        genresManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        genresOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        releasesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title)
        },
        releasesOneListFormatter(val) {
            if (!val) return ''
            return val.title
        },
        releasesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title}
            });
        },
        releasesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title, id: val.id}
        },
        
    
        
        tracksManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title)
        },
        tracksOneListFormatter(val) {
            if (!val) return ''
            return val.title
        },
        tracksManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title}
            });
        },
        tracksOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title, id: val.id}
        },
        
    
        
    
        
    
        
        smart_linksManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.slug)
        },
        smart_linksOneListFormatter(val) {
            if (!val) return ''
            return val.slug
        },
        smart_linksManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.slug}
            });
        },
        smart_linksOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.slug, id: val.id}
        },
        
    
        
    
        
    
        
        playlistsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        playlistsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        playlistsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        playlistsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
    
        
    
        
        royalty_reportsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.source_reference)
        },
        royalty_reportsOneListFormatter(val) {
            if (!val) return ''
            return val.source_reference
        },
        royalty_reportsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.source_reference}
            });
        },
        royalty_reportsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.source_reference, id: val.id}
        },
        
    
        
    
        
        walletsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.currency)
        },
        walletsOneListFormatter(val) {
            if (!val) return ''
            return val.currency
        },
        walletsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.currency}
            });
        },
        walletsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.currency, id: val.id}
        },
        
    
        
    
        
        payout_methodsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.method_label)
        },
        payout_methodsOneListFormatter(val) {
            if (!val) return ''
            return val.method_label
        },
        payout_methodsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.method_label}
            });
        },
        payout_methodsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.method_label, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
        referral_programsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        referral_programsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        referral_programsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        referral_programsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        referral_linksManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.code)
        },
        referral_linksOneListFormatter(val) {
            if (!val) return ''
            return val.code
        },
        referral_linksManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.code}
            });
        },
        referral_linksOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.code, id: val.id}
        },
        
    
        
    
}
