import React, { Component } from 'react';
import { GoogleMap, Marker } from 'react-google-maps';

import Dadata from 'cem/components/dadata';

import constants from 'cem/constants/properties';
const { addressMapping } = constants;

import UI from 'cem/components/ui';
import styles from 'cem/styles/id/main';
const {
  Grid: { Col },
  Form: { Group, Label, Input },
  Grid,
} = UI;

const containerProps = {
  style: {
    height: `22.5rem`,
  },
};

export default class extends Component {
  render() {
    const { formKey, dispatch, fields } = this.props;
    return (
      <section className={this.props.className}>
        <Grid.Row>
          <Col xs="20">
            <h2 className={styles.title}>Адрес</h2>
          </Col>
        </Grid.Row>

        <Grid.Row>
          <Col xs="17">
            <Group>
              <Label>Поиск адреса </Label>
              <Dadata.Location form="property" dispatch={dispatch} formKey={formKey} fieldParent="location" fields={addressMapping} />
            </Group>
          </Col>
          <Col sm="10">
            <Grid.Row>
              <Col sm="14" className={styles.wrapper}>
                <Grid.Row>
                  <Col sm="6">
                    <Group>
                      <Label>Индекс</Label>
                      <Input block type="text" {...fields.location.postalCode} />
                    </Group>
                  </Col>
                </Grid.Row>
                <Grid.Row>
                  <Col xs="20">
                    <Group>
                      <Label>Область</Label>
                      <Input block type="text" {...fields.location.administrativeArea} />
                    </Group>
                  </Col>
                </Grid.Row>
                <Grid.Row>
                  <Col xs="20">
                    <Group className={styles.resetMargin}>
                      <Label>Город</Label>
                      <Input block type="text" {...fields.location.locality} />
                    </Group>
                  </Col>
                </Grid.Row>
              </Col>
            </Grid.Row>
          </Col>
          <Col sm="10">
            <Grid.Row>
              <Col sm="14" className={styles.wrapper}>
                <Grid.Row>
                  <Col xs="20">
                    <Group>
                      <Label>Район</Label>
                      <Input block type="text" {...fields.location.subLocality} />
                    </Group>
                  </Col>
                </Grid.Row>
                <Grid.Row>
                  <Col xs="20">
                    <Group>
                      <Label>Улица</Label>
                      <Input block type="text" {...fields.location.street} />
                    </Group>
                  </Col>
                </Grid.Row>
                <Grid.Row>
                  <Col sm="5">
                    <Group className={styles.resetMargin}>
                      <Label>Дом</Label>
                      <Input block type="text" {...fields.location.house} />
                    </Group>
                  </Col>
                  {/* <Col sm="5">
                    <Group className={styles.resetMargin}>
                      <Label>Корпус</Label>
                      <Input block type="text" {...fields.location.block} />
                    </Group>
                  </Col>
                  <Col sm="5">
                    <Group className={styles.resetMargin}>
                      <Label>Строение</Label>
                      <Input block type="text" {...fields.location.building} />
                    </Group>
                  </Col> */}
                  <Col sm="5">
                    <Group className={styles.resetMargin}>
                      <Label>Квартира</Label>
                      <Input block type="text" {...fields.location.flatNumber} />
                    </Group>
                  </Col>
                </Grid.Row>
              </Col>
            </Grid.Row>
          </Col>
        </Grid.Row>
        <Grid.Row className={styles.mapWrapper}>
          <GoogleMap containerProps={containerProps} googleMapsApi={typeof google !== `undefined` ? google.maps : null} mapTypeId={ google.maps.MapTypeId.ROADMAP } zoom={12} defaultOptions={{ scrollwheel: false }} center={{ lat: -25.363882, lng: 131.044922 }}>
            <Marker position={{ lat: -25.363882, lng: 131.044922 }} key="1" />
          </GoogleMap>
        </Grid.Row>
      </section>
    );
  }
}
