'use client';

/**
 * Lazy-loaded CronScheduler Component
 *
 * CronScheduler (~15KB) is loaded only when component is rendered.
 * Use this for automatic code-splitting with Suspense fallback.
 *
 * @example
 * import { LazyCronScheduler } from '@djangocfg/ui-tools';
 *
 * <LazyCronScheduler
 *   value={cron}
 *   onChange={setCron}
 * />
 */

import { createLazyComponent, LoadingFallback } from '../../components';
import type { CronSchedulerProps } from './types';

// Re-export types
export type {
  CronSchedulerProps,
  ScheduleType,
  WeekDay,
  MonthDay,
  CronSchedulerState,
} from './types';

/**
 * LazyCronScheduler - Lazy-loaded cron expression builder
 *
 * Automatically shows loading state while CronScheduler loads (~15KB).
 * Uses createLazyComponent factory for optimal code-splitting.
 *
 * @example
 * // Basic usage
 * <LazyCronScheduler
 *   value="0 9 * * *"
 *   onChange={handleChange}
 * />
 *
 * @example
 * // With all options
 * <LazyCronScheduler
 *   value={cron}
 *   onChange={setCron}
 *   defaultType="weekly"
 *   showPreview
 *   showCronExpression
 *   allowCopy
 *   timeFormat="24h"
 * />
 */
export const LazyCronScheduler = createLazyComponent<CronSchedulerProps>(
  () => import('./CronScheduler.client'),
  {
    displayName: 'LazyCronScheduler',
    fallback: (
      <LoadingFallback
        minHeight={120}
        showText={false}
        className="rounded-lg"
      />
    ),
  }
);
