import type {
  HeaderDefinition,
  TitleDefinition,
  SubtitleDefinition,
  BottomActionButtonDefinition,
  NavigationDefinition,
  TypographyVariant,
  IconDefinition,
  DateInputDefinition,
  CouponDefinition,
  FormFieldDefinition,
  FormValidationMessages,
  ProgressbarDefinition,
} from "@/lib/funnel/types";

// ===== BUILDING BLOCK FUNCTIONS (КИРПИЧИКИ) =====
// These functions return default values for different screen components

/**
 * Creates default header configuration
 */
export function buildDefaultHeader(
  overrides?: Partial<HeaderDefinition>
): HeaderDefinition {
  return {
    show: true,
    showBackButton: true,
    showProgress: true,
    ...overrides,
  };
}

/**
 * Creates default title configuration
 */
export function buildDefaultTitle(
  overrides?: Partial<TitleDefinition>
): TitleDefinition {
  return {
    show: true,
    text: "Новый экран",
    font: "manrope",
    weight: "bold",
    align: "left",
    size: "2xl",
    color: "default",
    ...overrides,
  };
}

/**
 * Creates default subtitle configuration
 */
export function buildDefaultSubtitle(
  overrides?: Partial<SubtitleDefinition>
): SubtitleDefinition {
  return {
    show: true,
    text: "Добавьте детали справа",
    font: "manrope",
    weight: "medium",
    color: "default",
    align: "left",
    size: "lg",
    ...overrides,
  };
}

/**
 * Creates default bottom action button configuration
 */
export function buildDefaultBottomActionButton(
  overrides?: Partial<BottomActionButtonDefinition>
): BottomActionButtonDefinition {
  return {
    show: true,
    showGradientBlur: true,
    ...overrides,
  };
}

/**
 * Creates default navigation configuration
 */
export function buildDefaultNavigation(
  overrides?: Partial<NavigationDefinition>
): NavigationDefinition {
  return {
    defaultNextScreenId: undefined,
    rules: [],
    ...overrides,
  };
}

/**
 * Creates default description configuration
 */
export function buildDefaultDescription(
  overrides?: Partial<TypographyVariant>
): TypographyVariant {
  return {
    text: "Добавьте описание для экрана",
    font: "manrope",
    weight: "regular",
    align: "center",
    size: "md",
    color: "default",
    ...overrides,
  };
}

/**
 * Creates default icon configuration
 */
export function buildDefaultIcon(
  overrides?: Partial<IconDefinition>
): IconDefinition {
  return {
    type: "emoji",
    value: "ℹ️",
    size: "md",
    ...overrides,
  };
}

/**
 * Creates default date input configuration
 */
export function buildDefaultDateInput(
  overrides?: Partial<DateInputDefinition>
): DateInputDefinition {
  return {
    monthLabel: "Месяц",
    dayLabel: "День",
    yearLabel: "Год",
    monthPlaceholder: "ММ",
    dayPlaceholder: "ДД",
    yearPlaceholder: "ГГГГ",
    showSelectedDate: true,
    selectedDateFormat: "dd MMMM yyyy",
    selectedDateLabel: "Выбранная дата:",
    ...overrides,
  };
}

/**
 * Creates default coupon configuration
 */
export function buildDefaultCoupon(
  overrides?: Partial<CouponDefinition>
): CouponDefinition {
  return {
    title: {
      text: "Специальное предложение",
      font: "manrope",
      weight: "bold",
      align: "center",
      size: "lg",
      color: "default",
    },
    offer: {
      title: {
        text: "94% OFF",
        font: "manrope",
        weight: "extraBold",
        align: "center",
        size: "3xl",
        color: "primary",
      },
      description: {
        text: "Полный анализ личности",
        font: "manrope",
        weight: "medium",
        align: "center",
        size: "md",
        color: "default",
      },
    },
    promoCode: {
      text: "PROMO50",
      font: "geistMono",
      weight: "bold",
      align: "center",
      size: "lg",
      color: "accent",
    },
    footer: {
      text: "Нажмите чтобы скопировать промокод",
      font: "manrope",
      weight: "regular",
      align: "center",
      size: "sm",
      color: "muted",
    },
    ...overrides,
  };
}

