# 🔧 Fix Full-Width Scroll - نمایش کامل اسکرول

## مشکل: نوار اسکرول به خاطر container محدود شده

### راه‌حل: خارج کردن اسکرول از container

---

## 1. Home Features - نسخه Full Width

```jsx
// src/components/HomePage/HomeFeatures.jsx
import React, { useEffect, useState, useRef } from 'react';
import * as Icons from 'lucide-react';
import { ChevronLeft, ChevronRight } from 'lucide-react';

const HomeFeatures = () => {
  const [features, setFeatures] = useState([]);
  const [loading, setLoading] = useState(true);
  const scrollRef = useRef(null);
  const [canScrollLeft, setCanScrollLeft] = useState(false);
  const [canScrollRight, setCanScrollRight] = useState(false);

  useEffect(() => {
    fetchFeatures();
  }, []);

  const fetchFeatures = async () => {
    try {
      const response = await fetch('http://localhost:8000/api/home-features');
      const data = await response.json();
      setFeatures(data.data);
    } catch (error) {
      console.error('Error fetching features:', error);
    } finally {
      setLoading(false);
    }
  };

  useEffect(() => {
    checkScroll();
    window.addEventListener('resize', checkScroll);
    return () => window.removeEventListener('resize', checkScroll);
  }, [features]);

  const checkScroll = () => {
    if (scrollRef.current) {
      const { scrollLeft, scrollWidth, clientWidth } = scrollRef.current;
      setCanScrollLeft(scrollLeft > 0);
      setCanScrollRight(scrollLeft < scrollWidth - clientWidth - 10);
    }
  };

  const scroll = (direction) => {
    if (scrollRef.current) {
      const scrollAmount = 300;
      scrollRef.current.scrollBy({
        left: direction === 'left' ? -scrollAmount : scrollAmount,
        behavior: 'smooth'
      });
      setTimeout(checkScroll, 300);
    }
  };

  if (loading) {
    return (
      <div className="container mx-auto px-4 py-8">
        <div className="grid grid-cols-2 md:grid-cols-4 gap-4">
          {[1, 2, 3, 4].map((i) => (
            <div key={i} className="animate-pulse">
              <div className="bg-gray-200 rounded-2xl h-32"></div>
            </div>
          ))}
        </div>
      </div>
    );
  }

  if (features.length === 0) return null;

  const showScrollButtons = features.length > 4;

  return (
    <section className="py-12 bg-gradient-to-b from-gray-50 to-white overflow-hidden">
      {/* Desktop Grid View (4 items or less) */}
      {!showScrollButtons && (
        <div className="container mx-auto px-4">
          <div className="grid grid-cols-2 md:grid-cols-4 gap-6">
            {features.map((feature) => {
              const IconComponent = Icons[feature.icon] || Icons.Box;
              
              return (
                <div
                  key={feature.id}
                  className="group relative overflow-hidden rounded-2xl p-6 text-center transition-all duration-500 hover:scale-105 hover:shadow-2xl cursor-pointer"
                  style={{
                    backgroundColor: feature.bg_color,
                    color: feature.text_color
                  }}
                >
                  {/* Decorative Elements */}
                  <div className="absolute top-0 right-0 w-20 h-20 rounded-full opacity-10 blur-2xl group-hover:opacity-20 transition-opacity"
                    style={{ backgroundColor: feature.icon_color }}
                  ></div>
                  <div className="absolute bottom-0 left-0 w-16 h-16 rounded-full opacity-10 blur-2xl group-hover:opacity-20 transition-opacity"
                    style={{ backgroundColor: feature.icon_color }}
                  ></div>

                  {/* Content */}
                  <div className="relative z-10">
                    <div className="mb-4 transform transition-transform duration-500 group-hover:scale-110 group-hover:rotate-12">
                      <IconComponent
                        size={48}
                        style={{ color: feature.icon_color }}
                        className="mx-auto drop-shadow-lg"
                        strokeWidth={2}
                      />
                    </div>
                    <h3 className="text-lg font-bold mb-2 drop-shadow-sm">
                      {feature.title}
                    </h3>
                    <p className="text-sm opacity-90 leading-relaxed">
                      {feature.description}
                    </p>
                  </div>

                  {/* Hover Border Effect */}
                  <div className="absolute inset-0 rounded-2xl opacity-0 group-hover:opacity-100 transition-opacity duration-300"
                    style={{
                      boxShadow: `inset 0 0 0 2px ${feature.icon_color}`
                    }}
                  ></div>
                </div>
              );
            })}
          </div>
        </div>
      )}

      {/* ⭐ Full Width Scrollable View (more than 4 items) */}
      {showScrollButtons && (
        <div className="relative w-full">
          {/* Scroll Left Button */}
          {canScrollLeft && (
            <button
              onClick={() => scroll('left')}
              className="absolute left-4 top-1/2 -translate-y-1/2 z-20 bg-white shadow-xl rounded-full p-3 hover:bg-gray-100 transition-all duration-300 hover:scale-110"
              aria-label="اسکرول به چپ"
            >
              <ChevronLeft size={24} className="text-gray-800" />
            </button>
          )}

          {/* Scroll Right Button */}
          {canScrollRight && (
            <button
              onClick={() => scroll('right')}
              className="absolute right-4 top-1/2 -translate-y-1/2 z-20 bg-white shadow-xl rounded-full p-3 hover:bg-gray-100 transition-all duration-300 hover:scale-110"
              aria-label="اسکرول به راست"
            >
              <ChevronRight size={24} className="text-gray-800" />
            </button>
          )}

          {/* ⭐ Scrollable Container - بدون container - FULL WIDTH */}
          <div
            ref={scrollRef}
            onScroll={checkScroll}
            className="flex gap-6 overflow-x-auto scrollbar-hide scroll-smooth px-4 md:px-8"
            style={{
              scrollbarWidth: 'none',
              msOverflowStyle: 'none',
            }}
          >
            {/* Spacer برای شروع از لبه */}
            <div className="flex-shrink-0 w-4 md:w-8"></div>
            
            {features.map((feature) => {
              const IconComponent = Icons[feature.icon] || Icons.Box;
              
              return (
                <div
                  key={feature.id}
                  className="group relative flex-shrink-0 w-72 overflow-hidden rounded-2xl p-6 text-center transition-all duration-500 hover:scale-105 hover:shadow-2xl cursor-pointer"
                  style={{
                    backgroundColor: feature.bg_color,
                    color: feature.text_color
                  }}
                >
                  {/* Decorative Elements */}
                  <div className="absolute top-0 right-0 w-20 h-20 rounded-full opacity-10 blur-2xl group-hover:opacity-20 transition-opacity"
                    style={{ backgroundColor: feature.icon_color }}
                  ></div>
                  <div className="absolute bottom-0 left-0 w-16 h-16 rounded-full opacity-10 blur-2xl group-hover:opacity-20 transition-opacity"
                    style={{ backgroundColor: feature.icon_color }}
                  ></div>

                  {/* Content */}
                  <div className="relative z-10">
                    <div className="mb-4 transform transition-transform duration-500 group-hover:scale-110 group-hover:rotate-12">
                      <IconComponent
                        size={48}
                        style={{ color: feature.icon_color }}
                        className="mx-auto drop-shadow-lg"
                        strokeWidth={2}
                      />
                    </div>
                    <h3 className="text-lg font-bold mb-2 drop-shadow-sm">
                      {feature.title}
                    </h3>
                    <p className="text-sm opacity-90 leading-relaxed">
                      {feature.description}
                    </p>
                  </div>

                  {/* Hover Border Effect */}
                  <div className="absolute inset-0 rounded-2xl opacity-0 group-hover:opacity-100 transition-opacity duration-300"
                    style={{
                      boxShadow: `inset 0 0 0 2px ${feature.icon_color}`
                    }}
                  ></div>
                </div>
              );
            })}
            
            {/* Spacer برای پایان در لبه */}
            <div className="flex-shrink-0 w-4 md:w-8"></div>
          </div>

          {/* Gradient Fade Effects */}
          {canScrollLeft && (
            <div className="absolute left-0 top-0 bottom-0 w-24 bg-gradient-to-r from-white to-transparent pointer-events-none z-10"></div>
          )}
          {canScrollRight && (
            <div className="absolute right-0 top-0 bottom-0 w-24 bg-gradient-to-l from-white to-transparent pointer-events-none z-10"></div>
          )}
        </div>
      )}
    </section>
  );
};

export default HomeFeatures;
```

