'use client';
import React, { Fragment } from 'react';
import { useConfig } from '../../providers/Config/index.js';
import { useTranslation } from '../../providers/Translation/index.js';
import { formatDate } from '../../utilities/formatDate/index.js';
import DeleteDocument from '../DeleteDocument/index.js';
import DuplicateDocument from '../DuplicateDocument/index.js';
import { Gutter } from '../Gutter/index.js';
import * as PopupList from '../Popup/PopupButtonList/index.js';
import Popup from '../Popup/index.js';
import { Publish } from '../Publish/index.js';
import { Save } from '../Save/index.js';
import { SaveDraft } from '../SaveDraft/index.js';
import Status from '../Status/index.js';
const baseClass = 'doc-controls';
export const DocumentControls = (props)=>{
    const { id, slug, data, disableActions, hasSavePermission, isAccountView, isEditing, permissions } = props;
    const { i18n } = useTranslation();
    const config = useConfig();
    const collectionConfig = config.collections.find((coll)=>coll.slug === slug);
    const globalConfig = config.globals.find((global)=>global.slug === slug);
    const { admin: { dateFormat }, routes: { admin: adminRoute } } = config;
    const hasCreatePermission = permissions && 'create' in permissions && permissions.create?.permission;
    const hasDeletePermission = permissions && 'delete' in permissions && permissions.delete?.permission;
    const showDotMenu = Boolean(collectionConfig && id && !disableActions && (hasCreatePermission || hasDeletePermission));
    return /*#__PURE__*/ React.createElement(Gutter, {
        className: baseClass
    }, /*#__PURE__*/ React.createElement("div", {
        className: `${baseClass}__wrapper`
    }, /*#__PURE__*/ React.createElement("div", {
        className: `${baseClass}__content`
    }, /*#__PURE__*/ React.createElement("ul", {
        className: `${baseClass}__meta`
    }, collectionConfig && !isEditing && !isAccountView && /*#__PURE__*/ React.createElement("li", {
        className: `${baseClass}__list-item`
    }, /*#__PURE__*/ React.createElement("p", {
        className: `${baseClass}__value`
    }, i18n.t('general:creatingNewLabel', {
        label: typeof collectionConfig?.labels?.singular === 'string' ? collectionConfig.labels.singular : 'document'
    }))), (collectionConfig?.versions?.drafts || globalConfig?.versions?.drafts) && /*#__PURE__*/ React.createElement(Fragment, null, (globalConfig || collectionConfig && isEditing) && /*#__PURE__*/ React.createElement("li", {
        className: [
            `${baseClass}__status`,
            `${baseClass}__list-item`
        ].filter(Boolean).join(' ')
    }, /*#__PURE__*/ React.createElement(Status, null)), (collectionConfig?.versions?.drafts && collectionConfig?.versions?.drafts?.autosave || globalConfig?.versions?.drafts && globalConfig?.versions?.drafts?.autosave) && hasSavePermission && /*#__PURE__*/ React.createElement("li", {
        className: `${baseClass}__list-item`
    })), collectionConfig?.timestamps && (isEditing || isAccountView) && /*#__PURE__*/ React.createElement(Fragment, null, /*#__PURE__*/ React.createElement("li", {
        className: [
            `${baseClass}__list-item`,
            `${baseClass}__value-wrap`
        ].filter(Boolean).join(' '),
        title: data?.updatedAt ? formatDate(data?.updatedAt, dateFormat, i18n.language) : ''
    }, /*#__PURE__*/ React.createElement("p", {
        className: `${baseClass}__label`
    }, i18n.t('general:lastModified'), ": "), data?.updatedAt && /*#__PURE__*/ React.createElement("p", {
        className: `${baseClass}__value`
    }, formatDate(data.updatedAt, dateFormat, i18n.language))), /*#__PURE__*/ React.createElement("li", {
        className: [
            `${baseClass}__list-item`,
            `${baseClass}__value-wrap`
        ].filter(Boolean).join(' '),
        title: data?.createdAt ? formatDate(data?.createdAt, dateFormat, i18n.language) : ''
    }, /*#__PURE__*/ React.createElement("p", {
        className: `${baseClass}__label`
    }, i18n.t('general:created'), ": "), data?.createdAt && /*#__PURE__*/ React.createElement("p", {
        className: `${baseClass}__value`
    }, formatDate(data?.createdAt, dateFormat, i18n.language)))))), /*#__PURE__*/ React.createElement("div", {
        className: `${baseClass}__controls-wrapper`
    }, /*#__PURE__*/ React.createElement("div", {
        className: `${baseClass}__controls`
    }, hasSavePermission && /*#__PURE__*/ React.createElement(React.Fragment, null, collectionConfig?.versions?.drafts || globalConfig?.versions?.drafts ? /*#__PURE__*/ React.createElement(React.Fragment, null, (collectionConfig?.versions?.drafts && !collectionConfig?.versions?.drafts?.autosave || globalConfig?.versions?.drafts && !globalConfig?.versions?.drafts?.autosave) && /*#__PURE__*/ React.createElement(SaveDraft, {
        CustomComponent: collectionConfig?.admin?.components?.edit?.SaveDraftButton || globalConfig?.admin?.components?.elements?.SaveDraftButton
    }), /*#__PURE__*/ React.createElement(Publish, {
        CustomComponent: collectionConfig?.admin?.components?.edit?.PublishButton || globalConfig?.admin?.components?.elements?.PublishButton
    })) : /*#__PURE__*/ React.createElement(Save, {
        CustomComponent: collectionConfig?.admin?.components?.edit?.SaveButton || globalConfig?.admin?.components?.elements?.SaveButton
    }))), showDotMenu && /*#__PURE__*/ React.createElement(Popup, {
        button: /*#__PURE__*/ React.createElement("div", {
            className: `${baseClass}__dots`
        }, /*#__PURE__*/ React.createElement("div", null), /*#__PURE__*/ React.createElement("div", null), /*#__PURE__*/ React.createElement("div", null)),
        className: `${baseClass}__popup`,
        horizontalAlign: "right",
        size: "large",
        verticalAlign: "bottom"
    }, /*#__PURE__*/ React.createElement(PopupList.ButtonGroup, null, hasCreatePermission && /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(PopupList.Button, {
        href: `${adminRoute}/collections/${collectionConfig?.slug}/create`,
        id: "action-create"
    }, i18n.t('general:createNew')), !collectionConfig?.admin?.disableDuplicate && isEditing && /*#__PURE__*/ React.createElement(DuplicateDocument, {
        id: id.toString(),
        singularLabel: collectionConfig?.labels?.singular,
        slug: collectionConfig?.slug
    })), hasDeletePermission && /*#__PURE__*/ React.createElement(DeleteDocument, {
        buttonId: "action-delete",
        collectionSlug: collectionConfig?.slug,
        id: id.toString(),
        singularLabel: collectionConfig?.labels?.singular,
        useAsTitle: collectionConfig?.admin?.useAsTitle
    }))))), /*#__PURE__*/ React.createElement("div", {
        className: `${baseClass}__divider`
    }));
};

//# sourceMappingURL=index.js.map