/**
 * CommunicationFlow - Public Entry Point
 *
 * Single entry for consumers. Wires config + callbacks and renders
 * the CommunicationFlow orchestrator component.
 *
 */

import React from 'react';
import PropTypes from 'prop-types';
import CommunicationFlow from './CommunicationFlow';
import { hasSupportEngagementModule } from '../../utils/common';

const CommunicationFlowContainer = ({
  config,
  initialData,
  onSave,
  onCancel,
  onChange,
  ...otherProps
}) => {
  if (!hasSupportEngagementModule()) {
    return null;
  }

  return (
    <CommunicationFlow
      config={config}
      initialData={initialData}
      onSave={onSave}
      onCancel={onCancel}
      onChange={onChange}
      {...otherProps}
    />
  );
};

CommunicationFlowContainer.propTypes = {
  config: PropTypes.shape({
    consumer: PropTypes.oneOf(['campaigns', 'loyalty', 'adiona']).isRequired,
    channel: PropTypes.string, // optional if channel step is skipped
    mode: PropTypes.oneOf(['create', 'edit', 'preview']).isRequired,
    channelsToHide: PropTypes.arrayOf(PropTypes.string),
    channelsToDisable: PropTypes.arrayOf(PropTypes.string),
    features: PropTypes.shape({
      messageTypeData: PropTypes.shape({
        options: PropTypes.arrayOf(PropTypes.shape({
          value: PropTypes.string.isRequired,
          label: PropTypes.string.isRequired,
        })),
        defaultOption: PropTypes.shape({
          value: PropTypes.string.isRequired,
          label: PropTypes.string.isRequired,
        }),
        required: PropTypes.bool,
      }),
      communicationStrategyData: PropTypes.shape({
        options: PropTypes.arrayOf(PropTypes.shape({
          value: PropTypes.string.isRequired,
          label: PropTypes.string.isRequired,
        })),
        defaultOption: PropTypes.shape({
          value: PropTypes.string.isRequired,
          label: PropTypes.string.isRequired,
        }),
        required: PropTypes.bool,
        disabled: PropTypes.bool,
      }),
      contentTemplateData: PropTypes.shape({
        required: PropTypes.bool,
        channels: PropTypes.array,
        channelsToHide: PropTypes.arrayOf(PropTypes.string),
        channelsToDisable: PropTypes.arrayOf(PropTypes.string),
      }),
      incentivesData: PropTypes.shape({
        required: PropTypes.bool,
        types: PropTypes.arrayOf(PropTypes.shape({
          value: PropTypes.string.isRequired,
          label: PropTypes.string.isRequired,
          isActive: PropTypes.bool,
        })),
      }),
      deliverySettingsData: PropTypes.object,
      dynamicControlsData: PropTypes.shape({
        required: PropTypes.bool,
        controls: PropTypes.array,
      }),
    }),
    context: PropTypes.object, // ouId, campaignId, programId, etc.
  }).isRequired,
  initialData: PropTypes.object, // for edit/preview mode
  onSave: PropTypes.func.isRequired, // (data) => void - called when user saves
  onCancel: PropTypes.func.isRequired, // () => void - called when user cancels
  onChange: PropTypes.func, // (data) => void - optional, called on data changes
};

CommunicationFlowContainer.defaultProps = {
  initialData: null,
  onChange: null,
};

export default CommunicationFlowContainer;
