import React from 'react';
import { Link } from 'react-router';

import RetinaImage from 'react-retina-image';
import { FormattedCurrency } from 'react-formatted';
import { kind, condition } from 'cem/constants/properties/dictionaries';

import cn from 'classnames';
import styles from 'cem/styles/ui/card';

import UI from 'cem/components/ui';
const { Grid, Media } = UI;

const states = {
  active: `success`,
  draft: `danger`,
};

const Image = ({ image }) => (
  image ? <RetinaImage className={styles.imageProperties} src={`${image.url}-256`} height="175" /> : <UI.Image className={styles.imageProperties} src={require(`url!cem/assets/placeholder-photo`)} className={styles.placeholder} height="175" />
);

const Description = ({ property }) => (
  <div className={cn(styles.cardWrapper, styles.resetPadding)}>
    <Grid.Container fluid>
      <Grid.Row>
        <Grid.Col sm="15">
          {/* <Grid.Row className={styles.pushedBottom}>
            <Grid.Col className={styles.pushedBottom} sm="8">
              <p className={styles.title}>{property.metro}</p>
              <h2 className={styles.fullName}>{property.address}</h2>
            </Grid.Col>
          </Grid.Row> */}
          <Grid.Row>
            <Grid.Col sm="2">
              <dl className={styles.list}>
                <dt className={styles.listTitle}>ID</dt>
                <dd className={styles.listDescription}>{property.id}</dd>
              </dl>
            </Grid.Col>
            <Grid.Col sm="3">
              <dl className={styles.list}>
                <dt className={styles.listTitle}>Тип</dt>
                <dd className={styles.listDescription}>
                  {property.kind && kind[property.kind]}
                  {!property.kind && `Не указан`}
                </dd>
              </dl>
            </Grid.Col>

            {property.specification && (
              <Grid.Col sm="3">
                <dl className={styles.list}>
                  <dt className={styles.listTitle}>Площадь</dt>
                  <dd className={styles.listDescription}>
                    {property.specification.totalArea && `${property.specification.totalArea} м²`}
                    {!property.specification.totalArea && `Не указана`}
                  </dd>
                </dl>
              </Grid.Col>
            )}

            {property.specification && (
              <Grid.Col sm="3">
                <dl className={styles.list}>
                  <dt className={styles.listTitle}>Комнат</dt>
                  <dd className={styles.listDescription}>
                    {property.specification.roomsCount}
                    {!property.specification.roomsCount && `Не указано`}
                  </dd>
                </dl>
              </Grid.Col>
            )}

            {property.information && (
              <Grid.Col sm="4">
                <dl className={styles.list}>
                  <dt className={styles.listTitle}>Состояние</dt>
                  <dd className={styles.listDescription}>
                    {property.information.condition && condition[property.information.condition]}
                    {!property.information.condition && `Не указано`}
                  </dd>
                </dl>
              </Grid.Col>
            )}
          </Grid.Row>
        </Grid.Col>
        <Grid.Col sm="5">
          <Grid.Row>
            {property.saleDeal && (
              <Grid.Col xs="20">
                <div className={styles.objectPrice}>
                  <p className={styles.title}>Продажа</p>
                  <h2 className={styles.fullName}>
                    <FormattedCurrency symbol={property.saleDeal.currency} value={property.saleDeal.price} />
                  </h2>
                </div>
              </Grid.Col>
            )}
            {property.rentDeal && (
              <Grid.Col xs="20">
                <div className={styles.objectPrice}>
                  <p className={styles.title}>Аренда</p>
                  <h2 className={styles.fullName}>
                    <FormattedCurrency symbol={property.rentDeal.currency} value={property.rentDeal.price} />
                  </h2>
                </div>
              </Grid.Col>
            )}
          </Grid.Row>
        </Grid.Col>
      </Grid.Row>
    </Grid.Container>
  </div>
);

export default (props) => (
  <Link to={`/properties/${props.property.id}/about`} className={cn(styles.card, styles[states[props.property.state]])}>
    <Media left={<Image image={props.property.images[0]} />} body={<Description {...props} />} />
  </Link>
);
