import { render, screen } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';

vi.mock('@/lib/khu-cong-nghiep-api', () => ({
  PARK_STATUS_LABELS: { OPERATIONAL: 'Hoạt động', PLANNING: 'Quy hoạch', UNDER_CONSTRUCTION: 'Đang xây dựng', FULL: 'Đã lấp đầy' },
  PARK_STATUS_COLORS: { OPERATIONAL: 'bg-green-100 text-green-800', PLANNING: 'bg-blue-100 text-blue-800', UNDER_CONSTRUCTION: 'bg-amber-100 text-amber-800', FULL: 'bg-red-100 text-red-800' },
  REGION_LABELS: { NORTH: 'Miền Bắc', CENTRAL: 'Miền Trung', SOUTH: 'Miền Nam' },
}));

import { KhuCongNghiepDetailClient } from '../khu-cong-nghiep-detail-client';

const park = {
  id: 'ip1',
  name: 'KCN Tân Bình',
  nameEn: 'Tan Binh IP',
  slug: 'kcn-tan-binh',
  developer: 'Becamex',
  operator: 'Becamex IDC',
  status: 'OPERATIONAL' as const,
  latitude: 10.8,
  longitude: 106.6,
  address: '123 Đại lộ',
  district: 'Tân Bình',
  province: 'Bình Dương',
  region: 'SOUTH' as const,
  totalAreaHa: 500,
  leasableAreaHa: 400,
  occupancyRate: 85,
  remainingAreaHa: 60,
  tenantCount: 120,
  listingCount: 15,
  establishedYear: 2005,
  isVerified: true,
  landRentUsdM2Year: '55.0000',
  rbfRentUsdM2Month: '4.5000',
  rbwRentUsdM2Month: '3.2000',
  managementFeeUsd: '0.8000',
  targetIndustries: ['Điện tử', 'Cơ khí'],
  certifications: ['ISO 14001'],
  description: 'KCN hàng đầu',
  infrastructure: { power: '110kV', water: '50,000 m³/ngày' },
  connectivity: { airport: { name: 'Tân Sơn Nhất', distanceKm: 25 } },
  incentives: { cit: '2 năm miễn thuế' },
  existingTenants: [{ name: 'Samsung', country: 'Hàn Quốc', industry: 'Điện tử' }],
  documents: [{ name: 'Brochure.pdf', url: '/docs/b.pdf' }],
} as never;

describe('KhuCongNghiepDetailClient', () => {
  it('renders park name', () => {
    render(<KhuCongNghiepDetailClient park={park} />);
    expect(screen.getByText('KCN Tân Bình')).toBeInTheDocument();
  });

  it('renders English name', () => {
    render(<KhuCongNghiepDetailClient park={park} />);
    expect(screen.getByText('Tan Binh IP')).toBeInTheDocument();
  });

  it('renders status badge', () => {
    render(<KhuCongNghiepDetailClient park={park} />);
    expect(screen.getByText('Hoạt động')).toBeInTheDocument();
  });

  it('renders verified badge', () => {
    render(<KhuCongNghiepDetailClient park={park} />);
    expect(screen.getByText('Đã xác minh')).toBeInTheDocument();
  });

  it('renders quick stats', () => {
    render(<KhuCongNghiepDetailClient park={park} />);
    expect(screen.getByText('500 ha')).toBeInTheDocument();
    expect(screen.getByText('85%')).toBeInTheDocument();
    expect(screen.getByText('120')).toBeInTheDocument();
  });

  it('renders target industries', () => {
    render(<KhuCongNghiepDetailClient park={park} />);
    expect(screen.getByText('Điện tử')).toBeInTheDocument();
    expect(screen.getByText('Cơ khí')).toBeInTheDocument();
  });

  it('renders rent info', () => {
    render(<KhuCongNghiepDetailClient park={park} />);
    expect(screen.getByText('$55.0000/m²/năm')).toBeInTheDocument();
  });

  it('renders tabs', () => {
    render(<KhuCongNghiepDetailClient park={park} />);
    expect(screen.getByRole('tab', { name: 'Hạ tầng' })).toBeInTheDocument();
    expect(screen.getByRole('tab', { name: 'Doanh nghiệp' })).toBeInTheDocument();
  });
});
