'use client';
import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
import React, { useEffect } from 'react';
import { useRouteCache } from '../../providers/RouteCache/index.js';
import { useRouteTransition } from '../../providers/RouteTransition/index.js';
import { useTranslation } from '../../providers/Translation/index.js';
import { isClientUserObject } from '../../utilities/isClientUserObject.js';
import { Button } from '../Button/index.js';
import { Modal, useModal } from '../Modal/index.js';
import './index.scss';
const modalSlug = 'document-locked';
const baseClass = 'document-locked';
const formatDate = (date)=>{
    if (!date) {
        return '';
    }
    return new Intl.DateTimeFormat('en-US', {
        day: 'numeric',
        hour: 'numeric',
        hour12: true,
        minute: 'numeric',
        month: 'short',
        year: 'numeric'
    }).format(new Date(date));
};
export const DocumentLocked = ({ handleGoBack, isActive, onReadOnly, onTakeOver, updatedAt, user })=>{
    const { closeModal, openModal } = useModal();
    const { t } = useTranslation();
    const { clearRouteCache } = useRouteCache();
    const { startRouteTransition } = useRouteTransition();
    useEffect(()=>{
        if (isActive) {
            openModal(modalSlug);
        } else {
            closeModal(modalSlug);
        }
    }, [
        isActive,
        openModal,
        closeModal
    ]);
    return /*#__PURE__*/ _jsxDEV(Modal, {
        className: baseClass,
        // Fixes https://github.com/payloadcms/payload/issues/13778
        closeOnBlur: false,
        onClose: ()=>{
            startRouteTransition(()=>handleGoBack());
        },
        slug: modalSlug,
        children: /*#__PURE__*/ _jsxDEV("div", {
            className: `${baseClass}__wrapper`,
            children: [
                /*#__PURE__*/ _jsxDEV("div", {
                    className: `${baseClass}__content`,
                    children: [
                        /*#__PURE__*/ _jsxDEV("h1", {
                            children: t('general:documentLocked')
                        }, void 0, false, {
                            fileName: "src/elements/DocumentLocked/index.tsx",
                            lineNumber: 65,
                            columnNumber: 11
                        }, this),
                        /*#__PURE__*/ _jsxDEV("p", {
                            children: [
                                /*#__PURE__*/ _jsxDEV("strong", {
                                    children: isClientUserObject(user) ? user.email ?? user.id : `${t('general:user')}: ${user}`
                                }, void 0, false, {
                                    fileName: "src/elements/DocumentLocked/index.tsx",
                                    lineNumber: 67,
                                    columnNumber: 13
                                }, this),
                                ' ',
                                t('general:currentlyEditing')
                            ]
                        }, void 0, true, {
                            fileName: "src/elements/DocumentLocked/index.tsx",
                            lineNumber: 66,
                            columnNumber: 11
                        }, this),
                        /*#__PURE__*/ _jsxDEV("p", {
                            children: [
                                t('general:editedSince'),
                                " ",
                                /*#__PURE__*/ _jsxDEV("strong", {
                                    children: formatDate(updatedAt)
                                }, void 0, false, {
                                    fileName: "src/elements/DocumentLocked/index.tsx",
                                    lineNumber: 73,
                                    columnNumber: 40
                                }, this)
                            ]
                        }, void 0, true, {
                            fileName: "src/elements/DocumentLocked/index.tsx",
                            lineNumber: 72,
                            columnNumber: 11
                        }, this)
                    ]
                }, void 0, true, {
                    fileName: "src/elements/DocumentLocked/index.tsx",
                    lineNumber: 64,
                    columnNumber: 9
                }, this),
                /*#__PURE__*/ _jsxDEV("div", {
                    className: `${baseClass}__controls`,
                    children: [
                        /*#__PURE__*/ _jsxDEV(Button, {
                            buttonStyle: "secondary",
                            id: `${modalSlug}-go-back`,
                            onClick: ()=>{
                                closeModal(modalSlug);
                                startRouteTransition(()=>handleGoBack());
                            },
                            size: "large",
                            children: t('general:goBack')
                        }, void 0, false, {
                            fileName: "src/elements/DocumentLocked/index.tsx",
                            lineNumber: 77,
                            columnNumber: 11
                        }, this),
                        /*#__PURE__*/ _jsxDEV(Button, {
                            buttonStyle: "secondary",
                            id: `${modalSlug}-view-read-only`,
                            onClick: ()=>{
                                onReadOnly();
                                closeModal(modalSlug);
                                clearRouteCache();
                            },
                            size: "large",
                            children: t('general:viewReadOnly')
                        }, void 0, false, {
                            fileName: "src/elements/DocumentLocked/index.tsx",
                            lineNumber: 88,
                            columnNumber: 11
                        }, this),
                        /*#__PURE__*/ _jsxDEV(Button, {
                            buttonStyle: "primary",
                            id: `${modalSlug}-take-over`,
                            onClick: ()=>{
                                onTakeOver();
                                closeModal(modalSlug);
                            },
                            size: "large",
                            children: t('general:takeOver')
                        }, void 0, false, {
                            fileName: "src/elements/DocumentLocked/index.tsx",
                            lineNumber: 100,
                            columnNumber: 11
                        }, this)
                    ]
                }, void 0, true, {
                    fileName: "src/elements/DocumentLocked/index.tsx",
                    lineNumber: 76,
                    columnNumber: 9
                }, this)
            ]
        }, void 0, true, {
            fileName: "src/elements/DocumentLocked/index.tsx",
            lineNumber: 63,
            columnNumber: 7
        }, this)
    }, void 0, false, {
        fileName: "src/elements/DocumentLocked/index.tsx",
        lineNumber: 54,
        columnNumber: 5
    }, this);
};

//# sourceMappingURL=index.js.map