File size: 5,763 Bytes
3596161
 
ade45cd
3596161
 
ade45cd
3596161
 
ade45cd
3596161
 
ade45cd
3596161
 
ade45cd
3596161
 
ade45cd
 
3596161
 
 
ade45cd
3596161
 
 
 
ade45cd
3596161
 
ade45cd
 
3596161
 
 
ade45cd
 
3596161
 
 
 
 
 
 
 
 
 
 
ade45cd
 
 
 
3596161
 
 
 
 
 
 
ade45cd
3596161
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ade45cd
 
3596161
 
 
 
 
 
 
ade45cd
 
 
 
 
3596161
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ade45cd
 
3596161
 
 
 
 
 
ade45cd
 
3596161
 
 
 
 
 
ade45cd
3596161
 
 
ade45cd
 
3596161
 
 
 
 
 
 
ade45cd
3596161
 
ade45cd
3596161
 
 
 
 
 
 
 
 
 
ade45cd
 
3596161
 
 
 
 
 
 
 
ade45cd
 
3596161
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190

// Initialize mobile app when DOM is loaded
document.addEventListener('DOMContentLoaded', function() {
    // Initialize app functionality
    initializeApp();
    
    // Add touch feedback for buttons
    addTouchFeedback();
    
    // Initialize swipe gestures
    initializeSwipeGestures();
    
    // Add haptic feedback simulation
    addHapticFeedback();
    
    // Initialize balance animation
    animateBalance();
});

// Initialize app
function initializeApp() {
    console.log('LibyaPay App Initialized');
    
    // Check if app is running on mobile
    if (isMobileDevice()) {
        document.body.classList.add('mobile-device');
    }
    
    // Initialize touch events
    initializeTouchEvents();
}

// Check if device is mobile
function isMobileDevice() {
    return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
}

// Add touch feedback for buttons
function addTouchFeedback() {
    document.querySelectorAll('button').forEach(button => {
        button.addEventListener('touchstart', function() {
            this.style.transform = 'scale(0.95)';
            this.style.opacity = '0.8';
        });
        
        button.addEventListener('touchend', function() {
            this.style.transform = 'scale(1)';
            this.style.opacity = '1';
        });
    });
}

// Initialize swipe gestures
function initializeSwipeGestures() {
    let touchStartX = 0;
    let touchEndX = 0;
    
    document.addEventListener('touchstart', function(e) {
        touchStartX = e.changedTouches[0].screenX;
    });
    
    document.addEventListener('touchend', function(e) {
        touchEndX = e.changedTouches[0].screenX;
        handleSwipe();
    });
    
    function handleSwipe() {
        const swipeThreshold = 50;
        const diff = touchStartX - touchEndX;
        
        if (Math.abs(diff) > swipeThreshold) {
            if (diff > 0) {
                // Swipe left
                console.log('Swipe left detected');
            } else {
                // Swipe right
                console.log('Swipe right detected');
            }
        }
    }
}

// Add haptic feedback simulation
function addHapticFeedback() {
    document.querySelectorAll('button').forEach(button => {
        button.addEventListener('click', function() {
            // Vibrate if supported
            if (navigator.vibrate) {
                navigator.vibrate(50);
            }
        });
    });
}

// Initialize balance animation
function animateBalance() {
    const balanceElement = document.querySelector('.text-3xl');
    if (balanceElement) {
        const finalBalance = 1234.56;
        let currentBalance = 0;
        const increment = finalBalance / 50;
        
        const animation = setInterval(() => {
            currentBalance += increment;
            if (currentBalance >= finalBalance) {
                balanceElement.textContent = finalBalance.toFixed(2) + ' د.ل';
                clearInterval(animation);
            } else {
                balanceElement.textContent = currentBalance.toFixed(2) + ' د.ل';
            }
        }, 20);
    }
}

// Initialize touch events for better mobile experience
function initializeTouchEvents() {
    // Prevent default touch behaviors
    document.addEventListener('touchmove', function(e) {
        if (e.target.closest('.overflow-y-auto')) {
            // Allow scrolling in scrollable areas
            return;
        }
        e.preventDefault();
    }, { passive: false });
    
    // Add active state styling on touch
    document.addEventListener('touchstart', function(e) {
        if (e.target.closest('button')) {
            e.target.closest('button').classList.add('touch-active');
        }
    });
    
    document.addEventListener('touchend', function(e) {
        document.querySelectorAll('.touch-active').forEach(el => {
            el.classList.remove('touch-active');
        });
    });
}

// Simulate notification updates
function showNotification(message) {
    const notification = document.createElement('div');
    notification.className = 'fixed top-20 right-4 bg-libyana-600 text-white px-4 py-3 rounded-lg shadow-lg z-50 animate-slide-up';
    notification.textContent = message;
    document.body.appendChild(notification);
    
    setTimeout(() => {
        notification.remove();
    }, 3000);
}

// Handle online/offline status
function updateConnectionStatus() {
    const isOnline = navigator.onLine;
    if (!isOnline) {
        showNotification('أنت الآن في وضع عدم الاتصال - يمكنك استخدام الخدمات الأساسية');
    }
}

window.addEventListener('online', updateConnectionStatus);
window.addEventListener('offline', updateConnectionStatus);

// Initialize payment functions
function initiatePayment(amount, recipient) {
    console.log(`Initiating payment: ${amount} د.ل to ${recipient}`);
    showNotification(`جاري إرسال ${amount} د.ل إلى ${recipient}`);
    
    // Simulate payment processing
    setTimeout(() => {
        showNotification('تم إرسال المبلغ بنجاح');
        updateBalance();
    }, 2000);
}

// Update balance after transaction
function updateBalance() {
    const balanceElement = document.querySelector('.text-3xl');
    if (balanceElement) {
        const currentBalance = parseFloat(balanceElement.textContent.replace(' د.ل', ''));
        const newBalance = currentBalance - 100; // Example deduction
        balanceElement.textContent = newBalance.toFixed(2) + ' د.ل';
    }
}

// QR Scanner simulation
function openQRScanner() {
    showNotification('جاري فتح الماسح الضوئي...');
    // In a real app, this would open the camera for QR scanning
}