"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = tslib_1.__importDefault(require("react"));
const material_1 = require("@mui/material");
const types_1 = require("@selfcommunity/types");
const EmailTextField_1 = tslib_1.__importDefault(require("../EmailTextField"));
const UrlTextField_1 = tslib_1.__importDefault(require("../UrlTextField"));
const PhoneTextField_1 = tslib_1.__importDefault(require("../PhoneTextField"));
const MetadataField = (props) => {
    // PROPS
    const { metadata, className = '', label } = props, rest = tslib_1.__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 types_1.SCMetadataTypeFieldType.EMAIL:
            component = (0, jsx_runtime_1.jsx)(EmailTextField_1.default, Object.assign({}, rest, { className: className, label: _label, required: metadata === null || metadata === void 0 ? void 0 : metadata.mandatory }));
            break;
        case types_1.SCMetadataTypeFieldType.URL:
            component = (0, jsx_runtime_1.jsx)(UrlTextField_1.default, Object.assign({}, rest, { type: "url", className: className, label: _label, required: metadata === null || metadata === void 0 ? void 0 : metadata.mandatory }));
            break;
        case types_1.SCMetadataTypeFieldType.PHONE_NUMBER:
            component = (0, jsx_runtime_1.jsx)(PhoneTextField_1.default, Object.assign({}, rest, { className: className, label: _label, required: metadata === null || metadata === void 0 ? void 0 : metadata.mandatory }));
            break;
        case types_1.SCMetadataTypeFieldType.ENUM:
            component = ((0, jsx_runtime_1.jsx)(material_1.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) => ((0, jsx_runtime_1.jsx)(material_1.MenuItem, Object.assign({ value: option }, { children: option }), option))) })));
            break;
        case types_1.SCMetadataTypeFieldType.CHECKBOX:
            const { value } = rest;
            component = ((0, jsx_runtime_1.jsx)(material_1.FormControlLabel, { className: className, control: (0, jsx_runtime_1.jsx)(material_1.Checkbox, { required: metadata === null || metadata === void 0 ? void 0 : metadata.mandatory, checked: Boolean(value) }), label: _label }));
            break;
        default:
            component = (0, jsx_runtime_1.jsx)(material_1.TextField, Object.assign({}, rest, { className: className, label: _label, required: metadata === null || metadata === void 0 ? void 0 : metadata.mandatory }));
            break;
    }
    return (0, jsx_runtime_1.jsx)(react_1.default.Fragment, { children: component });
};
exports.default = MetadataField;
