import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
import { getStatusColor, getStatus, getStatusLabel } from '../../../utils/getStatusColor/getStatusColor.js';
import Checkbox from '../../Checkbox/Checkbox.js';
import Icon from '../../Icon/Icon.js';
import StatusButton from '../../StatusButton/StatusButton.js';
import Tooltip from '../../Tooltip/Tooltip.js';
import Typography from '../../Typography/Typography.js';
import StepResultStats from './StepResultStats.js';

const StepsTitle = ({ isHeaderRequired, isViewPrivilegeMode, onAccordionClick, isBulkEnable, showActionCell, handleMainCheckbox, isAllSelected, isPartialSelected, tableMeta = [], title, totalRows, expanded, actionCell, row, metaData, isClientSide, isMaximize, }) => {
    const columnWidths = tableMeta?.map((col) => col.width);
    const getWidth = (index) => {
        const width = columnWidths[index] ?? 0;
        switch (index) {
            case 0:
                return width + 110;
            case 1:
                return width + (width > 300 ? 60 : 70);
            case 2:
                return width + 20;
            default:
                return 0;
        }
    };
    const getStepResultStatsWidth = () => {
        const margin = row?.marginLeft ?? 0;
        const isChecked = isAllSelected?.(title, totalRows) ||
            isPartialSelected?.(title, totalRows);
        if (isChecked && title === 'Steps') {
            return 200 - margin;
        }
        const TITLE_WIDTH_MAP = {
            'Depends on Scripts': 240,
            'Post Conditions': 230,
            'Pre Conditions': 260,
            Steps: 310,
        };
        const DEFAULT_WIDTH = 250;
        const baseWidth = isMaximize
            ? 350
            : (TITLE_WIDTH_MAP[title] ?? DEFAULT_WIDTH);
        return baseWidth - margin;
    };
    return (jsxs("article", { className: "step-title-article", style: {
            ...(!isHeaderRequired &&
                !isClientSide && { backgroundColor: 'var(--hover-color)' }),
        }, children: [jsx("div", { style: { width: `${getWidth(0)}px` }, children: jsxs("div", { className: "accordion-header", style: {
                        paddingLeft: isViewPrivilegeMode || isClientSide ? '8px' : '24px',
                    }, children: [!isViewPrivilegeMode && !isClientSide && (jsx(Checkbox, { onChange: (e) => handleMainCheckbox(title, e.target.checked), checked: isAllSelected(title, totalRows), partial: isPartialSelected(title, totalRows), disabled: totalRows === 0 })), jsx("div", { className: "header-title", children: jsx(Typography, { as: "div", fontWeight: "semi-bold", color: isClientSide ? 'var(--brand-color)' : 'var(--nlp-option-color)', cursor: "default", lineHeight: "18px", children: title }) }), isClientSide ? (
                        //TODO: added temporary div will replace with add Icon
                        jsx("div", { style: { padding: '12px' } })) : (jsx("div", { className: `accordion-arrow ${expanded ? 'expanded' : ''}`, onClick: () => onAccordionClick(title), children: jsx(Icon, { name: "arrow_right", color: expanded ? 'var(--brand-color)' : 'var(--default-color)', width: 16, height: 16, className: "steps-arrow-svg" }) })), jsxs("div", { className: "ff_action_container", children: [metaData && (jsx(StepResultStats, { metaData: metaData, width: getStepResultStatsWidth() })), showActionCell && !isBulkEnable && jsx(Fragment, { children: actionCell(row) })] })] }) }), metaData?.message && (jsx("div", { className: "step-result", style: {
                    width: `${getWidth(1)}px`,
                }, children: jsx(Tooltip, { title: metaData?.message, placement: "bottom-start", children: jsx(Typography, { lineHeight: "18px", as: "div", className: "step-result-text", color: getStatusColor(metaData?.status), children: metaData?.message }) }) })), metaData?.status && (jsx("div", { className: "step-result", style: { width: `${getWidth(2)}px` }, children: jsx(StatusButton, { label: getStatusLabel(metaData?.status), status: getStatus(metaData?.status), children: metaData?.status }) }))] }));
};

export { StepsTitle as default };
//# sourceMappingURL=StepsTitle.js.map
