File size: 8,368 Bytes
74c227b
34a3b10
 
 
 
74c227b
34a3b10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74c227b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34a3b10
 
74c227b
34a3b10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250

document.addEventListener('DOMContentLoaded', function() {
  // Smooth scrolling for anchor links
  document.querySelectorAll('a[href^="#"]').forEach(anchor => {
    anchor.addEventListener('click', function(e) {
e.preventDefault();
      const targetId = this.getAttribute('href');
      if(targetId === '#') return;
      
      const targetElement = document.querySelector(targetId);
      if(targetElement) {
        window.scrollTo({
          top: targetElement.offsetTop - 100,
          behavior: 'smooth'
        });
      }
    });
  });
  
  // Handle initial hash in URL
  if(window.location.hash) {
    const target = document.querySelector(window.location.hash);
    if(target) {
      setTimeout(() => {
        window.scrollTo({
          top: target.offsetTop - 100,
          behavior: 'smooth'
        });
      }, 100);
    }
  }
  
  // Free delivery popup
  const hoveredElement = document.querySelector('.hovered-element');
  const freeDeliveryPopup = document.getElementById('freeDeliveryPopup');
  
  if (hoveredElement && freeDeliveryPopup) {
    hoveredElement.addEventListener('click', function() {
      // Hide the original element
      this.style.display = 'none';
      
      // Show the popup
      freeDeliveryPopup.classList.remove('hidden');
      
      // Hide the popup after 4 seconds
      setTimeout(() => {
        freeDeliveryPopup.classList.add('hidden');
        this.style.display = 'block';
      }, 4000);
    });
  }
  
  // Slider functionality
  const slider = document.getElementById('slider');
const prevBtn = document.getElementById('prevBtn');
  const nextBtn = document.getElementById('nextBtn');
  const dotsContainer = document.getElementById('dots');

  let currentIndex = 0;
  let photos = [
    { url: 'https://doczyscimy.pl/wp-content/uploads/2024/02/IMG_20211129_100823-scaled.jpg', caption: 'Pranie tapicerki' },
    { url: 'https://doczyscimy.pl/wp-content/uploads/2024/02/IMG_20211129_133710-scaled.jpg', caption: 'Profesjonalne czyszczenie' },
    { url: 'https://doczyscimy.pl/wp-content/uploads/2024/02/IMG_20220530_102405-1-scaled.jpg', caption: 'Czyszczenie mebli' },
    { url: 'https://doczyscimy.pl/wp-content/uploads/2024/02/IMG_20220604_173045-1-scaled.jpg', caption: 'Efekty przed i po' },
    { url: 'https://doczyscimy.pl/wp-content/uploads/2024/02/inbound5315846421320199128.jpg', caption: 'Głębokie czyszczenie' },
    { url: 'https://doczyscimy.pl/wp-content/uploads/2024/02/inbound4582808579900059862.jpg', caption: 'Odświeżanie mebli' },
    { url: 'https://doczyscimy.pl/wp-content/uploads/2024/02/IMG_20220506_120325.jpg', caption: 'Profesjonalna usługa' }
  ];

  function renderSlider() {
    slider.innerHTML = '';
    
    photos.forEach((photo, index) => {
      const slide = document.createElement('div');
      slide.className = `absolute inset-0 transition-opacity duration-500 ${index === currentIndex ? 'opacity-100' : 'opacity-0'}`;
      
      const img = document.createElement('img');
      img.src = photo.url;
      img.alt = photo.caption || 'Slide image';
      img.className = 'w-full h-full object-cover';
      
      if (photo.caption) {
        const caption = document.createElement('div');
        caption.className = 'absolute bottom-0 left-0 right-0 bg-black/50 text-white p-4 text-center';
        caption.textContent = photo.caption;
        slide.appendChild(caption);
      }
      
      slide.appendChild(img);
      slider.appendChild(slide);
    });

    updateDots();
    feather.replace();
  }

  function updateDots() {
    dotsContainer.innerHTML = '';
    photos.forEach((_, index) => {
      const dot = document.createElement('div');
      dot.className = `w-3 h-3 rounded-full cursor-pointer ${index === currentIndex ? 'bg-gray-800' : 'bg-gray-300'}`;
      dot.addEventListener('click', () => {
        currentIndex = index;
        renderSlider();
      });
      dotsContainer.appendChild(dot);
    });
  }

  function nextSlide() {
    currentIndex = (currentIndex + 1) % photos.length;
    renderSlider();
  }

  function prevSlide() {
    currentIndex = (currentIndex - 1 + photos.length) % photos.length;
    renderSlider();
  }

  // Event listeners
  nextBtn.addEventListener('click', nextSlide);
  prevBtn.addEventListener('click', prevSlide);

  // Keyboard navigation
  document.addEventListener('keydown', (e) => {
    if (e.key === 'ArrowRight') nextSlide();
    if (e.key === 'ArrowLeft') prevSlide();
  });

  // Auto-advance slides every 6 seconds
  const slideInterval = setInterval(nextSlide, 6000);

  // Initial render
  renderSlider();
  
  // FAQ accordion
  const faqButtons = document.querySelectorAll('.bg-white button');
  faqButtons.forEach(button => {
    button.addEventListener('click', function() {
      const content = this.nextElementSibling;
      const icon = this.querySelector('i');
      
      if (content.classList.contains('hidden')) {
        content.classList.remove('hidden');
        icon.setAttribute('data-feather', 'chevron-up');
      } else {
        content.classList.add('hidden');
        icon.setAttribute('data-feather', 'chevron-down');
      }
      feather.replace();
    });
  });
  
  // Contact form handling
  const form = document.getElementById('contactForm');
  const submitText = document.getElementById('submitText');
  const spinner = document.getElementById('spinner');
  const statusEl = document.getElementById('formStatus');
  const endpoint = '/wp-json/custom/v1/contact';
  
  async function handleSubmit(e) {
    e.preventDefault();
    
    // Show loading state
    submitText.classList.add('hidden');
    spinner.classList.remove('hidden');
    statusEl.textContent = '';
    statusEl.className = 'contact-form__status';

    // Get selected service and date
    const serviceSelect = document.getElementById('service');
    const serviceText = serviceSelect.options[serviceSelect.selectedIndex].text;
    const serviceDate = document.getElementById('service-date').value;
    
    const formData = new FormData(form);
    
    // Add service and date info to message
    const originalMessage = formData.get('message') || '';
    const phoneNumber = formData.get('phone') || '';
    formData.set('message', `Usługa: ${serviceText}\nPreferowana data: ${serviceDate}\nTelefon: ${phoneNumber}\n\n${originalMessage}`);
    
    // Validate files
    const files = form.querySelector('input[name="attachment"]').files;
    if (files.length > 3) {
      showError('Możesz dodać maksymalnie 3 zdjęcia');
      resetForm();
      return;
    }

    for (let file of files) {
      if (file.size > 5 * 1024 * 1024) {
        showError(`Plik "${file.name}" jest za duży (max 5MB)`);
        resetForm();
        return;
      }
    }
    
    try {
      const response = await fetch(endpoint, {
        method: 'POST',
        body: formData
      });

      const data = await response.json();

      if (response.ok && data.success) {
        showSuccess('Dziękujemy! Twoja wiadomość została wysłana. Skontaktujemy się z Tobą w ciągu 24 godzin.');
        form.reset();
      } else {
        showError(data.message || 'Wystąpił błąd podczas wysyłania formularza. Spróbuj ponownie.');
      }
    } catch (error) {
      showError('Błąd połączenia. Sprawdź swoje połączenie internetowe i spróbuj ponownie.');
    } finally {
      resetForm();
    }
  }

  function showSuccess(message) {
    statusEl.textContent = message;
    statusEl.classList.add('contact-form__status--success');
  }

  function showError(message) {
    statusEl.textContent = message;
    statusEl.classList.add('contact-form__status--error');
  }

  function resetForm() {
    submitText.classList.remove('hidden');
    spinner.classList.add('hidden');
  }

  form.addEventListener('submit', handleSubmit);
  
  // Initialize calendar icon
  feather.replace();

  // Dynamic file input label
  const fileInput = document.getElementById('attachment');
  fileInput.addEventListener('change', function() {
    const label = this.nextElementSibling;
    if (this.files.length > 0) {
      const fileNames = Array.from(this.files).map(file => file.name).join(', ');
      label.textContent = `Wybrano ${this.files.length} plików: ${fileNames}`;
    } else {
      label.textContent = 'Możesz dodać maksymalnie 3 zdjęcia (do 5MB każde)';
    }
  });
});