import React, { Component } from 'react';

import Select from 'react-select';
import currencies from 'cem/constants/currencies';

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

import styles from 'cem/styles/id/main';

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

export default class extends Component {
  render() {
    const { saleDeal, rentDeal } = this.props.fields;
    return (
      <section className={this.props.className}>
        <Grid.Row>
          <Col xs="20">
            <h2 className={styles.title}>Условия сделок</h2>
          </Col>
        </Grid.Row>

        <Grid.Row>
          <Col sm="10">
            <h3 className={styles.subTitle}>Продажа</h3>
            <Grid.Row>
              <Col sm="14" className={styles.wrapper}>
                <Grid.Row>
                  <Col sm="10">
                    <Group>
                      <Label>Цена</Label>
                      <Input block type="text" {...saleDeal.price} />
                    </Group>
                  </Col>
                  <Col sm="10">
                    <Group>
                      <Label>Валюта</Label>
                      <div className={styles.selectWrapper}>
                        <Select block options={currencies} {...saleDeal.currency} labelKey="title" valueKey="id" onBlur={() => ({})} />
                      </div>
                    </Group>
                  </Col>
                </Grid.Row>

                <Grid.Row>
                  <Col sm="10">
                    <Group>
                      <Label>Тип сделки</Label>
                      <div className={styles.selectWrapper}>
                        <Select block options={options.saleKinds} {...saleDeal.kind} labelKey="title" valueKey="id" onBlur={() => ({})} />
                      </div>
                    </Group>
                  </Col>
                </Grid.Row>

                <Grid.Row>
                  <Col sm="6">
                    <Group>
                      <Label><Input type="checkbox" {...saleDeal.isMortgage} /> ипотека</Label>
                    </Group>
                  </Col>
                  <Col sm="6">
                    <Group>
                      <Label><Input type="checkbox" {...saleDeal.isInstallment} /> рассрочка</Label>
                    </Group>
                  </Col>
                  <Col sm="6">
                    <Group>
                      <Label><Input type="checkbox" {...saleDeal.isResale} defaultValue={false} /> вторичка</Label>
                    </Group>
                  </Col>
                  <Col sm="6">
                    <Group>
                      <Label><Input type="checkbox" {...saleDeal.isBargain} /> торг</Label>
                    </Group>
                  </Col>
                </Grid.Row>

                <Grid.Row>
                  <Col sm="10">
                    <Label block>Форма комиссии</Label>
                    <Group>
                      <Label block><Input type="radio" {...saleDeal.isAgentFixed} value="false" checked={saleDeal.isAgentFixed.value === `false`} /> Процент </Label>
                      <Label block><Input type="radio" {...saleDeal.isAgentFixed} value="true" checked={saleDeal.isAgentFixed.value === `true`} /> Фиксированная сумма</Label>
                    </Group>
                  </Col>
                </Grid.Row>

                {saleDeal.isAgentFixed.value && (
                  <Grid.Row>
                    <Col sm="10">
                      {saleDeal.isAgentFixed.value === `true` &&
                        <Group>
                          <Label>Сумма комиссии</Label>
                          <Input block type="text" {...saleDeal.agentFixedPrice.price} />
                        </Group>
                      }
                      {saleDeal.isAgentFixed.value !== `true` &&
                        <Group>
                          <Label>Процент комиссии</Label>
                          <Input block type="text" {...saleDeal.agentFee} />
                        </Group>
                      }
                    </Col>
                    <Col sm="10">
                      {saleDeal.isAgentFixed.value === `true` && (
                        <Group>
                          <Label>Валюта</Label>
                          <Select block options={currencies} {...saleDeal.agentFixedPrice.currency} labelKey="title" valueKey="id" onBlur={() => {}} />
                        </Group>
                      )}
                    </Col>
                  </Grid.Row>
                )}
              </Col>
            </Grid.Row>
          </Col>

          <Col sm="10">
            <h3 className={styles.subTitle}>Аренда</h3>
            <Grid.Row>
              <Col sm="14" className={styles.wrapper}>
                <Grid.Row>
                  <Col sm="10">
                    <Group>
                      <Label>Цена</Label>
                      <Input block type="text" {...rentDeal.price} onBlur={() => {}} />
                    </Group>
                  </Col>
                  <Col sm="10">
                    <Group>
                      <Label>Валюта</Label>
                      <div className={styles.selectWrapper}>
                        <Select {...rentDeal.currency} options={currencies} valueKey="id" labelKey="title" onBlur={() => {}} />
                      </div>
                    </Group>
                  </Col>
                </Grid.Row>

                <Grid.Row>
                  <Col sm="10">
                    <Group>
                      <Label>Период аренды</Label>
                      <div className={styles.selectWrapper}>
                        <Select {...rentDeal.period} options={options.rentPeriods} valueKey="id" labelKey="title" onBlur={() => {}} />
                      </div>
                    </Group>
                  </Col>
                  <Col sm="10">
                    <Group>
                      <Label>Залог</Label>
                      <div className={styles.selectWrapper}>
                        <Select {...rentDeal.deposit} options={options.depositAmounts} valueKey="id" labelKey="title" onBlur={() => {}} />
                      </div>
                    </Group>
                  </Col>
                </Grid.Row>

                <Grid.Row>
                  <Col sm="6">
                    <Group>
                      <Label><Input type="checkbox" {...rentDeal.isAllowedChildren} /> с детьми</Label>
                    </Group>
                  </Col>
                  <Col sm="7">
                    <Group>
                      <Label><Input type="checkbox" {...rentDeal.isAllowedPets} /> с животными</Label>
                    </Group>
                  </Col>
                </Grid.Row>

                <Grid.Row>
                  <Col sm="10">
                    <Label block>Форма комиссии</Label>
                    <Group>
                      <Label block><Input type="radio" {...rentDeal.isAgentFixed} value="false" checked={rentDeal.isAgentFixed.value === `false`} /> Процент </Label>
                      <Label block><Input type="radio" {...rentDeal.isAgentFixed} value="true" checked={rentDeal.isAgentFixed.value === `true`} /> Фиксированная сумма</Label>
                    </Group>
                  </Col>
                </Grid.Row>

                {rentDeal.isAgentFixed.value && (
                  <Grid.Row>
                    <Col sm="10">
                      {rentDeal.isAgentFixed.value === `true` &&
                        <Group>
                          <Label>Сумма комиссии</Label>
                          <Input block type="text" {...rentDeal.agentFixedPrice.price} />
                        </Group>
                      }
                      {rentDeal.isAgentFixed.value !== `true` &&
                        <Group>
                          <Label>Процент комиссии</Label>
                          <Input block type="text" {...rentDeal.agentFee} />
                        </Group>
                      }
                    </Col>
                    <Col sm="10">
                      {rentDeal.isAgentFixed.value === `true` && (
                        <Group>
                          <Label>Валюта</Label>
                          <Select block options={currencies} {...rentDeal.agentFixedPrice.currency} labelKey="title" valueKey="id" onBlur={() => {}} />
                        </Group>
                      )}
                    </Col>
                  </Grid.Row>
                )}
              </Col>
            </Grid.Row>
          </Col>
        </Grid.Row>
      </section>
    );
  }
}
