import { useT } from "@agent-native/core/client/i18n";
import type { MobileActionId } from "@shared/types";
import {
IconArchive,
IconTrash,
IconStarFilled,
IconStar,
IconArrowBackUp,
IconArrowForwardUp,
IconMail,
IconChevronUp,
IconChevronDown,
IconSettings,
} from "@tabler/icons-react";
import { useState } from "react";
import {
Drawer,
DrawerContent,
DrawerHeader,
DrawerTitle,
DrawerClose,
} from "@/components/ui/drawer";
import { Switch } from "@/components/ui/switch";
import {
Tooltip,
TooltipContent,
TooltipTrigger,
} from "@/components/ui/tooltip";
import { cn } from "@/lib/utils";
export const ALL_MOBILE_ACTIONS: MobileActionId[] = [
"archive",
"trash",
"star",
"reply",
"replyAll",
"forward",
"markUnread",
"prev",
"next",
];
export const DEFAULT_MOBILE_ACTIONS: MobileActionId[] = [
"archive",
"trash",
"star",
"reply",
"replyAll",
"forward",
"markUnread",
"prev",
"next",
];
/** Metadata for each action: stable id plus icon SVG. */
const ACTION_META: Record<
MobileActionId,
{
labelKey: string;
icon: (active?: boolean) => React.ReactNode;
}
> = {
archive: {
labelKey: "mail.mobileActions.archive",
icon: () => ,
},
trash: {
labelKey: "mail.mobileActions.trash",
icon: () => ,
},
star: {
labelKey: "mail.mobileActions.star",
icon: (active) =>
active ? (
) : (
),
},
reply: {
labelKey: "mail.mobileActions.reply",
icon: () => ,
},
replyAll: {
labelKey: "mail.mobileActions.replyAll",
icon: () => ,
},
forward: {
labelKey: "mail.mobileActions.forward",
icon: () => ,
},
markUnread: {
labelKey: "mail.mobileActions.unread",
icon: () => ,
},
prev: {
labelKey: "mail.mobileActions.prev",
icon: () => ,
},
next: {
labelKey: "mail.mobileActions.next",
icon: () => ,
},
};
export type MobileActionBarProps = {
actions: MobileActionId[];
isStarred?: boolean;
onAction: (action: MobileActionId) => void;
onUpdateActions?: (actions: MobileActionId[]) => void;
};
export function MobileActionBar({
actions,
isStarred,
onAction,
onUpdateActions,
}: MobileActionBarProps) {
const [customizeOpen, setCustomizeOpen] = useState(false);
const t = useT();
return (
<>
{onUpdateActions && (
{t("mail.mobileActions.customize")}
)}
{actions.map((id) => {
const meta = ACTION_META[id];
if (!meta) return null;
const label = t(meta.labelKey);
return (
{label}
);
})}
{onUpdateActions && (
{t("mail.mobileActions.customizeActions")}
{ALL_MOBILE_ACTIONS.map((id) => {
const meta = ACTION_META[id];
if (!meta) return null;
const enabled = actions.includes(id);
const label = t(meta.labelKey);
return (
{
const next = enabled
? actions.filter((a) => a !== id)
: [...actions, id];
// Maintain canonical order
const ordered = ALL_MOBILE_ACTIONS.filter((a) =>
next.includes(a),
);
onUpdateActions(ordered);
}}
>
{meta.icon(false)}
{label}
{
const next = checked
? [...actions, id]
: actions.filter((a) => a !== id);
// Maintain canonical order
const ordered = ALL_MOBILE_ACTIONS.filter((a) =>
next.includes(a),
);
onUpdateActions(ordered);
}}
onClick={(e) => e.stopPropagation()}
/>
);
})}
)}
>
);
}