/**
 * Automation2Page
 *
 * n8n-style flow builder with backend-driven node list.
 */
import React from 'react';
import { useSearchParams } from 'react-router-dom';
import { useInstanceId } from '../../../hooks/useCurrentInstance';
import { useLanguage } from '../../../providers/language/LanguageContext';
import { Automation2FlowEditor } from '../../../components/Automation2FlowEditor';
import styles from '../../FeatureView.module.css';

export const Automation2Page: React.FC = () => {
  const instanceId = useInstanceId();
  const [searchParams] = useSearchParams();
  const workflowId = searchParams.get('workflowId');
  const { currentLanguage } = useLanguage();
  const language = (currentLanguage?.slice(0, 2) || 'de') as string;

  if (!instanceId) {
    return (
      <div className={styles.placeholder}>
        <h2>Automation 2</h2>
        <p>Keine Feature-Instanz gefunden.</p>
      </div>
    );
  }

  return (
    <div style={{ flex: 1, minHeight: 0, display: 'flex' }}>
      <Automation2FlowEditor
        instanceId={instanceId}
        language={language}
        initialWorkflowId={workflowId}
      />
    </div>
  );
};
