var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useState } from 'react';
import Radio from 'src/components/Radio';
import { getSortType } from 'src/lib/common/helpers';
import Button from 'src/components/Button';
import { PatientType, SortTypes } from 'src/lib/types/types';
import css from '../FilterBar.module.scss';
import { _cx } from 'src/utility/class';
var cx = _cx(css);
var PatientAge = function (_a) {
    var filters = _a.filters, t = _a.t, onFilterApply = _a.onFilterApply, defaultSort = _a.defaultSort, closeModal = _a.closeModal;
    var patientType = filters.patientType;
    var _b = __read(useState(patientType || 'adult'), 2), age = _b[0], setAge = _b[1];
    var applyFilter = function () {
        var _a;
        var defSortType = (_a = getSortType(defaultSort)) !== null && _a !== void 0 ? _a : filters.sortType;
        var val = age === PatientType.TEEN ? SortTypes.teen : defSortType;
        onFilterApply('patientType', age, [{ key: 'sortType', value: val }]);
        closeModal();
    };
    return (_jsxs("div", { className: cx('form-group patient-age'), children: [_jsx("label", { className: "filter-title", children: t.result_age_label }), _jsxs("div", { className: "flex-space-between", children: [_jsx(Radio, { id: "age_adult", label: t.result_age_adult, value: PatientType.ADULT, checked: age === PatientType.ADULT, onChange: function () {
                            setAge('adult');
                        } }), _jsx(Radio, { id: "age_teen", label: t.result_age_teen, value: PatientType.TEEN, checked: age === PatientType.TEEN, onChange: function () {
                            setAge('teen');
                        } })] }), _jsx("hr", {}), _jsxs("div", { className: "flex-space-between", children: [_jsx(Button, { type: "submit", styleType: "cancel", onClick: closeModal, children: t.result_sort_button_cancel }), _jsx(Button, { type: "submit", styleType: "normal", onClick: applyFilter, children: t.result_filter_button_apply })] })] }));
};
export default PatientAge;
