'use client';

import type { ReactNode } from 'react';
import { X, Lock } from 'lucide-react';
import { t } from '@/lib/i18n';

export function BrowserLightbox(props: {
  open: boolean;
  onClose: () => void;
  title?: string;
  address?: string;
  position?: 'fixed' | 'absolute';
  children: ReactNode;
}) {
  if (!props.open) return null;

  const Container = props.position === 'absolute' ? 'div' : 'div';

  return (
    <div
      className={props.position === 'absolute' ? 'absolute inset-0 z-[1500]' : 'fixed inset-0 z-[1500]'}
      style={{ background: 'rgba(0,0,0,0.55)' }}
      onClick={props.onClose}
    >
      <Container
        className={props.position === 'absolute'
          ? 'absolute inset-0 m-0 rounded-none overflow-hidden flex flex-col'
          : 'absolute inset-4 md:inset-10 rounded-2xl overflow-hidden flex flex-col'}
        style={{ background: 'var(--bg-panel)', border: '1px solid var(--border-dark)', boxShadow: '0 20px 80px rgba(0,0,0,0.35)' }}
        onClick={(e: any) => e.stopPropagation()}
      >
        <div className="shrink-0 flex items-center justify-between gap-2 px-3 py-2" style={{ borderBottom: '1px solid var(--border-dark)' }}>
          <div className="flex items-center gap-2 min-w-0">
            <Lock size={14} style={{ color: 'var(--text-muted)' }} />
            <div className="min-w-0">
              <p className="text-[10px] font-bold truncate" style={{ color: 'var(--text-primary)' }}>{props.title || t('browser.title')}</p>
              <p className="text-[9px] truncate" style={{ color: 'var(--text-muted)' }}>{props.address || ''}</p>
            </div>
          </div>
          <button
            type="button"
            onClick={props.onClose}
            className="w-8 h-8 rounded-lg flex items-center justify-center hover:opacity-80"
            style={{ background: 'rgba(255,255,255,0.04)', border: '1px solid rgba(255,255,255,0.06)' }}
          >
            <X size={14} style={{ color: 'var(--text-secondary)' }} />
          </button>
        </div>

        <div className="flex-1 min-h-0 overflow-y-auto">
          {props.children}
        </div>
      </Container>
    </div>
  );
}
