import { _ } from '@evershop/evershop/lib/locale/translate/_'; import { Calendar, Edit3 } from 'lucide-react'; import React from 'react'; /** * Subset of `Changeset.rolloutPlan` the badge actually renders. Kept structurally * compatible with the Editor's full `ChangesetInfo['rolloutPlan']` so callers * can pass the GraphQL value through directly. */ export interface SessionModeBadgeRolloutPlan { rolloutPlanId: number; name: string; startTime?: { text: string | null } | null; endTime?: { text: string | null } | null; } interface SessionModeBadgeProps { rolloutPlan: SessionModeBadgeRolloutPlan | null | undefined; /** Reopens the SessionPicker (switch session). */ onClick: () => void; /** * Click handler for the inline pencil button. Only rendered when supplied * AND the badge is in rollout-edit mode — the pencil opens the schedule * editor (RolloutDialog in `editingPlan` mode). */ onEditSchedule?: () => void; } /** * Topbar session badge (spec § 7.6). * * - Editing draft: edit icon + "New changeset", muted styling. * - Editing rollout: calendar icon + "Rollout: " + a status pill * (Scheduled / Live), violet styling per demo (publish-flow.jsx:58-76), * plus an inline pencil button to open the schedule editor without * leaving the badge. */ export function SessionModeBadge({ rolloutPlan, onClick, onEditSchedule }: SessionModeBadgeProps): React.ReactElement { if (!rolloutPlan) { return ( ); } const startMs = rolloutPlan.startTime?.text ? new Date(rolloutPlan.startTime.text).getTime() : null; const status: 'scheduled' | 'live' = startMs != null && startMs > Date.now() ? 'scheduled' : 'live'; const pillStyles = status === 'scheduled' ? 'bg-emerald-100 text-emerald-700 dark:bg-emerald-950/50 dark:text-emerald-300' : 'bg-blue-100 text-blue-700 dark:bg-blue-950/50 dark:text-blue-300'; // Wrapper div hosts two distinct click targets (the name area reopens the // picker; the pencil opens the schedule editor) without nesting {onEditSchedule && ( )} ); }