import { SectionTitleArrow } from '@/entities/common/ui/section-title-arrow';
import { InfoWrapKeys, MerchantMidResponse } from '../../model/types';
import SlideDown from 'react-slidedown';
import 'react-slidedown/lib/slidedown.css';
import { useEffect, useState } from 'react';

export interface ManagerInfoWrapProps {
  type: InfoWrapKeys;
  title?: string;
  manager?: string;
  managerTelephone?: string;
  managetEmail?: string;
  openChild: InfoWrapKeys | null;
  setOpenChild: (openChild: InfoWrapKeys | null) => void;
};

export const ManagerInfoWrap = ({
  type,
  title,
  manager,
  managerTelephone,
  managetEmail,
  openChild,
  setOpenChild
}: ManagerInfoWrapProps) => {

  const [isOpen, setIsOpen] = useState<boolean>(false);

  const opeSection = () => {
    const staus = !isOpen;
    setIsOpen(staus);
    if(!!staus){
      setOpenChild(type);  
    }
    else {
      setOpenChild(null)
    }
  };

  useEffect(() => {
    if(!!openChild && openChild !== type){
    setIsOpen(false);
    }
  }, [openChild]);
  
  return (
    <>
      <div className="section">
        <div className="section-title"
          onClick={ () => opeSection() }
        >
          { title } <SectionTitleArrow isOpen={ isOpen }></SectionTitleArrow>
        </div>
        <SlideDown className={'my-dropdown-slidedown'}>
        { isOpen &&
          <ul className="kv-list">
            <li className="kv-row">
              <span className="k">{ manager }</span>
              <span className="v"></span>
            </li>
            <li className="kv-row">
              <span className="k">{ managerTelephone }</span>
              <span className="v"></span>
            </li>
            <li className="kv-row">
              <span className="k">{ managetEmail }</span>
              <span className="v"></span>
            </li>
          </ul>
        }
        </SlideDown> 
      </div>
    </>
  );
};