import React from "react";
import WebGLVectorTileLayer from "ol/layer/WebGLVectorTile";

import { LegendStyleConfig } from "./StyleLegend";

export type ClassificationMethod = "pretty_breaks" | "custom_breaks";
export type ColorType = "single" | "gradient" | "rainbow" | "custom";

export interface StyleConfig {
  property: string;
  classificationMethod: ClassificationMethod;
  /** Number of rendered intervals. Boundaries always contain segments + 1 values. */
  segments: number;
  minSize: number;
  maxSize: number;
  minStrokeWidth: number;
  maxStrokeWidth: number;
  fixedStrokeWidth: number;
  colorType: ColorType;
  singlePaletteIndex: number;
  gradientPaletteIndex: number;
  rainbowPaletteIndex: number;
  showLabels: boolean;
  showId: boolean;
  opacity: number;
  adjustWidthByProperty: boolean;
  customBreaks?: number[];
  customColors?: string[];
}

export interface ResolvedLayerStyle {
  boundaries: number[];
  colors: string[];
  dimensions: number[];
  labels: string[];
  isConstant: boolean;
}

export interface StyleValidationResult {
  valid: boolean;
  errors: string[];
}

export interface LayerStyleState {
  layerId: string;
  layerName: string;
  styleConfig: StyleConfig;
  legendConfig: LegendStyleConfig;
  isActive: boolean;
}

export type DefaultLayerStyleId = "junctions" | "pipes";

export interface StyleEditorStateProps {
  layerStyleStates: LayerStyleState[];
  setLayerStyleStates: React.Dispatch<React.SetStateAction<LayerStyleState[]>>;
  workspace: string;
}

export interface AvailableProperty {
  name: string;
  value: string;
}

export interface StyleEditorFormProps {
  renderLayers: WebGLVectorTileLayer[];
  selectedRenderLayer?: WebGLVectorTileLayer;
  styleConfig: StyleConfig;
  setStyleConfig: React.Dispatch<React.SetStateAction<StyleConfig>>;
  availableProperties: AvailableProperty[];
  onLayerChange: (layerId: string) => void;
  onPropertyChange: (property: string) => void;
  onClassificationMethodChange: (method: ClassificationMethod) => void;
  onSegmentsChange: (segments: number) => void;
  onCustomBreakChange: (index: number, value: string) => void;
  onColorTypeChange: (colorType: ColorType) => void;
  onApply: () => void;
  onReset: () => void;
  validationErrors: string[];
  isDirty: boolean;
  isApplying: boolean;
}

export interface StyleEditorPanelProps extends StyleEditorFormProps {
  isReady: boolean;
}
