import React, { useState } from 'react'; import { Camera as CameraIcon, X } from 'lucide-react'; import { Camera, CameraResultType, CameraSource } from '@capacitor/camera'; import { useNotification } from '@/hooks/useNotification'; interface PhotoTakerProps { onPhotoTaken?: (webPath: string) => void; onClose?: () => void; } export const PhotoTaker: React.FC = ({ onPhotoTaken, onClose }) => { const [photoUri, setPhotoUri] = useState(); const notify = useNotification(); const takeAndSavePhoto = async () => { try { const image = await Camera.getPhoto({ quality: 90, allowEditing: false, // Giữ nguyên ảnh gốc, không qua chỉnh sửa resultType: CameraResultType.Uri, source: CameraSource.Camera, // Mở camera trực tiếp saveToGallery: true, // Tự động lưu ảnh gốc vào thư viện điện thoại }); setPhotoUri(image.webPath); notify({ title: 'Thành công', message: 'Ảnh đã được chụp và tự động lưu vào thư viện điện thoại.', type: 'success' }); if (onPhotoTaken && image.webPath) { onPhotoTaken(image.webPath); } } catch (error: any) { console.error('Lỗi khi chụp hoặc lưu ảnh:', error); if (error?.message !== 'User cancelled photos app') { notify({ title: 'Lỗi chụp ảnh', message: 'Không thể truy cập camera hoặc lưu ảnh.', type: 'error' }); } } }; return (

Chụp ảnh hành trình

{onClose && ( )}
{photoUri && (

Xem trước ảnh vừa chụp:

Xem trước ảnh chụp
)}
); };