// @flow

import * as React from 'react'
import {View, FlatList} from 'react-native'
import * as c from '../components/colors'
import {ListSeparator, Title, Detail, ListRow} from '../components/list'
import {Row, Column} from '../components/layout'
import type {Building} from './types'

type Props = {
	buildings: Array<Building>,
	onSelect: string => any,
	scrollEnabled: boolean,
}

export class BuildingList extends React.Component<Props> {
	keyExtractor = (item: Building) => item.id

	onPress = (id: string) => this.props.onSelect(id)

	renderItem = ({item}: {item: Building}) => {
		const detail = item.address || (item.center || []).join(',') || ''
		return (
			<ListRow onPress={() => this.onPress(item.id)} spacing={{left: 12}}>
				<Row>
					<View
						alignSelf="center"
						backgroundColor={c.success}
						borderRadius={24}
						height={24}
						marginRight={8}
						width={24}
					/>
					<Column>
						<Title>{item.name}</Title>
						<Detail>{detail}</Detail>
					</Column>
				</Row>
			</ListRow>
		)
	}

	separator = () => <ListSeparator spacing={{left: 12}} />

	render() {
		return (
			<FlatList
				ItemSeparatorComponent={this.separator}
				contentInsetAdjustmentBehavior="automatic"
				data={this.props.buildings}
				keyExtractor={this.keyExtractor}
				keyboardDismissMode="on-drag"
				renderItem={this.renderItem}
				scrollEnabled={this.props.scrollEnabled}
			/>
		)
	}
}

@@ -46,14 +46,8 @@
 rt %7B
-View, 
 Flat
@@ -76,50 +76,8 @@
 ve'%0A
-import * as c from '../components/colors'%0A
 impo
@@ -149,57 +149,8 @@
 st'%0A
-import %7BRow, Column%7D from '../components/layout'%0A
 impo
@@ -640,193 +640,8 @@
 %7D%7D%3E%0A
-%09%09%09%09%3CRow%3E%0A%09%09%09%09%09%3CView%0A%09%09%09%09%09%09alignSelf=%22center%22%0A%09%09%09%09%09%09backgroundColor=%7Bc.success%7D%0A%09%09%09%09%09%09borderRadius=%7B24%7D%0A%09%09%09%09%09%09height=%7B24%7D%0A%09%09%09%09%09%09marginRight=%7B8%7D%0A%09%09%09%09%09%09width=%7B24%7D%0A%09%09%09%09%09/%3E%0A%09%09%09%09%09%3CColumn%3E%0A%09%09
 %09%09%09%09
@@ -667,18 +667,16 @@
 /Title%3E%0A
-%09%09
 %09%09%09%09%3CDet
@@ -701,34 +701,8 @@
 il%3E%0A
-%09%09%09%09%09%3C/Column%3E%0A%09%09%09%09%3C/Row%3E%0A
 %09%09%09%3C

remove dots from building list