/**
 * Retrieves the translation of text.
 *
 * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-i18n/
 */
import { __ } from '@wordpress/i18n';


/**
 * Use Effect Hook
 */
import { useEffect } from '@wordpress/element';

/**
 * React hook that is used to mark the block wrapper element.
 * It provides all the necessary props like the class name.
 *
 * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops
 */
import { useBlockProps, InnerBlocks } from '@wordpress/block-editor';

/**
 * Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files.
 * Those files can contain any CSS code that gets applied to the editor.
 *
 * @see https://www.npmjs.com/package/@wordpress/scripts#using-css
 */
import './editor.scss';
import SidePanel from './side-panel';

/**
 * The edit function describes the structure of your block in the context of the
 * editor. This represents what the editor will render when the block is used.
 *
 * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/#edit
 *
 * @return {Element} Element to render.
 */
export default function Edit({ attributes, setAttributes, isSelected }) {
  const { sections, currentSection } = attributes;
  const blockProps = useBlockProps({
    className: 'wp-block-documentation documentation-editor',
  });

  // Fonction pour arrêter la propagation des événements au parent
  const handleClick = (e) => {
    e.stopPropagation();
  };

  return (
    <div {...blockProps} onClick={handleClick}>
      <div className="documentation-layout">
        {/* Left Navigation Panel */}
        <div className="documentation-nav">
          <div className="documentation-sections">
          {sections.map((section) => (
            <div key={section.id} className="nav-section">
              <h3> <span className="section-icon" dangerouslySetInnerHTML={{ __html: section.svg }}></span> {section.title}</h3>
              <nav>
                {section.links.map((link) => (
                  <div 
                    key={link.id}
                    className={`nav-item ${currentSection === link.id ? 'active' : ''}`}
                    onClick={() => setAttributes({ currentSection: link.id })}
                  >
                    
                    {link.title}
                  </div>
                ))}
              </nav>
            </div>
          ))}
          </div>
        </div>

        {/* Middle Content Area */}
        <div className="documentation-content">
          <InnerBlocks />
        </div>

       
      </div>
      <SidePanel attributes={attributes} setAttributes={setAttributes} />
    </div>
  );
}
