import React from 'react';
import PhotoListRadio from './PhotoListRadio/PhotoListRadio';
import { FONT_VARIANTS } from "../../../globalStyled";
import { isUndefined, getRandomString } from "../../../utils";
import { renderMark, RadioC } from "../Radio/Radio";
import { RadioText, RadioWrapperDiv, RadioWrapperInnerDiv, RadioTextBlockDiv, } from "../Radio/styled";
const { body2Regular } = FONT_VARIANTS;
export class RadioImg extends RadioC {
    render() {
        var _a, _b;
        const { props: { name, value, label, checked, withContext, img }, context: { fields }, } = this;
        let formValueImg = '';
        let error = '';
        if (withContext) {
            formValueImg = !fields[name] ? '' : fields[name].value;
            error = !fields[name] ? '' : (_b = (_a = fields[name]) === null || _a === void 0 ? void 0 : _a.validation) === null || _b === void 0 ? void 0 : _b.errorMessage;
        }
        const checkedInit = isUndefined(checked) ? formValueImg === value : checked;
        return (React.createElement(RadioWrapperDiv, null,
            React.createElement(RadioWrapperInnerDiv, null,
                renderMark({
                    error,
                    checked: checkedInit,
                    onClick: () => {
                        this.onClick();
                    },
                }),
                React.createElement("input", { type: "radio", name: name, value: value || '', checked: checkedInit, onChange: ({ currentTarget }) => {
                        this.onChange({ value: currentTarget.value });
                    }, ref: this.$ref }),
                (label || img) && (React.createElement(RadioTextBlockDiv, null,
                    label && (React.createElement(RadioText, { forwardedAs: "div", variant: body2Regular },
                        React.createElement("span", { onClick: () => {
                                this.onClick();
                            } }, label))),
                    img && (React.createElement(PhotoListRadio, { photos: [
                            {
                                link: img,
                                id: getRandomString(),
                                createTime: '',
                                name: '',
                            },
                        ], checked: checkedInit, onClick: () => {
                            this.onClick();
                        } })))))));
    }
}
