/**
 * Copyright 2017 - 2018  The Hyve B.V.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */ import { Col } from './col' ; import { FormatHelper } from '../../utilities/format-helper' ; export class Row { private _data : object ; private _metadata : Map < string , Map < string , string > > ; private _metadataText : Map < string , string > ; private _length = 0 ; private _isHeaderRow = false ; private _headerCellCount = 0 ; constructor ( ) { this . data = { } ; this . metadata = new Map < string , Map < string , string > > ( ) ; this . metadataText = new Map < string , string > ( ) ; } param value param { Map < string , string > } metadataValue addDatum ( value , metadataValue ? ) { this . length ++ ; const field = Col . COLUMN_FIELD_PREFIX + this . length . toString ( ) ; this . data [ field ] = value ; if ( metadataValue != null && metadataValue . size ) { this . data [ field ] += ' ⓘ' ; this . metadata [ field ] = metadataValue ; this . metadataText [ field ] = FormatHelper . formatMetadata ( metadataValue ) ; } } addHeader ( value , metadataValue ? ) { this . addDatum ( value , metadataValue ) ; this . _headerCellCount ++ ; } param obj addDatumObject ( obj ) { this . length ++ ; const field = Col . COLUMN_FIELD_PREFIX + this . length . toString ( ) ; this . data [ field ] = obj ; } render ( field ) { return FormatHelper . formatValue ( this . _data [ field ] ) ; } get data ( ) : Object { return this . _data ; } set data ( value ) { this . _data = value ; } get length ( ) : number { return this . _length ; } set length ( value ) { this . _length = value ; } get metadata ( ) : Map < string , Map < string , string > > { return this . _metadata ; } set metadata ( value ) { value . forEach ( ( map , field ) => { this . metadataText [ field ] = FormatHelper . formatMetadata ( map ) ; } ) ; this . _metadata = value ; } get metadataText ( ) : Map < string , string > { return this . _metadataText ; } set metadataText ( value ) { this . _metadataText = value ; } get isHeaderRow ( ) : boolean { return this . _isHeaderRow ; } set isHeaderRow ( value ) { this . _isHeaderRow = value ; } get headerCellCount ( ) : number { return this . _headerCellCount ; } }