import type { RoomProfile } from '../../types/garden';
import { spaceTypeOptions } from '../../types/appTypes';
import { formatGardenValue } from './coreFormatters';
import { isIndoorSpaceType, isOutdoorSpaceType } from './spaceFormatters';

export const insideSpaceTypeOptions = spaceTypeOptions
  .filter(option => isIndoorSpaceType(option.value))
  .sort((a, b) => a.label.localeCompare(b.label));

export const outsideSpaceTypeOptions = spaceTypeOptions
  .filter(option => isOutdoorSpaceType(option.value))
  .sort((a, b) => a.label.localeCompare(b.label));

export const elevationOptions: { value: 'ground' | 'floor_1' | 'floor_2_3' | 'floor_4_plus' | 'unsure'; label: string }[] = [
  { value: 'ground', label: 'Ground floor' },
  { value: 'floor_1', label: 'Floor 1' },
  { value: 'floor_2_3', label: 'Floor 2–3' },
  { value: 'floor_4_plus', label: 'Floor 4+' },
  { value: 'unsure', label: 'Not sure' },
];

export const roofTypeOptions: { value: 'none' | 'solid' | 'glass' | 'permeable' | 'unsure'; label: string }[] = [
  { value: 'none', label: 'No roof / open sky' },
  { value: 'solid', label: 'Solid roof (awning, concrete)' },
  { value: 'glass', label: 'Glass / clear roof' },
  { value: 'permeable', label: 'Lattice / vine awning / shade cloth' },
  { value: 'unsure', label: 'Not sure' },
];

export const wallsOptions: { value: 'none' | 'one' | 'two' | 'three' | 'unsure'; label: string }[] = [
  { value: 'none', label: 'No walls (open sides)' },
  { value: 'one', label: '1 wall' },
  { value: 'two', label: '2 walls' },
  { value: 'three', label: '3 walls' },
  { value: 'unsure', label: 'Not sure' },
];

export const openFacesOptions: { value: 'north' | 'south' | 'east' | 'west'; label: string }[] = [
  { value: 'north', label: 'North' },
  { value: 'south', label: 'South' },
  { value: 'east', label: 'East' },
  { value: 'west', label: 'West' },
];

export const glassTintOptions: { value: 'clear' | 'tinted' | 'frosted' | 'unsure'; label: string }[] = [
  { value: 'clear', label: 'Clear' },
  { value: 'tinted', label: 'UV-tinted' },
  { value: 'frosted', label: 'Frosted' },
  { value: 'unsure', label: 'Not sure' },
];

export function formatElevation(value?: RoomProfile['elevation']): string {
  return elevationOptions.find(option => option.value === value)?.label || 'Not sure';
}

/** Short tag for a roof type on a space card. */
export function formatExposureShort(roof?: string): string {
  if (roof === 'solid') return 'Solid roof';
  if (roof === 'glass') return 'Glass roof';
  if (roof === 'permeable') return 'Lattice/vine cover';
  if (roof === 'none') return 'Open sky';
  if (roof === 'unsure') return 'Covered';
  return roof?.trim() ? formatGardenValue(roof) : 'Not sure';
}
