"use client";

import ContentLockup from "../../type/ContentLockup";
import ModalFooter from "../ModalFooter";
import ModalHeader from "../ModalHeader";
import { CreateModalFrameView } from "./CreateModalFrame.view";
import type { CreateViewProps } from "./Create.types";

export function CreateView({
  isOpen,
  onClose,
  title,
  description,
  headerContent,
  children,
  footerContent,
  footerClassName,
  showBackButton,
  showNextButton,
  showRemoveButton,
  onBack,
  onNext,
  onRemove,
  backButtonText,
  nextButtonText,
  removeButtonText,
  nextButtonDisabled,
  currentStep,
  totalSteps,
  className,
  ariaLabel,
  ariaLabelledBy,
  createRef,
  overlayRef,
  backdropVariant,
  stepper,
  kebabTriggerAriaLabel,
  kebabMenuAriaLabel,
  kebabMenuItems,
  belowCard,
}: CreateViewProps) {
  return (
    <CreateModalFrameView
      isOpen={isOpen}
      onOverlayClick={onClose}
      backdropVariant={backdropVariant}
      className={className}
      ariaLabel={ariaLabel}
      ariaLabelledBy={ariaLabelledBy}
      overlayRef={overlayRef}
      dialogRef={createRef}
      belowCard={belowCard}
    >
      <ModalHeader
        onClose={onClose}
        moreOptionsAriaLabel={kebabTriggerAriaLabel}
        menuAriaLabel={kebabMenuAriaLabel}
        menuItems={kebabMenuItems}
        showMoreOptionsButton={(kebabMenuItems?.length ?? 0) > 0}
      />

      {headerContent !== undefined ? (
        <div className="shrink-0">{headerContent}</div>
      ) : title || description ? (
        <div className="bg-[var(--color-surface-default-primary)] px-[24px] shrink-0">
          <ContentLockup
            title={title}
            description={description}
            variant="modal"
            alignment="left"
          />
        </div>
      ) : null}

      <div className="scrollbar-design flex min-h-0 flex-1 flex-col gap-[var(--spacing-scale-024)] overflow-x-clip overflow-y-auto px-[24px] pb-6 pt-0">
        {children}
      </div>

      <ModalFooter
        showBackButton={showBackButton}
        showNextButton={showNextButton}
        showRemoveButton={showRemoveButton}
        onBack={onBack}
        onNext={onNext}
        onRemove={onRemove}
        backButtonText={backButtonText}
        nextButtonText={nextButtonText}
        removeButtonText={removeButtonText}
        nextButtonDisabled={nextButtonDisabled}
        currentStep={currentStep}
        totalSteps={totalSteps}
        stepper={stepper}
        footerContent={footerContent}
        className={footerClassName}
      />
    </CreateModalFrameView>
  );
}
