"use strict";
/**
 * react-native-check-box
 * Checkbox component for react native, it works on iOS and Android
 * https://github.com/crazycodeboy/react-native-check-box
 * Email:crazycodeboy@gmail.com
 * Blog:http://www.devio.org
 * @flow
 */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = __importStar(require("react"));
const react_native_1 = require("react-native");
const prop_types_1 = __importDefault(require("prop-types"));
const deprecated_react_native_prop_types_1 = require("deprecated-react-native-prop-types");
const ViewPropTypes = deprecated_react_native_prop_types_1.ViewPropTypes || react_native_1.View.propTypes;
class CheckBox extends react_1.Component {
    constructor(props) {
        super(props);
    }
    onClick() {
        this.props.onClick();
    }
    _renderLeft() {
        if (this.props.leftTextView)
            return this.props.leftTextView;
        if (!this.props.leftText)
            return null;
        return (react_1.default.createElement(react_native_1.Text, { style: [styles.leftText, this.props.leftTextStyle] }, this.props.leftText));
    }
    _renderRight() {
        if (this.props.rightTextView)
            return this.props.rightTextView;
        if (!this.props.rightText)
            return null;
        return (react_1.default.createElement(react_native_1.Text, { style: [styles.rightText, this.props.rightTextStyle] }, this.props.rightText));
    }
    _renderImage() {
        if (this.props.isIndeterminate) {
            return this.props.indeterminateImage ? this.props.indeterminateImage : this.genCheckedImage();
        }
        if (this.props.isChecked) {
            return this.props.checkedImage ? this.props.checkedImage : this.genCheckedImage();
        }
        else {
            return this.props.unCheckedImage ? this.props.unCheckedImage : this.genCheckedImage();
        }
    }
    _getCheckedCheckBoxColor() {
        return this.props.checkedCheckBoxColor ? this.props.checkedCheckBoxColor : this.props.checkBoxColor;
    }
    _getUncheckedCheckBoxColor() {
        return this.props.uncheckedCheckBoxColor ? this.props.uncheckedCheckBoxColor : this.props.checkBoxColor;
    }
    _getTintColor() {
        return this.props.isChecked ? this._getCheckedCheckBoxColor() : this._getUncheckedCheckBoxColor();
    }
    genCheckedImage() {
        let source;
        if (this.props.isIndeterminate) {
            source = require('./img/ic_indeterminate_check_box.png');
        }
        else {
            source = this.props.isChecked ? require('./img/ic_check_box.png') : require('./img/ic_check_box_outline_blank.png');
        }
        return (react_1.default.createElement(react_native_1.Image, { source: source, style: { tintColor: this._getTintColor() } }));
    }
    render() {
        return (react_1.default.createElement(react_native_1.TouchableHighlight, { style: this.props.style, onPress: () => this.onClick(), underlayColor: 'transparent', disabled: this.props.disabled },
            react_1.default.createElement(react_native_1.View, { style: styles.container },
                this._renderLeft(),
                this._renderImage(),
                this._renderRight())));
    }
}
exports.default = CheckBox;
CheckBox.propTypes = Object.assign(Object.assign({}, ViewPropTypes), { leftText: prop_types_1.default.string, leftTextView: prop_types_1.default.element, rightText: prop_types_1.default.string, leftTextStyle: prop_types_1.default.oneOfType([
        prop_types_1.default.string,
        prop_types_1.default.number,
        prop_types_1.default.object,
    ]), rightTextView: prop_types_1.default.element, rightTextStyle: prop_types_1.default.oneOfType([
        prop_types_1.default.string,
        prop_types_1.default.number,
        prop_types_1.default.object,
    ]), checkedImage: prop_types_1.default.element, unCheckedImage: prop_types_1.default.element, onClick: prop_types_1.default.func.isRequired, isChecked: prop_types_1.default.bool.isRequired, isIndeterminate: prop_types_1.default.bool.isRequired, checkBoxColor: prop_types_1.default.string, checkedCheckBoxColor: prop_types_1.default.string, uncheckedCheckBoxColor: prop_types_1.default.string, disabled: prop_types_1.default.bool });
CheckBox.defaultProps = {
    isChecked: false,
    isIndeterminate: false,
    leftTextStyle: {},
    rightTextStyle: {}
};
const styles = react_native_1.StyleSheet.create({
    container: {
        flexDirection: 'row',
        alignItems: 'center'
    },
    leftText: {
        flex: 1,
    },
    rightText: {
        flex: 1,
        marginLeft: 10
    }
});
//# sourceMappingURL=checkbox.js.map