import { useViewportTier } from "$hooks/useViewportTier";
import type { DocMeta, LineEnding } from "$types";
import { formatStatusDate } from "$utils/date";
import { useMemo } from "react";
export type StatusBarStats = {
cursorLine: number;
cursorColumn: number;
wordCount: number;
charCount: number;
selectionCount?: number;
};
export type StatusBarProps = {
docMeta?: DocMeta | null;
stats: StatusBarStats;
encoding?: string;
lineEnding?: LineEnding;
};
type StatusItemProps = { label?: string; value: string | number; title?: string; valueClassName?: string };
const StatusItem = ({ label, value, title, valueClassName = "" }: StatusItemProps) => (
{label && {label}}
{value}
);
const StatusDivider = () => ;
const UpdatedAtItem = ({ updatedAt }: { updatedAt: string }) => (
<>
>
);
const WordAndCharItems = ({ wordCount, charCount }: { wordCount: number; charCount: number }) => (
<>
>
);
const SelectionItems = ({ selectionCount }: { selectionCount: number }) => (
<>
>
);
const EncodingItems = ({ encoding }: { encoding: string }) => (
<>
>
);
const LineEndingItems = ({ lineEnding }: { lineEnding: LineEnding }) => (
<>
>
);
const LeftItems = (
{ docMeta, stats, showUpdatedAt, showSelection }: {
docMeta?: DocMeta | null;
stats: StatusBarStats;
showUpdatedAt: boolean;
showSelection: boolean;
},
) => {
const selectionCount = useMemo(() => stats.selectionCount ?? 0, [stats.selectionCount]);
if (!docMeta) {
return No document open;
}
return (
{showUpdatedAt ? : null}
{showSelection && selectionCount > 0 ? : null}
);
};
const RightItems = (
{ stats, encoding, lineEnding, showEncoding, showLineEnding }: {
stats: StatusBarStats;
encoding: string;
lineEnding: LineEnding;
showEncoding: boolean;
showLineEnding: boolean;
},
) => (
{showEncoding ? : null}
{showLineEnding ? : null}
);
export function StatusBar({ docMeta, stats, encoding = "utf8", lineEnding = "LF" }: StatusBarProps) {
const { viewportWidth, isCompact, isNarrow } = useViewportTier();
const showUpdatedAt = useMemo(() => !isCompact && viewportWidth >= 900, [isCompact, viewportWidth]);
const showEncoding = useMemo(() => !isCompact, [isCompact]);
const showLineEnding = useMemo(() => !isNarrow, [isNarrow]);
const showSelection = useMemo(() => !isCompact, [isCompact]);
return (
);
}