import React, { Component } from 'react';
import {Linking, StyleSheet, ScrollView, Text, Platform, View, Image, TouchableHighlight,
TouchableOpacity} from "react-native";
import HTMLView from 'react-native-htmlview';
import moment from "moment";
import {Button, Icon, Text as NBText} from "native-base";
moment.locale('nb');
const CHATEAU_NEUF_ADDRESS = 'Chateau Neuf, Slemdalsveien 15, 0369 Oslo';
export default class EventDetail extends Component {
_formatTime(time) {
return moment(time).format('HH:mm');
}
_formatMonth(time) {
return moment(time).format('MMM');
}
_formatDay(time) {
return moment(time).format('DD.');
}
_formatLocalDay(time) {
return moment(time).format('ddd')
}
_formatYear(time) {
return moment(time).format('YYYY');
}
_formatRelative(time) {
return moment(time).fromNow();
}
_formatLocation() {
if(this.props.item.venue !== 'Annetsteds') {
return CHATEAU_NEUF_ADDRESS;
}
return 'Ukjent adresse'
}
_formatTicketText() {
/* FIXME: This should be handled by API */
const {item} = this.props;
let reg_kr = '';
let mem_kr = '';
if (item.price_regular === '0') {
item.price_regular = 'Gratis'
}
if (item.price_member === '0') {
item.price_member = 'Gratis'
}
if (item.price_regular !== 'Gratis') {
reg_kr = " kr"
}
if (item.price_member !== 'Gratis') {
mem_kr = " kr"
}
let text = '';
if (item.price_regular && item.price_member) {
text = `Pris: ${item.price_regular}${reg_kr} / Medlemmer: ${item.price_member}${mem_kr}`;
}
else if (item.price_regular) {
text = `Pris: ${item.price_regular}${reg_kr}`;
}
else if (item.price_member) {
text = `Pris (Medlemmer): ${item.price_member}${mem_kr}`;
} else {
return '';
}
return text;
}
onUrlPress(link) {
Linking.openURL(link);
}
onLocationPress(venue) {
if( venue !== 'Annetsteds' ) {
Linking.openURL(`https://www.google.com/maps/dir/?api=1&destination=${CHATEAU_NEUF_ADDRESS}`);
}
}
showPriceAndTicket() {
const {item} = this.props;
const text = this._formatTicketText();
if(text === '') {
return;
}
if(item.ticket_url) {
return (
this.onUrlPress(item.ticket_url)}>
{text}
Kjøp billett
);
}
return (
{text}
Billett i døra
)
}
showFacebutton() {
const {item} = this.props;
if (!item.facebook_url) { return;}
return (
this.onUrlPress(item.facebook_url)} style={styles.metaInner}>
På Facebook
);
}
showImage() {
const {item} = this.props;
if (item.thumbnail.medium_large) {
return ;
}
}
showYear() {
const {item} = this.props;
if(moment().year() !== moment(item.start_time).year()) {
return {this._formatYear(item.start_time)}
}
}
render() {
const {item} = this.props;
return (
{this.showImage()}
{/* Date and title */}
{this._formatDay(item.start_time)}
{this._formatMonth(item.start_time)}
{this.showYear()}
{item.title.decoded}
{/* Time and calendar */}
{this._formatLocalDay(item.start_time)} kl. {this._formatTime(item.start_time)} - {this._formatTime(item.end_time)}
{this._formatRelative(item.start_time)}
{/* Location and maps */}
this.onLocationPress(item.venue)}>
{item.venue}
{this._formatLocation()}
{this.showPriceAndTicket()}
{this.showFacebutton()}
)
}
}
const styles = StyleSheet.create({
dateAndTitle: {
flexDirection: 'row',
marginBottom: 8
},
titleContainer: {
paddingLeft: 10,
justifyContent: 'center',
flex: 4,
},
title: {
fontSize: 20,
fontWeight: 'bold',
color: '#000',
},
card: {
borderColor: '#e1e8ee',
borderWidth: 1,
...Platform.select({
ios: {
shadowColor: 'rgba(0,0,0, .2)',
shadowOffset: {height: 0, width: 0},
shadowOpacity: 1,
shadowRadius: 1,
},
android: {
elevation: 1,
},
}),
padding: 8,
margin: 8,
backgroundColor: '#fff',
},
image: {
height: 260,
width: null
},
time: {
fontSize: 14,
color: '#666'
},
metaInner: {
flexDirection: 'row',
marginVertical: 8,
},
metaIcon: {
width: 16,
paddingTop: 3,
marginHorizontal: 8,
marginVertical: 8,
},
metaText: {
color: '#000',
},
metaSubtitle: {
color: '#666',
},
content: {
borderTopWidth: StyleSheet.hairlineWidth,
borderColor: '#ccc',
marginTop: 8,
paddingTop: 10,
},
dateContainer: {
flex: 1,
justifyContent: 'center',
},
dateCard: {
borderColor: '#e1e8ee',
borderWidth: 1,
...Platform.select({
ios: {
shadowColor: 'rgba(0,0,0, .2)',
shadowOffset: {height: 0, width: 0},
shadowOpacity: 2,
shadowRadius: 2,
},
android: {
elevation: 1,
},
}),
backgroundColor: '#fff',
paddingBottom: 6,
width: 62,
},
day: {
paddingTop: 5,
fontSize: 20,
color: '#000',
textAlign: 'center',
},
month: {
textAlign: 'center',
paddingHorizontal: 16,
},
year: {
fontSize: 10,
color: '#fff',
backgroundColor: '#f58220',
textAlign: 'center',
paddingRight: 20,
paddingBottom: 3,
paddingLeft: 20,
paddingTop: 3,
},
icons: {
fontSize: 16,
},
});
//FIXME: Ninja margin
const HTMLStyles = StyleSheet.create({
p: {
fontSize: 16,
marginBottom: -30,
color: '#000',
},
ul: {
fontSize: 16,
color: '#000',
marginTop: -20,
marginBottom: -30,
},
});