'use client';
import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
import { useCallback } from 'react';
import { Gutter } from '../../../elements/Gutter/index.js';
import { useModal } from '../../../elements/Modal/index.js';
import { RenderTitle } from '../../../elements/RenderTitle/index.js';
import { useFormModified } from '../../../forms/Form/index.js';
import { XIcon } from '../../../icons/X/index.js';
import { useDocumentInfo } from '../../../providers/DocumentInfo/index.js';
import { useDocumentTitle } from '../../../providers/DocumentTitle/index.js';
import { useTranslation } from '../../../providers/Translation/index.js';
import { IDLabel } from '../../IDLabel/index.js';
import { LeaveWithoutSavingModal } from '../../LeaveWithoutSaving/index.js';
import { documentDrawerBaseClass } from '../index.js';
import './index.scss';
const leaveWithoutSavingModalSlug = 'leave-without-saving-doc-drawer';
export const DocumentDrawerHeader = ({ AfterHeader, drawerSlug, showDocumentID = true })=>{
    const { closeModal, openModal } = useModal();
    const { t } = useTranslation();
    const isModified = useFormModified();
    const handleOnClose = useCallback(()=>{
        if (isModified) {
            openModal(leaveWithoutSavingModalSlug);
        } else {
            closeModal(drawerSlug);
        }
    }, [
        isModified,
        openModal,
        closeModal,
        drawerSlug
    ]);
    return /*#__PURE__*/ _jsxDEV(Gutter, {
        className: `${documentDrawerBaseClass}__header`,
        children: [
            /*#__PURE__*/ _jsxDEV("div", {
                className: `${documentDrawerBaseClass}__header-content`,
                children: [
                    /*#__PURE__*/ _jsxDEV("h2", {
                        className: `${documentDrawerBaseClass}__header-text`,
                        children: /*#__PURE__*/ _jsxDEV(RenderTitle, {
                            element: "span"
                        }, void 0, false, {
                            fileName: "src/elements/DocumentDrawer/DrawerHeader/index.tsx",
                            lineNumber: 41,
                            columnNumber: 12
                        }, this)
                    }, void 0, false, {
                        fileName: "src/elements/DocumentDrawer/DrawerHeader/index.tsx",
                        lineNumber: 40,
                        columnNumber: 9
                    }, this),
                    /*#__PURE__*/ _jsxDEV("button", {
                        "aria-label": t('general:close'),
                        className: `${documentDrawerBaseClass}__header-close`,
                        onClick: handleOnClose,
                        type: "button",
                        children: /*#__PURE__*/ _jsxDEV(XIcon, {}, void 0, false, {
                            fileName: "src/elements/DocumentDrawer/DrawerHeader/index.tsx",
                            lineNumber: 49,
                            columnNumber: 11
                        }, this)
                    }, void 0, false, {
                        fileName: "src/elements/DocumentDrawer/DrawerHeader/index.tsx",
                        lineNumber: 43,
                        columnNumber: 9
                    }, this)
                ]
            }, void 0, true, {
                fileName: "src/elements/DocumentDrawer/DrawerHeader/index.tsx",
                lineNumber: 39,
                columnNumber: 7
            }, this),
            showDocumentID && /*#__PURE__*/ _jsxDEV(DocumentID, {}, void 0, false, {
                fileName: "src/elements/DocumentDrawer/DrawerHeader/index.tsx",
                lineNumber: 52,
                columnNumber: 26
            }, this),
            AfterHeader ? /*#__PURE__*/ _jsxDEV("div", {
                className: `${documentDrawerBaseClass}__after-header`,
                children: AfterHeader
            }, void 0, false, {
                fileName: "src/elements/DocumentDrawer/DrawerHeader/index.tsx",
                lineNumber: 54,
                columnNumber: 9
            }, this) : null,
            /*#__PURE__*/ _jsxDEV(LeaveWithoutSavingModal, {
                modalSlug: leaveWithoutSavingModalSlug,
                onConfirm: ()=>closeModal(drawerSlug)
            }, void 0, false, {
                fileName: "src/elements/DocumentDrawer/DrawerHeader/index.tsx",
                lineNumber: 57,
                columnNumber: 7
            }, this)
        ]
    }, void 0, true, {
        fileName: "src/elements/DocumentDrawer/DrawerHeader/index.tsx",
        lineNumber: 38,
        columnNumber: 5
    }, this);
};
const DocumentID = ()=>{
    const { id } = useDocumentInfo();
    const { title } = useDocumentTitle();
    return id && id !== title ? /*#__PURE__*/ _jsxDEV(IDLabel, {
        id: id.toString()
    }, void 0, false, {
        fileName: "src/elements/DocumentDrawer/DrawerHeader/index.tsx",
        lineNumber: 68,
        columnNumber: 31
    }, this) : null;
};

//# sourceMappingURL=index.js.map