import type { ReactNode } from "react";

type DrawerFooterProps = {
  /**
   * The actions, in reading order: secondary first, the primary last so it
   * sits at the right edge where the eye ends and the thumb rests.
   */
  children: ReactNode;
  /**
   * Optional content on the left that takes the remaining width — e.g. a
   * one-line summary of what will change, or a save progress line.
   */
  leading?: ReactNode;
};

/**
 * The bottom action bar of a drawer view whose primary action belongs at the
 * end of a form (Save, Assign, Apply): a hairline on top, the drawer surface
 * behind it, and the bottom safe-area inset added to its padding.
 *
 * @remarks
 * Render it as the last child of a `DrawerView`. It is positioned
 * `absolute` at the view's bottom edge (the view is the positioning parent),
 * so it stays put while the content scrolls underneath. The scrolling content
 * needs its own bottom padding to scroll clear of the bar (about `pb-28` for
 * one row of `size="rounded"` buttons). For the floating confirm pill of a
 * picker use `FloatingConfirm` instead.
 */
export function DrawerFooter({ children, leading }: DrawerFooterProps) {
  return (
    <div className="absolute inset-x-0 bottom-0 z-20 flex items-center gap-3 border-t border-surface-stroke bg-surface-drawer px-6 pt-3 pb-[calc(0.75rem+env(safe-area-inset-bottom))]">
      {leading != null && <div className="min-w-0 flex-1">{leading}</div>}
      <div className={`flex shrink-0 items-center gap-3 ${leading != null ? "" : "ml-auto"}`}>
        {children}
      </div>
    </div>
  );
}
