"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FeedbackForm = FeedbackForm;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const uikit_1 = require("@gravity-ui/uikit");
const cn_1 = require("../../../utils/cn.js");
const i18n_1 = require("./i18n/index.js");
require("./FeedbackForm.css");
const b = (0, cn_1.block)('feedback-form');
/**
 * FeedbackForm - Reusable feedback form with reason selection and comment field
 *
 * This component provides a user-friendly way to collect feedback with multiple
 * selectable reasons (rendered as chips) and an optional comment field.
 * Can be used standalone or inside ActionPopup.
 *
 * @returns React element with feedback form
 */
function FeedbackForm({ options, onSubmit, reasonsLabel, commentLabel, commentPlaceholder, showComment = true, submitLabel, disabled = false, className, qa, }) {
    const [selectedReasons, setSelectedReasons] = (0, react_1.useState)([]);
    const [comment, setComment] = (0, react_1.useState)('');
    const handleReasonToggle = (reasonId) => {
        setSelectedReasons((prev) => prev.includes(reasonId) ? prev.filter((id) => id !== reasonId) : [...prev, reasonId]);
    };
    const handleSubmit = () => {
        onSubmit(selectedReasons, comment);
        setSelectedReasons([]);
        setComment('');
    };
    const isReasonSelected = (reasonId) => selectedReasons.includes(reasonId);
    // Submit button is disabled if no reason selected AND no comment provided (when comment is shown)
    const isSubmitDisabled = disabled || (selectedReasons.length === 0 && (!showComment || comment.trim() === ''));
    const displayCommentPlaceholder = commentPlaceholder || (0, i18n_1.i18n)('comment-placeholder');
    const displaySubmitLabel = submitLabel || (0, i18n_1.i18n)('submit');
    return ((0, jsx_runtime_1.jsxs)("div", { className: b(null, className), "data-qa": qa, children: [reasonsLabel && ((0, jsx_runtime_1.jsx)(uikit_1.Text, { variant: "subheader-2", "data-qa": qa ? `${qa}-reasons-label` : undefined, children: reasonsLabel })), (0, jsx_runtime_1.jsx)("div", { className: b('reasons'), "data-qa": qa ? `${qa}-reasons` : undefined, children: options.map((option) => {
                    const selected = isReasonSelected(option.id);
                    return ((0, jsx_runtime_1.jsx)(uikit_1.Button, { view: "normal", size: "m", selected: selected, onClick: () => handleReasonToggle(option.id), className: b('reason-chip', { selected }), "data-qa": qa ? `${qa}-reason-${option.id}` : undefined, disabled: disabled, children: option.label }, option.id));
                }) }), showComment && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [commentLabel && ((0, jsx_runtime_1.jsx)(uikit_1.Text, { variant: "subheader-2", "data-qa": qa ? `${qa}-comment-label` : undefined, children: commentLabel })), (0, jsx_runtime_1.jsx)(uikit_1.TextArea, { value: comment, onUpdate: setComment, placeholder: displayCommentPlaceholder, rows: 2, className: b('comment'), disabled: disabled, qa: qa ? `${qa}-comment` : undefined })] })), (0, jsx_runtime_1.jsx)(uikit_1.Button, { view: "action", size: "l", onClick: handleSubmit, disabled: isSubmitDisabled, className: b('submit'), qa: qa ? `${qa}-submit` : undefined, children: displaySubmitLabel })] }));
}
//# sourceMappingURL=FeedbackForm.js.map
