import React, { useState } from 'react';
import { View, Text, TouchableOpacity, TextInput, Modal, KeyboardAvoidingView, Platform, Alert } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { Plus, Pencil, Undo2 } from 'lucide-react-native';
import * as Haptics from 'expo-haptics';
interface TopBarProps {
mode: 'camera' | 'library';
recipeName: string;
onSaveRecipe: (name: string) => void;
// Present only when the active recipe is user-created: enables Save (overwrite).
onOverwriteRecipe?: (name: string) => void;
// Also custom-only: opens the recipe editor — the CREATE form prefilled
// with this recipe's parameters and name.
onEditRecipe?: () => void;
// SAVE & SHARE -> EXPORT: write this look to an encrypted recipe file and
// hand it to the system share sheet so it can reach another phone.
onExportShare: (name: string) => void;
// BACK (undo): one step back through the look's history. PRO only — App
// refuses and offers the paywall when a LITE build taps it. No count is
// drawn: the icon turns amber while there is a step to go back to.
onUndo: () => void;
undoDepth: number;
}
export default function TopBar({
mode,
recipeName,
onSaveRecipe,
onOverwriteRecipe,
onEditRecipe,
onExportShare,
onUndo,
undoDepth,
}: TopBarProps) {
const insets = useSafeAreaInsets();
const [modalVisible, setModalVisible] = useState(false);
const [newRecipeName, setNewRecipeName] = useState('');
const openModal = () => {
// Bundled recipes are read-only -> Save As only, blank name. Custom ones
// prefill with the current name so Save (overwrite) is one tap.
setNewRecipeName(onOverwriteRecipe ? recipeName : '');
setModalVisible(true);
};
// SAVE & SHARE: two ways out of the same look — keep it as a recipe on this
// phone, or export it as a file another phone can import.
const openSaveMenu = () => {
Alert.alert(
'SAVE & SHARE',
'Save the look on this screen as a recipe, or export it as a file to share.',
[
{ text: 'CANCEL', style: 'cancel' },
{ text: 'EXPORT & SHARE', onPress: () => onExportShare(recipeName) },
{ text: 'SAVE RECIPE', onPress: openModal },
],
);
};
const run = (fn: (name: string) => void) => {
const name = newRecipeName.trim();
if (!name) return;
fn(name);
setNewRecipeName('');
setModalVisible(false);
Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light);
};
const handleSavePress = () => run(onSaveRecipe);
const handleOverwritePress = () => onOverwriteRecipe && run(onOverwriteRecipe);
return (
<>
{mode === 'camera' ? 'LIVE' : 'LIBRARY'}
{recipeName}
{/* BACK: the history control the chip row used to carry, sitting
between the status block and SAVE & SHARE. Lucide (ISC) vector
— no icon font to ship or license. */}
0 ? '#f59e0b' : '#52525b'} />
{onEditRecipe && (
)}
SAVE & SHARE
setModalVisible(false)}
>
{onOverwriteRecipe ? 'SAVE RECIPE' : 'SAVE CURRENT AS RECIPE'}
setModalVisible(false)}
className="flex-1 bg-zinc-800 py-3 rounded-lg items-center"
>
CANCEL
{onOverwriteRecipe ? (
<>
SAVE AS
SAVE
>
) : (
SAVE RECIPE
)}
>
);
}