import React from 'react';
import PaymentMethodBase from './paymentmethodbase.jsx';

const propTypes = {
    enabled: React.PropTypes.bool
};

var id = 0;

export default class Authorize extends PaymentMethodBase {

    static get defaultProps(){
        return {
            enabled: true
        };
    }

    inputId(){
        return this.lastInputId = `payment__authorize-${id++}`;
    }

    getData() {
        return {
            'creditCardName': this.creditCardNameInput.value,
            'creditCardNumber': this.creditCardNumberInput.value,
            'expirationMonth': this.expirationMonthInput.value,
            'expirationYear': this.expirationYearInput.value,
            'creditCardSecurityCode': this.creditCardSecurityCodeInput.value,
        };
    }

    isValid() {
        if (this.creditCardNameInput.value
            && this.creditCardNumberInput.value
            && this.expirationMonthInput.value
            && this.expirationYearInput.value
            && this.creditCardSecurityCodeInput.value) {
            return true;
        }

        return false;
    }

    render() {
        const disabled = !this.props.enabled;
        return (
            <div className="payment__authorize">
                <label
                    htmlFor={`${this.inputId()}`}
                    className="payment__authorize__label">
                    Name on card
                </label>
                <input
                    id={`${this.lastInputId}`}
                    disabled={disabled}
                    ref={input => { this.creditCardNameInput = input; }}
                    className="payment__authorize__text-input payment__authorize__text-input--owner"
                    type="text"
                    onBlur={event => this.onInputBlur(event)} />
                <label
                    htmlFor={`${this.inputId()}`}
                    className="payment__authorize__label">
                    Card number
                </label>
                <input
                    id={`${this.lastInputId}`}
                    disabled={disabled}
                    ref={input => { this.creditCardNumberInput = input; }}
                    className="payment__authorize__text-input payment__authorize__text-input--card-number"
                    type="text"
                    onBlur={event => this.onInputBlur(event)} />
                <label
                    htmlFor={`${this.inputId()}`}
                    className="payment__authorize__label">
                    Expiration (month/year)
                </label>
                <input
                    id={`${this.lastInputId}`}
                    disabled={disabled}
                    ref={input => { this.expirationMonthInput = input; }}
                    className="payment__authorize__text-input payment__authorize__text-input--expiration-month"
                    type="text"
                    onBlur={event => this.onInputBlur(event)} />
                <input
                    disabled={disabled}
                    ref={input => { this.expirationYearInput = input; }}
                    className="payment__authorize__text-input payment__authorize__text-input--expiration-year"
                    type="text"
                    onBlur={event => this.onInputBlur(event)} />
                <label
                    htmlFor={`${this.inputId()}`}
                    className="payment__authorize__label">
                    Card security code (CVC/CVV)
                </label>
                <input
                    id={`${this.lastInputId}`}
                    disabled={disabled}
                    ref={input => { this.creditCardSecurityCodeInput = input; }}
                    className="payment__authorize__text-input payment__authorize__text-input--security-code"
                    type="text"
                    onBlur={event => this.onInputBlur(event)} />
            </div>
        );
    }
}

Authorize.propTypes = propTypes;