import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { EditorWarning } from "../EditorWarning";
import { useEditContext } from "../client/editContext";
import { Button } from "../../components/ui/button";
import { getCreateAndSwitchToNewVersionCommand } from "../commands/createVersionCommand";
export function FinalWorkflowStateReadOnly({ item }) {
    const editContext = useEditContext();
    if (!editContext)
        return;
    // Admins may edit final-state items; this warning is only for non-admin users.
    if (editContext.user?.isAdministrator)
        return;
    // Only show when workflow write access is blocked.
    if (item.canWriteWorkflow)
        return;
    // Prefer backend-provided flag; final-state items typically aren't in the workbox.
    const isFinalState = item.isFinalState ??
        editContext.workboxItems.find((wb) => wb.item.id === item.id &&
            wb.item.language === item.language &&
            wb.item.version === item.version)?.isFinalState ??
        false;
    if (!isFinalState)
        return;
    const canCreateVersion = !!item.canLock;
    return (_jsxs(EditorWarning, { title: "This item is in a final workflow state", severity: "warning", children: [_jsx("p", { className: "mb-2", children: "Non-admin users can\u2019t edit items in a final workflow state. Create a new version to continue editing." }), _jsx("div", { children: _jsx(Button, { size: "sm", onClick: async () => {
                        await editContext.executeCommand({
                            command: getCreateAndSwitchToNewVersionCommand({}),
                            event: new Event("click"),
                        });
                    }, disabled: !canCreateVersion, children: "Create new version" }) })] }));
}
//# sourceMappingURL=FinalWorkflowStateReadOnly.js.map