export class DataModelLocalStorage {

    constructor() { }

    getItem( key: string ) 
    {
        var returnData = '';

        var keyArr = key.split( '~' );
        var fieldName = keyArr[0];
        var fieldValue = keyArr[1];
        var data = localStorage.getItem( fieldName );
        if ( data && data.trim().length > 0 ) 
        {
            var jsonData = JSON.parse( data );
            returnData = jsonData[fieldValue];
            console.log( 'returnData', returnData );
        }
        return returnData;
    }

    setItem( key: string, response:any ) 
    {
        var keyArr = key.split( '~' );
        var fieldName = keyArr[0];
        var fieldValue = keyArr[1];

        var data = localStorage.getItem( fieldName );
        var jsonData:any = {};
        if ( data && data.trim().length > 0 ) 
        {
            console.log( 'inside setItem ' )
            jsonData = JSON.parse( data );
            jsonData[fieldValue] = response;
            localStorage.setItem( fieldName, JSON.stringify( jsonData ) );
        }
        else 
        {
            jsonData = {};
            jsonData[fieldValue] = response;
            localStorage.setItem( fieldName, JSON.stringify( jsonData ) );
        }
    }
}
