import { h } from 'preact';
import moment from 'moment';
import PropTypes from 'prop-types';
import { Options } from './Options';
import { ButtonNew as Button } from '@crayons';
export const EditorActions = ({
onSaveDraft,
onPublish,
onClearChanges,
published,
publishedAtDate,
publishedAtTime,
schedulingEnabled,
edited,
version,
passedData,
onConfigChange,
submitting,
previewLoading,
}) => {
const isVersion1 = version === 'v1';
const isVersion2 = version === 'v2';
if (submitting) {
return (
);
}
const now = moment();
const publishedAtObj = publishedAtDate
? moment(`${publishedAtDate} ${publishedAtTime || '00:00'}`)
: now;
const schedule = publishedAtObj > now;
const wasScheduled = passedData.publishedAtWas > now;
let saveButtonText;
if (isVersion1) {
saveButtonText = 'Save changes';
} else if (schedule) {
saveButtonText = 'Schedule';
} else if (wasScheduled || !published) {
// if the article was saved as scheduled, and the user clears publishedAt in the post options, the save button text is changed to "Publish"
// to make it clear that the article is going to be published right away
saveButtonText = 'Publish';
} else {
saveButtonText = 'Save changes';
}
return (