import React from 'react';
import { StyleSheet } from 'react-native';
import { observer } from 'mobx-react';
import PropTypes from 'prop-types';
import Background from '../component/background';
import MainContent from '../component/main-content';
import { InputField, AmountInputField } from '../component/field';
import { Header, Title } from '../component/header';
import { CancelButton, PillButton, Button } from '../component/button';
import { BalanceLabel, BalanceLabelUnit } from '../component/label';
import Card from '../component/card';
import { FormStretcher, FormSubText } from '../component/form';
import { color } from '../component/style';

const styles = StyleSheet.create({
  balance: {
    marginTop: 40,
  },
  unit: {
    color: color.blackText,
  },
  subText: {
    paddingTop: 40,
    paddingBottom: 40,
  },
  doneBtn: {
    backgroundColor: color.blackDark,
  },
});

const PoolAddView = ({ store, nav, channel }) => (
  <Background color={color.blackDark}>
    <Header separator>
      <Button disabled onPress={() => {}} />
      <Title title="Search merchant" />
      <CancelButton onPress={() => nav.goChannels()} />
    </Header>
    <MainContent>
      <Card>
        <BalanceLabel style={styles.balance}>
          <AmountInputField
            autoFocus={true}
            value={store.channel.amount}
            onChangeText={amount => channel.setAmount({ amount })}
            onSubmitEditing={() => channel.connectAndOpen()}
          />
          <BalanceLabelUnit style={styles.unit}>
            {store.unitFiatLabel}
          </BalanceLabelUnit>
        </BalanceLabel>
        <FormStretcher>
          <InputField
            placeholder="https://merchant.domain"
            value={store.channel.pubkeyAtHost}
            onChangeText={pubkeyAtHost =>
              channel.setPubkeyAtHost({ pubkeyAtHost })
            }
            onSubmitEditing={() => channel.connectAndOpen()}
          />
        </FormStretcher>
        <FormSubText style={styles.subText}>
          search for merchant by name or web address.
        </FormSubText>
        <PillButton
          onPress={() => channel.connectAndOpen()}
          style={styles.doneBtn}
        >
          Done
        </PillButton>
      </Card>
    </MainContent>
  </Background>
);

PoolAddView.propTypes = {
  store: PropTypes.object.isRequired,
  nav: PropTypes.object.isRequired,
  channel: PropTypes.object.isRequired,
};

export default observer(PoolAddView);
