/src/modules/FAQ/components/two/index.tsx
'use client'
import { ComponentFaqTwo, Maybe } from "@/types/gpl/graphql";
import styles from "./index.module.scss";
import Image from "@/modules/common/components/image";
import Button from "@/modules/common/components/button/border";
import { useState } from "react";
interface Props {
  param: Maybe<ComponentFaqTwo> | undefined;
}
export default function CtaTwo({ param }: Props) {
    const [activeSet, setActiveSet] = useState<Set<number>>(new Set([]));

  const toggleItem = (index: number) => {

    setActiveSet(prev => {
      const newSet = new Set(prev);
      if (newSet.has(index)) {
        newSet.delete(index);
      } else {
        newSet.add(index);
      }
      return newSet;
    });
  }
  return (
      <section className={styles.container}>
        <div className={styles.content}>
          <div className={styles.left}>
            <div className={styles.head}>
              <span className={styles.subTitle}>{param?.tip}</span>
              <h2 className={styles.mainTitle}>
                {param?.title}
              </h2>
            </div>
            <div className={styles.faqContainer}>
              {param?.list?.map((item, index) => (
                <div key={index} className={styles.faqItem}>
                  <button
                    className={styles.questionBtn}
                    onClick={() => toggleItem(index)}
                  >
                    <span className={`${styles.questionText} ${activeSet.has(index) ? styles.active : ''}`}>{item?.title}</span>
                    <span className={`${styles.arrowIcon} ${activeSet.has(index) ? styles.arrowUp : ''}`}>
                      <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                      <path d="M6 9L12 15L18 9" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
                      </svg>
                    </span>
                  </button>
                  <div className={`${styles.answerPanel} ${activeSet.has(index) ? styles.open : ''}`}>
                    <p>{item?.desc}</p>
                  </div>
                </div>
              ))}
            </div>
          </div>
          <div className={styles.right}>
            <div className={styles.imgWrap}>
              <Image image={param?.img} />
            </div>
          </div>
        </div>
      </section>
  );
}
/src/modules/FAQ/components/two/index.module.scss
.container {
  padding: 80px 20px;
  background: var(--back-color);

  .content {
    width: 100%;
    max-width: var(--max-width);
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 20px;

    @include lg {
      flex-direction: row;
      gap: 40px;
    }

    .left {
      flex: 1;

      .head {
        margin-bottom: 40px;

        .subTitle {
          font-size: var(--font-sm);
          color: var(--primary-color);
          font-weight: 500;
        }

        .mainTitle {
          font-size: var(--font-3xl);
          font-weight: 400;
          margin-top: 40px;
          font-family: "Playfair display", serif;
        }
      }

      .faqContainer {
        gap: 24px;

        .faqItem {
          margin: 30px 0;
          border-bottom: 1px solid #000;

          .questionBtn {
            width: 100%;
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0;
            margin-bottom: 10px;
            background: transparent;
            border: none;
            cursor: pointer;
            text-align: left;

            .questionText {
              font-size: 18px;
              color: #000;
            }

            .active {
              color: var(--primary-color) !important;
            }

            .arrowIcon {
              font-size: 18px;
              color: #000;
              transition: transform 0.2s ease;

              &.arrowUp {
                transform: rotate(180deg);
                color: var(--primary-color);
              }
            }
          }

          .answerPanel {
            transition: max-height 0.4s ease;
            max-height: 0;
            overflow: hidden;

            p {
              font-size: 17px;
              line-height: 1.6;
              color: #444;
            }
          }

          .open {
            max-height: 100px !important;
          }
        }
      }
    }

    .right {
      flex: 1;
      display: flex;
      align-items: center;
      justify-content: center;

      .imgWrap {
        width: 100%;
        aspect-ratio: 14/15;
        border-radius: 10px;
        overflow: hidden;
      }
    }
  }
}