/**
 * Creates default form fields configuration
 */
export function buildDefaultFormFields(): FormFieldDefinition[] {
  return [
    {
      id: "field1",
      label: "Имя",
      placeholder: "Введите ваше имя",
      type: "text",
      required: true,
    },
  ];
}

/**
 * Creates default form validation messages
 */
export function buildDefaultFormValidation(
  overrides?: Partial<FormValidationMessages>
): FormValidationMessages {
  return {
    required: "Это поле обязательно для заполнения",
    ...overrides,
  };
}

/**
 * Creates default progressbars configuration with sample data from Loaders.stories.tsx
 */
export function buildDefaultProgressbars(
  overrides?: Partial<ProgressbarDefinition>
): ProgressbarDefinition {
  return {
    items: [
      {
        processingTitle: "Анализ твоих ответов",
        processingSubtitle: "Processing...",
        completedTitle: "Анализ твоих ответов",
        completedSubtitle: "Complete",
      },
      {
        processingTitle: "Portrait of the Soulmate",
        processingSubtitle: "Processing...",
        completedTitle: "Portrait of the Soulmate",
        completedSubtitle: "Complete",
      },
      {
        processingTitle: "Portrait of the Soulmate",
        processingSubtitle: "Processing...",
        completedTitle: "Connection Insights",
        completedSubtitle: "Complete",
      },
    ],
    transitionDuration: 3000,
    ...overrides,
  };
}

/**
 * Creates default coupon copied message
 */
export function buildDefaultCopiedMessage(): string {
  return "Промокод скопирован!";
}

/**
 * Creates default image configuration
 */
export function buildDefaultImage(overrides?: { src?: string }): {
  src: string;
} {
  return {
    src: "/female-portrait.jpg",
    ...overrides,
  };
}

/**
 * Creates default email input configuration
 */
export function buildDefaultEmailInput(overrides?: {
  label?: string;
  placeholder?: string;
}): { label: string; placeholder: string } {
  return {
    label: "Email адрес",
    placeholder: "example@email.com",
    ...overrides,
  };
}

/**
 * Creates default special offer page text configuration
 */
export function buildDefaultSpecialOfferText(overrides?: {
  title?: TypographyVariant;
  subtitle?: TypographyVariant;
  description?: {
    trialPrice?: TypographyVariant;
    text?: TypographyVariant;
    oldTrialPrice?: TypographyVariant;
  };
}): {
  title: TypographyVariant;
  subtitle: TypographyVariant;
  description: {
    trialPrice?: TypographyVariant;
    text?: TypographyVariant;
    oldTrialPrice?: TypographyVariant;
  };
} {
  return {
    title: { text: "Special Offer" },
    subtitle: { text: "SAVE {{discountPercent}}% OFF!" },
    description: {
      trialPrice: { text: "{{trialPrice}}" },
      text: { text: " instead of " },
      oldTrialPrice: { text: "~~{{oldTrialPrice}}~~" },
    },
    ...overrides,
  };
}

/**
 * Creates default special offer page advantages configuration
 */
export function buildDefaultSpecialOfferAdvantages(overrides?: {
  items?: Array<{ icon: TypographyVariant; text: TypographyVariant }>;
}): { items: Array<{ icon: TypographyVariant; text: TypographyVariant }> } {
  return {
    items: [
      {
        icon: {
          text: "🔥",
        },
        text: {
          text: " **{{trialPeriodHyphen}}** trial instead of ~~{{oldTrialPeriod}}~~",
        },
      },
      {
        icon: {
          text: "💝",
        },
        text: {
          text: " Get **{{discountPercent}}%** off your Soulmate Sketch",
        },
      },
      {
        icon: {
          text: "💌",
        },
        text: { text: " Includes the **“Finding the One”** Guide" },
      },
    ],
    ...overrides,
  };
}
