/**
 * Copyright 2018 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */ import * as Api from '../../../api/v2' ; import * as common from '../../../../../common' ; public export interface TableColumn extends Api . GoogleActionsV2UiElementsTableCardColumnProperties { public align ? : Api . GoogleActionsV2UiElementsTableCardColumnPropertiesHorizontalAlignment ; } public export interface TableRow { public cells ? : ( Api . GoogleActionsV2UiElementsTableCardCell | string ) [ ] ; public dividerAfter ? : boolean ; } public export interface TableOptions { public title ? : string ; public subtitle ? : string ; public image ? : Api . GoogleActionsV2UiElementsImage ; public columns ? : ( TableColumn | string ) [ ] | number ; public columnProperties ? : ( TableColumn | string ) [ ] ; public rows : ( TableRow | string [ ] ) [ ] ; public dividers ? : boolean ; public buttons ? : Api . GoogleActionsV2UiElementsButton | Api . GoogleActionsV2UiElementsButton [ ] ; } const toColumnProperties = ( columns ) => columns . map ( column => typeof column === 'string' ? { header : column , } : ( { header : column . header , horizontalAlignment : column . horizontalAlignment || column . align , } as Api . GoogleActionsV2UiElementsTableCardColumnProperties ) ) ; example public export interface Table extends Api . GoogleActionsV2UiElementsTableCard { } export class Table implements Api . GoogleActionsV2UiElementsTableCard { public constructor ( options ) { this . title = options . title ; this . subtitle = options . subtitle ; this . image = options . image ; this . rows = options . rows . map ( row => Array . isArray ( row ) ? ( { cells : row . map ( text => ( { text } ) ) , dividerAfter : options . dividers , } as Api . GoogleActionsV2UiElementsTableCardRow ) : ( { cells : row . cells ! . map ( cell => typeof cell === 'string' ? { text : cell } : cell ) , dividerAfter : typeof row . dividerAfter === 'undefined' ? options . dividers : row . dividerAfter , } as Api . GoogleActionsV2UiElementsTableCardRow ) ) ; const { columnProperties , columns , buttons } = options ; if ( columnProperties ) { this . columnProperties = toColumnProperties ( columnProperties ) ; } if ( typeof columns !== 'undefined' ) { if ( ! this . columnProperties ) { this . columnProperties = [ ] ; } const properties = typeof columns === 'number' ? new Array < Api . GoogleActionsV2UiElementsTableCardColumnProperties > ( columns ) . fill ( { } ) : toColumnProperties ( columns ) ; properties . forEach ( ( v , i ) => { if ( ! this . columnProperties ! [ i ] ) { this . columnProperties ! [ i ] = properties [ i ] ; } } ) ; } if ( buttons ) { this . buttons = common . toArray ( buttons ) ; } } }