---

## 2. Product Showcases - نسخه Full Width

```jsx
// src/components/HomePage/ProductShowcases.jsx
// فقط بخش ShowcaseSection رو تغییر میدیم

const ShowcaseSection = ({ showcase }) => {
  const scrollRef = useRef(null);
  const [canScrollLeft, setCanScrollLeft] = useState(false);
  const [canScrollRight, setCanScrollRight] = useState(false);
  const [showViewAll, setShowViewAll] = useState(false);

  useEffect(() => {
    checkScroll();
    window.addEventListener('resize', checkScroll);
    return () => window.removeEventListener('resize', checkScroll);
  }, [showcase.products]);

  const checkScroll = () => {
    if (scrollRef.current) {
      const { scrollLeft, scrollWidth, clientWidth } = scrollRef.current;
      setCanScrollLeft(scrollLeft > 0);
      setCanScrollRight(scrollLeft < scrollWidth - clientWidth - 10);
      setShowViewAll(showcase.products.length > 4);
    }
  };

  const scroll = (direction) => {
    if (scrollRef.current) {
      const scrollAmount = 320;
      scrollRef.current.scrollBy({
        left: direction === 'left' ? -scrollAmount : scrollAmount,
        behavior: 'smooth'
      });
      setTimeout(checkScroll, 300);
    }
  };

  const displayType = showcase.display_type || 'grid';
  const products = showcase.products || [];

  if (products.length === 0) return null;

  return (
    <section
      className="py-12 relative overflow-hidden"
      style={{ backgroundColor: showcase.bg_color }}
    >
      {/* ⭐ Header در داخل container */}
      <div className="container mx-auto px-4 mb-8">
        <div className="flex items-center justify-between">
          <div>
            <h2
              className="text-3xl md:text-4xl font-bold mb-2 drop-shadow-sm"
              style={{ color: showcase.title_color }}
            >
              {showcase.title}
            </h2>
            {showcase.subtitle && (
              <p className="text-gray-600 text-lg">{showcase.subtitle}</p>
            )}
          </div>
          {showViewAll && (
            <Link
              to={`/showcases/${showcase.id}`}
              className="group flex items-center gap-2 px-6 py-3 bg-white rounded-xl shadow-lg hover:shadow-xl transition-all duration-300 hover:scale-105"
              style={{ color: showcase.title_color }}
            >
              <span className="font-medium">مشاهده همه</span>
              <ArrowLeft size={20} className="group-hover:-translate-x-1 transition-transform" />
            </Link>
          )}
        </div>
      </div>

      {/* Products Display */}
      {displayType === 'grid' && products.length <= 4 ? (
        /* Grid View for 4 or less - در داخل container */
        <div className="container mx-auto px-4">
          <div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-6">
            {products.map((product) => (
              <ProductCard key={product.id} product={product} />
            ))}
          </div>
        </div>
      ) : (
        /* ⭐ Full Width Scrollable View */
        <div className="relative w-full">
          {/* Scroll Buttons */}
          {canScrollLeft && (
            <button
              onClick={() => scroll('left')}
              className="absolute left-4 top-1/2 -translate-y-1/2 z-20 bg-white shadow-2xl rounded-full p-4 hover:bg-gray-100 transition-all duration-300 hover:scale-110"
            >
              <ChevronLeft size={24} className="text-gray-800" />
            </button>
          )}
          {canScrollRight && (
            <button
              onClick={() => scroll('right')}
              className="absolute right-4 top-1/2 -translate-y-1/2 z-20 bg-white shadow-2xl rounded-full p-4 hover:bg-gray-100 transition-all duration-300 hover:scale-110"
            >
              <ChevronRight size={24} className="text-gray-800" />
            </button>
          )}

          {/* ⭐ Products Container - FULL WIDTH بدون container */}
          <div
            ref={scrollRef}
            onScroll={checkScroll}
            className="flex gap-6 overflow-x-auto scrollbar-hide scroll-smooth px-4 md:px-8"
            style={{
              scrollbarWidth: 'none',
              msOverflowStyle: 'none',
            }}
          >
            {/* Spacer */}
            <div className="flex-shrink-0 w-4 md:w-8"></div>
            
            {products.map((product) => (
              <div key={product.id} className="flex-shrink-0 w-72">
                <ProductCard product={product} />
              </div>
            ))}
            
            {/* Spacer */}
            <div className="flex-shrink-0 w-4 md:w-8"></div>
          </div>

          {/* Gradient Fade */}
          {canScrollLeft && (
            <div 
              className="absolute left-0 top-0 bottom-0 w-24 pointer-events-none z-10"
              style={{
                background: `linear-gradient(to right, ${showcase.bg_color || '#ffffff'}, transparent)`
              }}
            ></div>
          )}
          {canScrollRight && (
            <div 
              className="absolute right-0 top-0 bottom-0 w-24 pointer-events-none z-10"
              style={{
                background: `linear-gradient(to left, ${showcase.bg_color || '#ffffff'}, transparent)`
              }}
            ></div>
          )}
        </div>
      )}
    </section>
  );
};
```

