Files
SweetHomeWeb/app/payments/page.js

714 lines
28 KiB
JavaScript
Raw Normal View History

"use client";
2026-03-30 19:26:03 +03:00
2026-05-25 21:27:39 +03:00
import { useEffect, useState, useCallback } from 'react';
2026-06-16 14:12:26 +03:00
import Link from 'next/link';
2026-05-25 21:27:39 +03:00
import { motion } from 'framer-motion';
import { useTranslation } from 'react-i18next';
2026-06-24 15:04:56 +03:00
import {
Home,
MapPin,
Phone,
ShieldCheck,
CreditCard,
Banknote,
Building,
ArrowLeftRight,
Loader2,
Check,
X,
Calendar,
Clock,
LogIn,
Lock,
Info,
Landmark,
Wallet,
} from 'lucide-react';
2026-05-25 21:27:39 +03:00
import toast, { Toaster } from 'react-hot-toast';
2026-03-30 19:26:03 +03:00
import AuthService from '@/app/services/AuthService';
2026-07-04 02:05:13 +03:00
import { payDeposit, getMyTransaction, getPaymentTypes } from '@/app/utils/api';
2026-03-30 19:26:03 +03:00
2026-05-25 21:27:39 +03:00
const STATUS_MAP = ['pending', 'ownerConfirmed', 'depositPaid', 'depositConfirmed', 'completed', 'cancelled'];
2026-07-02 10:38:55 +03:00
function getStatusConfig(t) {
return {
pending: { label: t('bookingStatus.pending'), color: 'bg-yellow-100 text-yellow-800 border-yellow-300', icon: Clock },
ownerConfirmed: { label: t('bookingStatus.ownerConfirmed'), color: 'bg-blue-100 text-blue-800 border-blue-300', icon: ShieldCheck },
depositPaid: { label: t('bookingStatus.depositPaid'), color: 'bg-orange-100 text-orange-800 border-orange-300', icon: Wallet },
depositConfirmed: { label: t('bookingStatus.depositConfirmed'), color: 'bg-green-100 text-green-800 border-green-300', icon: Check },
completed: { label: t('bookingStatus.completed'), color: 'bg-teal-100 text-teal-800 border-teal-300', icon: Check },
cancelled: { label: t('bookingStatus.cancelled'), color: 'bg-red-100 text-red-800 border-red-300', icon: X },
};
}
2026-03-30 19:26:03 +03:00
2026-07-02 10:38:55 +03:00
function getPaymentMethods(t) {
return [
{ id: 'cash', label: t('payments.method.cash'), desc: t('payments.method.cashDesc'), icon: Banknote, active: true },
{ id: 'office', label: t('payments.method.office'), desc: t('payments.method.officeDesc'), icon: Building, active: true },
{ id: 'transfer', label: t('payments.method.transfer'), desc: t('payments.method.transferDesc'), icon: ArrowLeftRight, active: false },
{ id: 'electronic', label: t('payments.method.electronic'), desc: t('payments.method.electronicDesc'), icon: CreditCard, active: false },
];
}
2026-06-24 15:04:56 +03:00
2026-07-02 10:38:55 +03:00
function formatCurrency(v, sign = '') {
2026-06-24 15:04:56 +03:00
return `${sign} ${Number(v ?? 0).toLocaleString()}`;
}
function formatDate(date) {
if (!date) return '';
const d = new Date(date);
if (Number.isNaN(d.getTime())) return '';
return d.toLocaleDateString('en-GB');
}
2026-07-11 05:21:38 -07:00
function normalizeText(value) {
return String(value ?? '').trim().toLowerCase();
}
2026-07-13 20:20:17 +03:00
function isHaramText(value) {
const text = normalizeText(value);
2026-07-13 21:51:04 +03:00
return text.includes('haram') || text.includes('هرم') || text.includes('هرام');
2026-07-13 20:20:17 +03:00
}
2026-07-15 19:25:39 +03:00
function isReceiptRequiredPayment(value, method = null) {
const haystack = [
value,
method?.name,
method?.label,
method?.id,
method?.description,
]
.filter(Boolean)
.join(' ');
const text = normalizeText(haystack);
return (
text.includes('transfer') ||
text.includes('تحويل') ||
text.includes('حوالة') ||
text.includes('bank') ||
text.includes('بنك') ||
isHaramText(value) ||
isHaramText(method?.name) ||
isHaramText(method?.label) ||
isHaramText(method?.id) ||
isHaramText(method?.description)
);
}
2026-03-30 19:26:03 +03:00
export default function PaymentsPage() {
2026-07-02 10:38:55 +03:00
const { t, i18n } = useTranslation();
2026-05-25 21:27:39 +03:00
const [reservations, setReservations] = useState([]);
const [loading, setLoading] = useState(true);
const [payingId, setPayingId] = useState(null);
2026-06-16 14:12:26 +03:00
const [isGuest, setIsGuest] = useState(null);
2026-07-04 02:05:13 +03:00
const [paymentMethods, setPaymentMethods] = useState([]);
const [loadingPaymentMethods, setLoadingPaymentMethods] = useState(true);
2026-07-11 05:21:38 -07:00
const [selectedPayment, setSelectedPayment] = useState(null);
2026-03-30 19:26:03 +03:00
2026-05-25 21:27:39 +03:00
const loadReservations = useCallback(async () => {
try {
2026-06-23 23:45:48 +03:00
const json = await getMyTransaction();
const items = Array.isArray(json) ? json : [];
2026-06-15 10:18:15 -07:00
const mapped = items.map((item) => {
const deposit = item?.diposit || item?.deposit || {};
const reservation = deposit?.reservation || {};
const transaction = deposit?.transaction || {};
const currency = item?.currency || {};
2026-06-24 15:04:56 +03:00
const propertyInfo = reservation?.propertyInformation || {};
2026-06-15 10:18:15 -07:00
return {
2026-06-24 15:04:56 +03:00
id: deposit.id ?? reservation.id ?? item?.id,
reservationId: reservation.id ?? deposit.reservationId ?? item?.reservationId,
2026-06-15 10:18:15 -07:00
status: reservation.status ?? 0,
startDate: reservation.startDate,
endDate: reservation.endDate,
totalPrice: reservation.totalPrice ?? transaction.amount ?? 0,
depositAmount: transaction.amount ?? reservation.totalPrice ?? 0,
2026-07-02 10:38:55 +03:00
currencySign: currency.sign || t('currency.syp'),
2026-06-15 10:18:15 -07:00
currencyName: currency.name || '',
currencyRate: currency.rate,
2026-07-02 10:38:55 +03:00
propertyName: propertyInfo.name || propertyInfo.address || reservation.propertyName || `${t('payments.propertyLabel')} #${reservation.id || ''}`,
2026-06-24 15:04:56 +03:00
propertyAddress: propertyInfo.address || reservation.propertyAddress || '',
propertyCity: propertyInfo.city || reservation.city || '',
2026-06-15 10:18:15 -07:00
_deposit: deposit,
2026-06-24 15:04:56 +03:00
_reservation: reservation,
2026-06-15 10:18:15 -07:00
};
});
setReservations(mapped);
2026-05-25 21:27:39 +03:00
} catch (err) {
console.error(err);
toast.error(t('payments.loadingTransactions'));
2026-05-25 21:27:39 +03:00
} finally {
setLoading(false);
}
2026-07-02 10:38:55 +03:00
}, [t]);
2026-05-25 21:27:39 +03:00
2026-07-04 02:05:13 +03:00
const loadPaymentMethods = useCallback(async () => {
setLoadingPaymentMethods(true);
try {
const data = await getPaymentTypes();
const methods = Array.isArray(data) ? data : [];
setPaymentMethods(methods);
2026-07-11 05:21:38 -07:00
2026-07-04 02:05:13 +03:00
const firstActive = methods.find((method) => method?.isActive === true || method?.active === true);
if (firstActive) {
2026-07-11 05:21:38 -07:00
setSelectedPayment(firstActive.name ?? firstActive.id ?? null);
2026-07-04 02:05:13 +03:00
}
} catch (err) {
console.error('[Payments] failed to load payment methods', err);
setPaymentMethods([]);
} finally {
setLoadingPaymentMethods(false);
}
2026-07-11 05:21:38 -07:00
}, []);
2026-07-04 02:05:13 +03:00
2026-06-15 10:18:15 -07:00
useEffect(() => {
2026-06-16 14:12:26 +03:00
if (AuthService.isGuest()) {
setIsGuest(true);
setLoading(false);
return;
}
setIsGuest(false);
2026-06-15 10:18:15 -07:00
loadReservations();
2026-06-16 14:12:26 +03:00
}, [loadReservations]);
2026-06-15 10:18:15 -07:00
2026-07-04 02:05:13 +03:00
useEffect(() => {
loadPaymentMethods();
}, [loadPaymentMethods]);
const resolvePaymentTypeId = (paymentKey) => {
const method = paymentMethods.find(
(m) => String(m.id) === String(paymentKey) || String(m.name) === String(paymentKey),
);
return method?.id ?? paymentKey;
};
2026-07-11 05:21:38 -07:00
const handlePayDeposit = async (reservation, paymentKey, paymentImageFile) => {
2026-07-04 02:05:13 +03:00
const paymentTypeId = resolvePaymentTypeId(paymentKey);
2026-07-11 05:21:38 -07:00
const selectedMethod = paymentMethods.find(
(m) => String(m.id) === String(paymentTypeId) || String(m.name) === String(paymentTypeId),
);
2026-07-15 19:25:39 +03:00
const requiresReceiptUpload = isReceiptRequiredPayment(paymentKey, selectedMethod);
2026-07-11 05:21:38 -07:00
2026-07-15 19:25:39 +03:00
if (requiresReceiptUpload && !paymentImageFile) {
toast.error(t('payments.receiptRequired'));
return;
}
2026-07-11 05:21:38 -07:00
setPayingId(reservation.id);
2026-05-25 21:27:39 +03:00
try {
2026-07-04 02:05:13 +03:00
await payDeposit({
reservationId: reservation.id,
paymentTypeId,
2026-07-11 05:21:38 -07:00
paymentImage: paymentImageFile,
2026-07-04 02:05:13 +03:00
});
toast.success(t('payments.depositPaidSuccess'));
2026-05-25 21:27:39 +03:00
loadReservations();
} catch (err) {
toast.error(err?.message || t('payments.paymentFailed'));
2026-05-25 21:27:39 +03:00
} finally {
setPayingId(null);
}
};
2026-06-24 15:04:56 +03:00
const canPay = (status) => STATUS_MAP[status] === 'ownerConfirmed';
2026-03-30 19:26:03 +03:00
2026-05-25 21:27:39 +03:00
if (loading) {
2026-03-30 19:26:03 +03:00
return (
2026-07-02 10:38:55 +03:00
<div className="min-h-screen bg-gray-50 flex items-center justify-center" dir={i18n.dir()}>
2026-05-25 21:27:39 +03:00
<Loader2 className="w-12 h-12 text-amber-500 animate-spin" />
2026-03-30 19:26:03 +03:00
</div>
);
}
2026-06-16 14:12:26 +03:00
if (isGuest) {
return (
2026-07-15 19:25:39 +03:00
<div className="min-h-screen bg-linear-to-b from-amber-50/50 to-white flex items-center justify-center p-4" dir={i18n.dir()}>
2026-06-16 14:12:26 +03:00
<motion.div
initial={{ opacity: 0, scale: 0.95 }}
animate={{ opacity: 1, scale: 1 }}
className="bg-white rounded-3xl shadow-xl border border-gray-200 p-10 max-w-md w-full text-center"
>
<div className="w-20 h-20 bg-amber-100 rounded-full flex items-center justify-center mx-auto mb-6">
<Lock className="w-10 h-10 text-amber-600" />
</div>
<h2 className="text-2xl font-bold text-gray-900 mb-3">{t('payments.title')}</h2>
2026-06-16 14:12:26 +03:00
<p className="text-gray-600 leading-relaxed mb-8">
{t('payments.loginRequiredDesc')}
2026-06-16 14:12:26 +03:00
</p>
<Link
href="/login"
className="inline-flex items-center gap-2 bg-amber-500 hover:bg-amber-600 text-white px-8 py-3 rounded-2xl text-lg font-semibold transition shadow-lg shadow-amber-200"
>
<LogIn className="w-5 h-5" />
{t('login')}
2026-06-16 14:12:26 +03:00
</Link>
</motion.div>
</div>
);
}
2026-06-24 15:04:56 +03:00
const payables = reservations.filter((r) => canPay(r.status));
const others = reservations.filter((r) => !canPay(r.status));
2026-05-25 21:27:39 +03:00
2026-03-30 19:26:03 +03:00
return (
2026-07-02 10:38:55 +03:00
<div className="min-h-screen bg-gray-50 py-8" dir={i18n.dir()}>
2026-05-25 21:27:39 +03:00
<Toaster position="top-center" reverseOrder={false} />
2026-03-30 19:26:03 +03:00
<div className="container mx-auto px-4 max-w-4xl">
2026-06-24 15:04:56 +03:00
<motion.div
initial={{ opacity: 0, y: -20 }}
animate={{ opacity: 1, y: 0 }}
className="mb-8"
>
<h1 className="text-3xl font-bold text-gray-900 mb-2">{t('payments.title')}</h1>
<p className="text-gray-600">{t('payments.description')}</p>
2026-05-25 21:27:39 +03:00
</motion.div>
2026-03-30 19:26:03 +03:00
2026-06-24 15:04:56 +03:00
{payables.length > 0 && (
<div className="space-y-6 mb-10">
<h2 className="text-xl font-bold text-gray-800 flex items-center gap-2">
<Wallet className="w-5 h-5 text-amber-500" />
{t('payments.payablesTitle')}
2026-06-24 15:04:56 +03:00
</h2>
{payables.map((r, i) => (
<PaymentCard
key={r.id || i}
reservation={r}
payingId={payingId}
2026-07-04 02:05:13 +03:00
paymentMethods={paymentMethods}
loadingPaymentMethods={loadingPaymentMethods}
2026-06-24 15:04:56 +03:00
selectedPayment={selectedPayment}
onSelectPayment={setSelectedPayment}
onPay={handlePayDeposit}
/>
))}
</div>
)}
{others.length > 0 && (
2026-03-30 19:26:03 +03:00
<div className="space-y-4">
2026-06-24 15:04:56 +03:00
<h2 className="text-xl font-bold text-gray-800 flex items-center gap-2">
<Clock className="w-5 h-5 text-gray-500" />
{t('payments.previousReservationsTitle')}
2026-06-24 15:04:56 +03:00
</h2>
{others.map((r, i) => {
2026-05-25 21:27:39 +03:00
const statusKey = STATUS_MAP[r.status] || 'pending';
2026-07-02 10:38:55 +03:00
const cfg = getStatusConfig(t)[statusKey];
2026-06-24 15:04:56 +03:00
const Icon = cfg.icon;
2026-05-25 21:27:39 +03:00
const amount = r.depositAmount || r.totalPrice || 0;
return (
2026-06-15 10:18:15 -07:00
<motion.div
key={r.id || i}
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
2026-06-24 15:04:56 +03:00
className="bg-white rounded-2xl shadow-sm border border-gray-200 p-5"
2026-06-15 10:18:15 -07:00
>
2026-06-24 15:04:56 +03:00
<div className="flex items-center justify-between gap-3 mb-3">
<span className="text-sm font-medium text-gray-400">#{r.reservationId || r.id}</span>
<span className={`inline-flex items-center gap-1 px-3 py-1 rounded-full text-xs font-medium border ${cfg.color}`}>
<Icon className="w-3 h-3" />
{cfg.label}
</span>
</div>
<div className="flex items-center justify-between">
<div className="flex items-center gap-2 text-sm text-gray-600">
<Calendar className="w-4 h-4" />
{formatDate(r.startDate)} - {formatDate(r.endDate)}
2026-05-25 21:27:39 +03:00
</div>
2026-06-24 15:04:56 +03:00
<div className="text-lg font-bold text-gray-900">
{formatCurrency(amount, r.currencySign)}
2026-05-25 21:27:39 +03:00
</div>
2026-06-15 10:18:15 -07:00
</div>
2026-05-25 21:27:39 +03:00
</motion.div>
);
})}
2026-03-30 19:26:03 +03:00
</div>
)}
2026-06-24 15:04:56 +03:00
2026-07-11 05:21:38 -07:00
{reservations.length === 0 && (
<motion.div
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
className="bg-white rounded-2xl p-12 text-center border-2 border-dashed border-gray-300"
>
<CreditCard className="w-16 h-16 text-gray-300 mx-auto mb-4" />
<h3 className="text-xl font-bold text-gray-700 mb-2">{t('payments.noTransactions')}</h3>
<p className="text-gray-500">{t('payments.noTransactionsDesc')}</p>
</motion.div>
)}
2026-03-30 19:26:03 +03:00
</div>
2026-07-11 05:21:38 -07:00
</div>
);
}
2026-06-24 15:04:56 +03:00
2026-07-11 05:21:38 -07:00
// eslint-disable-next-line react/prop-types
function PaymentCard({ reservation, payingId, paymentMethods, loadingPaymentMethods, selectedPayment, onSelectPayment, onPay }) {
const { t } = useTranslation();
const r = reservation;
const amount = r.depositAmount || r.totalPrice || 0;
const [showCashDialog, setShowCashDialog] = useState(false);
2026-07-15 19:25:39 +03:00
const [showReceiptModal, setShowReceiptModal] = useState(false);
2026-07-11 05:21:38 -07:00
const [localPaymentImage, setLocalPaymentImage] = useState(null);
2026-07-15 19:25:39 +03:00
const [receiptPreviewUrl, setReceiptPreviewUrl] = useState('');
const [receiptFileName, setReceiptFileName] = useState('');
2026-06-24 15:04:56 +03:00
2026-07-11 05:21:38 -07:00
const methods = paymentMethods.length > 0 ? paymentMethods : getPaymentMethods(t);
const selectedMethod = methods.find((m) => {
const methodName = normalizeText(m?.name);
const methodLabel = normalizeText(m?.label);
const methodId = normalizeText(m?.id);
const paymentKey = normalizeText(selectedPayment);
return methodName === paymentKey || methodLabel === paymentKey || methodId === paymentKey;
});
2026-07-15 19:25:39 +03:00
const requiresReceiptUpload = isReceiptRequiredPayment(selectedPayment, selectedMethod);
useEffect(() => {
if (!localPaymentImage) {
setReceiptPreviewUrl('');
return undefined;
}
const previewUrl = URL.createObjectURL(localPaymentImage);
setReceiptPreviewUrl(previewUrl);
return () => URL.revokeObjectURL(previewUrl);
}, [localPaymentImage]);
const handleSelectMethod = (optionId, method) => {
onSelectPayment(optionId);
if (isReceiptRequiredPayment(optionId, method)) {
setShowReceiptModal(true);
return;
}
setShowReceiptModal(false);
setLocalPaymentImage(null);
setReceiptPreviewUrl('');
setReceiptFileName('');
};
const handleReceiptSelection = (event) => {
const file = event.target.files?.[0] || null;
setLocalPaymentImage(file);
setReceiptFileName(file?.name || '');
};
const handleReceiptConfirm = () => {
if (!localPaymentImage) {
toast.error(t('payments.receiptRequired'));
return;
}
setShowReceiptModal(false);
};
2026-07-11 05:21:38 -07:00
return (
<>
<motion.div
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
className="bg-white rounded-3xl shadow-md border border-gray-200 overflow-hidden"
>
{/* Property details */}
<div className="p-6 border-b border-gray-100">
<div className="flex items-start gap-4 mb-4">
<div className="w-14 h-14 bg-amber-100 rounded-2xl flex items-center justify-center shrink-0">
<Home className="w-7 h-7 text-amber-600" />
</div>
<div className="min-w-0 flex-1">
<h3 className="text-xl font-bold text-gray-900 mb-1">
{r.propertyName}
</h3>
{(r.propertyAddress || r.propertyCity) && (
<p className="text-sm text-gray-500 flex items-center gap-1">
<MapPin className="w-3.5 h-3.5" />
{[r.propertyCity, r.propertyAddress].filter(Boolean).join(' - ')}
</p>
)}
</div>
2026-06-24 15:04:56 +03:00
</div>
<div className="flex items-center gap-4 text-sm text-gray-600">
<span className="flex items-center gap-1.5">
<Calendar className="w-4 h-4 text-gray-400" />
{formatDate(r.startDate)} - {formatDate(r.endDate)}
</span>
<span className="flex items-center gap-1.5">
<Clock className="w-4 h-4 text-gray-400" />
#{r.reservationId || r.id}
</span>
</div>
2026-06-24 15:04:56 +03:00
</div>
{/* Deposit amount */}
<div className="px-6 py-5 border-b border-gray-100">
<div className="text-center">
<p className="text-sm text-gray-500 mb-1">{t('payments.depositAmount')}</p>
<p className="text-4xl font-bold text-amber-600">
{formatCurrency(amount, r.currencySign)}
</p>
<p className="text-xs text-gray-400 mt-2">
{t('payments.depositPaidToPlatform')}
</p>
</div>
2026-06-24 15:04:56 +03:00
</div>
{/* Payment methods note */}
<div className="px-6 py-4 bg-amber-50 border-b border-amber-100">
<div className="flex items-start gap-3">
<Info className="w-5 h-5 text-amber-600 shrink-0 mt-0.5" />
<p className="text-sm text-amber-800 leading-relaxed">
{t('payments.cashOnlyNotice')}
</p>
</div>
2026-06-24 15:04:56 +03:00
</div>
{/* Payment method options */}
<div className="px-6 py-5 border-b border-gray-100">
<p className="text-sm font-bold text-gray-700 mb-3">{t('payments.paymentMethodLabel')}</p>
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
2026-07-04 02:05:13 +03:00
{loadingPaymentMethods ? (
<div className="col-span-full rounded-2xl border border-dashed border-gray-200 bg-gray-50 p-4 text-sm text-gray-600">
2026-07-13 20:20:17 +03:00
{t('payments.loadingPaymentMethods')}
2026-07-04 02:05:13 +03:00
</div>
) : methods.length === 0 ? (
<div className="col-span-full rounded-2xl border border-dashed border-gray-200 bg-gray-50 p-4 text-sm text-gray-600">
2026-07-13 20:20:17 +03:00
{t('payments.noPaymentMethodsAvailable')}
2026-07-04 02:05:13 +03:00
</div>
) : (
methods.map((method, index) => {
2026-07-11 05:21:38 -07:00
const optionId = method.name ?? method.id ?? `payment-method-${index}`;
2026-07-04 02:05:13 +03:00
const isActive = method?.isActive === true || method?.active === true;
const isSelected = String(selectedPayment) === String(optionId);
const Icon = method.icon || CreditCard;
return (
<button
key={optionId}
type="button"
disabled={!isActive}
2026-07-15 19:25:39 +03:00
onClick={() => isActive && handleSelectMethod(optionId, method)}
2026-07-04 02:05:13 +03:00
className={`relative flex items-start gap-3 p-4 rounded-2xl border-2 text-right transition-all ${
!isActive
? 'border-gray-100 bg-gray-50 opacity-50 cursor-not-allowed'
: isSelected
? 'border-amber-500 bg-amber-50 shadow-sm'
: 'border-gray-200 bg-white hover:border-amber-300 cursor-pointer'
}`}
>
2026-07-11 05:21:38 -07:00
<div
className={`w-10 h-10 rounded-xl flex items-center justify-center shrink-0 ${
isSelected ? 'bg-amber-500 text-white' : 'bg-gray-100 text-gray-500'
}`}
>
2026-07-04 02:05:13 +03:00
<Icon className="w-5 h-5" />
</div>
<div className="min-w-0 flex-1">
<p className={`text-sm font-bold ${isSelected ? 'text-amber-900' : 'text-gray-800'}`}>
2026-07-13 20:20:17 +03:00
{method.name || method.label || t('payments.paymentMethodName')}
2026-07-04 02:05:13 +03:00
</p>
{method.description && (
<p className="text-xs text-gray-500 mt-0.5 leading-relaxed">
{method.description}
</p>
)}
2026-07-11 05:21:38 -07:00
<span
className={`inline-block mt-1 text-[10px] font-medium px-2 py-0.5 rounded-full ${
isActive ? 'bg-amber-100 text-amber-700' : 'bg-gray-200 text-gray-500'
}`}
>
2026-07-13 20:20:17 +03:00
{isActive ? t('payments.methodActive') : t('payments.methodInactive')}
</span>
</div>
2026-07-04 02:05:13 +03:00
{isSelected && (
<div className="absolute top-2 left-2 w-5 h-5 bg-amber-500 rounded-full flex items-center justify-center">
<Check className="w-3 h-3 text-white" />
</div>
)}
</button>
);
})
)}
</div>
2026-06-24 15:04:56 +03:00
</div>
2026-07-15 19:25:39 +03:00
{requiresReceiptUpload && (
<div className="px-6 py-4 bg-amber-50 border-b border-amber-100">
<div className="flex items-start gap-2 text-sm text-amber-800">
<Info className="w-4 h-4 shrink-0 mt-0.5" />
<p>{t('payments.receiptUploadRequiredHint')}</p>
</div>
2026-07-11 05:21:38 -07:00
</div>
)}
2026-06-24 15:04:56 +03:00
2026-07-11 05:21:38 -07:00
{/* Pay button */}
<div className="px-6 py-5 border-b border-gray-100">
<motion.button
type="button"
onClick={() => onPay(r, selectedPayment, localPaymentImage)}
disabled={payingId === r.id}
whileHover={{ scale: 1.01 }}
whileTap={{ scale: 0.99 }}
className="w-full bg-amber-500 hover:bg-amber-600 disabled:bg-amber-300 text-white font-bold py-4 px-6 rounded-2xl text-lg transition-all shadow-lg hover:shadow-xl flex items-center justify-center gap-3"
>
{payingId === r.id ? (
<>
<Loader2 className="w-5 h-5 animate-spin" />
{t('payments.processingPayment')}
</>
) : (
<>
<Banknote className="w-5 h-5" />
{t('payments.payButton', { amount: formatCurrency(amount, r.currencySign) })}
</>
)}
</motion.button>
</div>
2026-06-24 15:04:56 +03:00
2026-07-15 19:25:39 +03:00
{showReceiptModal && (
<div className="fixed inset-0 z-60 flex items-center justify-center bg-black/60 px-4 py-8">
<motion.div
initial={{ opacity: 0, scale: 0.95 }}
animate={{ opacity: 1, scale: 1 }}
className="w-full max-w-md rounded-3xl bg-white p-6 shadow-2xl border border-gray-200"
>
<div className="flex items-center justify-between mb-4">
<div>
<h3 className="text-xl font-bold text-gray-900">{t('payments.receiptDialogTitle')}</h3>
<p className="text-sm text-gray-600 mt-1">{t('payments.receiptDialogDescription')}</p>
</div>
<div className="w-12 h-12 bg-amber-100 rounded-2xl flex items-center justify-center">
<CreditCard className="w-6 h-6 text-amber-600" />
</div>
</div>
<label className="block text-sm font-bold text-gray-700 mb-2">
{t('payments.uploadReceipt')}
</label>
<input
type="file"
accept="image/*"
onChange={handleReceiptSelection}
className="block w-full rounded-2xl border border-gray-300 bg-white px-4 py-3 text-sm text-gray-700 file:mr-4 file:rounded-xl file:border-0 file:bg-amber-500 file:px-4 file:py-2 file:text-white hover:file:bg-amber-600"
/>
{receiptFileName && (
<div className="mt-3 rounded-2xl border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-800">
{t('payments.receiptSelected')} {receiptFileName}
</div>
)}
{localPaymentImage && receiptPreviewUrl && (
<div className="mt-4 overflow-hidden rounded-2xl border border-gray-200 bg-gray-50 p-2">
<img
src={receiptPreviewUrl}
alt={t('payments.uploadReceipt')}
className="h-48 w-full rounded-xl object-cover"
/>
</div>
)}
<div className="mt-6 flex flex-col gap-3 sm:flex-row">
<button
type="button"
onClick={() => setShowReceiptModal(false)}
className="w-full rounded-xl border border-gray-300 px-4 py-3 text-sm font-semibold text-gray-700 hover:bg-gray-100"
>
{t('payments.closeButton')}
</button>
<button
type="button"
onClick={handleReceiptConfirm}
className="w-full rounded-xl bg-amber-500 px-4 py-3 text-sm font-semibold text-white hover:bg-amber-600"
>
{t('payments.continueToPay')}
</button>
</div>
</motion.div>
</div>
)}
2026-07-11 05:21:38 -07:00
{/* Cash pay button */}
<div className="px-6 py-4 border-b border-gray-100">
<button
type="button"
onClick={() => setShowCashDialog(true)}
className="w-full bg-white border-2 border-amber-200 hover:border-amber-400 text-amber-700 font-bold py-3 px-6 rounded-2xl text-base transition-all flex items-center justify-center gap-2"
2026-06-24 15:04:56 +03:00
>
2026-07-11 05:21:38 -07:00
<Building className="w-5 h-5" />
{t('payments.payCashButton')}
</button>
</div>
{/* Cash payment dialog */}
{showCashDialog && (
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 px-4 py-8">
<motion.div
initial={{ opacity: 0, scale: 0.95 }}
animate={{ opacity: 1, scale: 1 }}
className="w-full max-w-md rounded-3xl bg-white p-8 shadow-2xl border border-gray-200 text-center"
>
<div className="w-16 h-16 bg-amber-100 rounded-full flex items-center justify-center mx-auto mb-5">
<Clock className="w-8 h-8 text-amber-600" />
</div>
<h3 className="text-xl font-bold text-gray-900 mb-3">{t('payments.cashPendingDialogTitle')}</h3>
<p className="text-gray-600 leading-relaxed mb-6">
{t('payments.cashPendingDialogDesc1')}
<br />
{t('payments.cashPendingDialogDesc2')}
</p>
<div className="bg-gray-50 rounded-2xl p-4 mb-6 text-right">
<p className="text-sm font-bold text-gray-800 mb-1">{t('payments.platformOfficeLabel')}</p>
<p className="text-sm text-gray-600">{t('payments.platformOfficeFullAddress')}</p>
<p className="text-sm text-gray-600 flex items-center gap-1 mt-1" dir="ltr">
<Phone className="w-3.5 h-3.5" />
+963567823411
</p>
</div>
<div className="flex flex-col gap-3 sm:flex-row">
<button
type="button"
onClick={() => setShowCashDialog(false)}
className="w-full px-5 py-3 rounded-xl border border-gray-300 text-gray-700 hover:bg-gray-100 transition-colors font-medium"
>
{t('payments.closeButton')}
</button>
<Link
href="/reservations"
className="w-full px-5 py-3 rounded-xl bg-amber-500 text-white font-semibold text-center hover:bg-amber-600 transition-colors"
>
{t('payments.myReservationsLink')}
</Link>
</div>
</motion.div>
</div>
)}
{/* Platform location */}
<div className="px-6 py-5 bg-gray-50">
<div className="flex items-start gap-3">
<Landmark className="w-5 h-5 text-amber-600 shrink-0 mt-0.5" />
<div>
<p className="text-sm font-bold text-gray-800 mb-1">{t('payments.cashPaymentLocationLabel')}</p>
<p className="text-sm text-gray-600 leading-relaxed">
{t('payments.platformOfficeFullAddress')}
</p>
<p className="text-sm text-gray-600 flex items-center gap-1 mt-1">
2026-06-24 15:04:56 +03:00
<Phone className="w-3.5 h-3.5" />
2026-07-11 05:21:38 -07:00
<span dir="ltr">+963567823411</span>
2026-06-24 15:04:56 +03:00
</p>
</div>
</div>
</div>
2026-07-11 05:21:38 -07:00
</motion.div>
2026-06-24 15:04:56 +03:00
</>
);
2026-07-11 05:21:38 -07:00
}