import { __rest } from "tslib";
import { jsx as _jsx } from "react/jsx-runtime";
import React from 'react';
import { FormControlLabel, MenuItem, TextField, Checkbox } from '@mui/material';
import { SCMetadataTypeFieldType } from '@selfcommunity/types';
import EmailTextField from '../EmailTextField';
import UrlTextField from '../UrlTextField';
import PhoneTextField from '../PhoneTextField';
const MetadataField = (props) => {
    // PROPS
    const { metadata, className = '', label } = props, rest = __rest(props, ["metadata", "className", "label"]);
    // RENDER
    let component = null;
    const _label = label !== null && label !== void 0 ? label : metadata.label;
    switch (metadata === null || metadata === void 0 ? void 0 : metadata.type) {
        case SCMetadataTypeFieldType.EMAIL:
            component = _jsx(EmailTextField, Object.assign({}, rest, { className: className, label: _label, required: metadata === null || metadata === void 0 ? void 0 : metadata.mandatory }));
            break;
        case SCMetadataTypeFieldType.URL:
            component = _jsx(UrlTextField, Object.assign({}, rest, { type: "url", className: className, label: _label, required: metadata === null || metadata === void 0 ? void 0 : metadata.mandatory }));
            break;
        case SCMetadataTypeFieldType.PHONE_NUMBER:
            component = _jsx(PhoneTextField, Object.assign({}, rest, { className: className, label: _label, required: metadata === null || metadata === void 0 ? void 0 : metadata.mandatory }));
            break;
        case SCMetadataTypeFieldType.ENUM:
            component = (_jsx(TextField, Object.assign({}, rest, { className: className, label: _label, required: metadata === null || metadata === void 0 ? void 0 : metadata.mandatory, select: true }, { children: metadata === null || metadata === void 0 ? void 0 : metadata.type_options.map((option) => (_jsx(MenuItem, Object.assign({ value: option }, { children: option }), option))) })));
            break;
        case SCMetadataTypeFieldType.CHECKBOX:
            const { value } = rest;
            component = (_jsx(FormControlLabel, { className: className, control: _jsx(Checkbox, { required: metadata === null || metadata === void 0 ? void 0 : metadata.mandatory, checked: Boolean(value) }), label: _label }));
            break;
        default:
            component = _jsx(TextField, Object.assign({}, rest, { className: className, label: _label, required: metadata === null || metadata === void 0 ? void 0 : metadata.mandatory }));
            break;
    }
    return _jsx(React.Fragment, { children: component });
};
export default MetadataField;
