'use client';

import { ViewNameModal } from './ViewModals';

/**
 * Name (and optionally personal / shared) of a view, e.g. the bottom bar's "Clone to new view":
 * the design's centered view-name dialog (view-settings.js `vsNameModal`). The name is checked on
 * submit only. `onSubmit` returns false to keep the dialog open (e.g. name taken).
 */
export function ViewNameDrawer({
  open,
  title,
  submitLabel,
  initialName,
  showShare = false,
  initialShared = false,
  onClose,
  onSubmit,
}: {
  id: string;
  open: boolean;
  title: string;
  submitLabel: string;
  initialName: string;
  showShare?: boolean;
  initialShared?: boolean;
  onClose: () => void;
  onSubmit: (values: { name: string; isShared: boolean }) => Promise<boolean>;
}) {
  return (
    <ViewNameModal
      open={open}
      title={title}
      submitLabel={submitLabel}
      initialName={initialName}
      share={showShare ? (initialShared ? 'everyone' : 'private') : undefined}
      onClose={onClose}
      onSubmit={({ name, access }) => onSubmit({ name, isShared: access === 'everyone' })}
    />
  );
}