---

## 3. CSS اضافی برای نمایش بهتر

```css
/* src/index.css */

/* مخفی کردن scrollbar */
.scrollbar-hide {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.scrollbar-hide::-webkit-scrollbar {
  display: none;
}

/* جلوگیری از overflow افقی در body */
body {
  overflow-x: hidden;
}

/* Smooth scroll */
.scroll-smooth {
  scroll-behavior: smooth;
}

/* بهینه‌سازی performance اسکرول */
.overflow-x-auto {
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x proximity;
}

/* Snap برای آیتم‌ها (اختیاری) */
.snap-item {
  scroll-snap-align: start;
}
```

---

## 🔍 تفاوت‌های کلیدی:

### ❌ قبل (محدود به container):
```jsx
<div className="container mx-auto px-4">
  <div className="overflow-x-auto">
    {/* محتوا */}
  </div>
</div>
```

### ✅ بعد (Full Width):
```jsx
<div className="relative w-full">
  <div className="overflow-x-auto px-4">
    <div className="flex-shrink-0 w-8"></div>
    {/* محتوا */}
    <div className="flex-shrink-0 w-8"></div>
  </div>
</div>
```

---

## 📐 ساختار Layout:

```
┌─────────────────────────────────────────┐
│  Header (در container)                  │
│  Title + مشاهده همه                     │
└─────────────────────────────────────────┘
┌─────────────────────────────────────────┐
│ [◄] Full Width Scroll Area          [►] │
│ ┌──┬────┬────┬────┬────┬────┬────┬────┐ │
│ │sp│Item│Item│Item│Item│Item│Item│sp  │ │
│ └──┴────┴────┴────┴────┴────┴────┴────┘ │
└─────────────────────────────────────────┘
    └─ Spacer برای padding
```

---

## ✅ چک‌لیست

- [x] حذف `container` از بخش اسکرول
- [x] اضافه کردن Spacer در ابتدا و انتها
- [x] استفاده از `w-full` برای عرض کامل
- [x] Gradient Fade با رنگ پس‌زمینه
- [x] دکمه‌های Navigation در موقعیت مناسب
- [x] Header همچنان در container
- [x] CSS overflow-x: hidden در body

---

## 🎉 نتیجه

حالا نوار اسکرول **کاملاً Full Width** هست و:
- ✅ از لبه تا لبه صفحه امتداد داره
- ✅ دکمه‌ها در موقعیت مناسب
- ✅ Gradient fade درست کار می‌کنه
- ✅ Padding مناسب از طرفین
- ✅ نمایش زیبا و حرفه‌ای

**مشکل حل شد! 🚀**
