const savedTheme: string | null = localStorage.getItem("theme");

export type Controls = {
    azimuthRotateSpeed: number;
    polarRotateSpeed: number;
    truckSpeed: number;
    minDistance: number;
    maxDistance: number;
    maxPolarAngle: number;
    leftMouse: number;
    forwardSpeed: number;
    backwardSpeed: number;
    leftSpeed: number;
    rightSpeed: number;
};

export type ThirdPersonControls = {
    azimuthRotateSpeed: number;
    polarRotateSpeed: number;
    truckSpeed: number;
    maxDistance: number;
    maxPolarAngle: number;
    minZoom: number;
    maxZoom: number;
    targetOffset: number;
    cameraHeight: number;
    leftMouse: number;
    rightMouse: number;
    wheelMouse: number;
    middleMouse: number;
};

export type ControlsTransition = {
    leftMouse: number;
    rightMouse: number;
    wheelMouse: number;
    middleMouse: number;
};

export type TwoDimension = {
    defaultPosition: [x: number, y: number, z: number];
    defaultTarget: [x: number, y: number, z: number];
    defaultAzimuth: number;
    minDistance: number;
    leftMouse: number;
    rightMouse: number;
};

export type ThreeDimension = {
    defaultPosition: [x: number, y: number, z: number];
    defaultTarget: [x: number, y: number, z: number];
    defaultRotation: [x: number, y: number, z: number];
    defaultAzimuth: number;
    boundaryBottom: [x: number, y: number, z: number];
    boundaryTop: [x: number, y: number, z: number];
    minDistance: number;
    leftMouse: number;
    rightMouse: number;
};

export type GridConfig = {
    size: number;
    divisions: number;
    primaryColor: string;
    secondaryColor: string;
    position2D: [x: number, y: number, z: number];
    position3D: [x: number, y: number, z: number];
};

export type PlaneConfig = {
    position2D: [x: number, y: number, z: number];
    position3D: [x: number, y: number, z: number];
    rotation: number;
    width: number;
    height: number;
    color: string;
};

export type ShadowConfig = {
    shadowOffset: number;
    shadowmapSizewidth: number;
    shadowmapSizeheight: number;
    shadowcamerafar: number;
    shadowcameranear: number;
    shadowcameratop: number;
    shadowcamerabottom: number;
    shadowcameraleft: number;
    shadowcameraright: number;
    shadowbias: number;
    shadownormalBias: number;
    shadowMaterialPosition: [x: number, y: number, z: number];
    shadowMaterialRotation: [x: number, y: number, z: number];
    shadowMaterialOpacity: number;
};

export type SkyConfig = {
    defaultTurbidity: number;
    maxTurbidity: number;
    minTurbidity: number;
    defaultRayleigh: number;
    mieCoefficient: number;
    mieDirectionalG: number;
    skyDistance: number;
};

export type AssetConfig = {
    defaultScaleBeforeGsap: [number, number, number];
    defaultScaleAfterGsap: [number, number, number];
};

export type PointConfig = {
    defaultInnerColor: string;
    defaultOuterColor: string;
    deleteColor: string;
    boxScale: [number, number, number];
    wallOuterColor: string;
    floorOuterColor: string;
    aisleOuterColor: string;
    zoneOuterColor: string;
    snappingThreshold: number;
    helperColor: string;
};

export type LineConfig = {
    tubularSegments: number;
    radius: number;
    radialSegments: number;
    wallName: string;
    floorName: string;
    aisleName: string;
    zoneName: string;
    referenceName: string;
    lineIntersectionPoints: number;
    defaultColor: string;
    wallColor: string;
    floorColor: string;
    aisleColor: string;
    zoneColor: string;
    deleteColor: string;
    helperColor: string;
};

export type WallConfig = {
    defaultColor: string;
    height: number;
    width: number;
};

export type FloorConfig = {
    defaultColor: string;
    height: number;
    textureScale: number;
};

export type RoofConfig = {
    defaultColor: string;
    height: number;
};

export type AisleConfig = {
    width: number;
    height: number;
    defaultColor: string;
};

export type ZoneConfig = {
    defaultColor: string;
    height: number;
    color: string;
};

export type ColumnConfig = {
    defaultColor: string;
};

export type OutlineConfig = {
    assetSelectColor: number;
    assetDeleteColor: number;
};

export type DistanceConfig = {
    minDistance: number;
    maxDistance: number;
};

export type undoRedoCount = {
    undoRedoCount: number;
};

export const firstPersonControls: Controls = {
    azimuthRotateSpeed: 0.3, // Speed of rotation around the azimuth axis
    polarRotateSpeed: 0.3, // Speed of rotation around the polar axis
    truckSpeed: 10, // Speed of truck movement
    minDistance: 0, // Minimum distance from the target
    maxDistance: 0, // Maximum distance from the target
    maxPolarAngle: Math.PI, // Maximum polar angle
    leftMouse: 1, // Mouse button for rotation (ROTATE)
    forwardSpeed: 0.1, // Speed of forward movement
    backwardSpeed: -0.1, // Speed of backward movement
    leftSpeed: -0.1, // Speed of left movement
    rightSpeed: 0.1, // Speed of right movement
};

export const thirdPersonControls: ThirdPersonControls = {
    azimuthRotateSpeed: 1, // Speed of rotation around the azimuth axis
    polarRotateSpeed: 1, // Speed of rotation around the polar axis
    truckSpeed: 2, // Speed of truck movement
    maxDistance: 100, // Maximum distance from the target
    maxPolarAngle: Math.PI / 2, // Maximum polar angle
    minZoom: 6, // Minimum zoom level
    maxZoom: 100, // Maximum zoom level
    targetOffset: 20, // Offset of the target from the camera
    cameraHeight: 30, // Height of the camera
    leftMouse: 2, // Mouse button for panning
    rightMouse: 1, // Mouse button for rotation
    wheelMouse: 8, // Mouse button for zooming
    middleMouse: 8, // Mouse button for zooming
};

export const controlsTransition: ControlsTransition = {
    leftMouse: 0, // Mouse button for no action
    rightMouse: 0, // Mouse button for no action
    wheelMouse: 0, // Mouse button for no action
    middleMouse: 0, // Mouse button for no action
};

export const twoDimension: TwoDimension = {
    defaultPosition: [0, 100, 0], // Default position of the camera
    defaultTarget: [0, 0, 0], // Default target of the camera
    defaultAzimuth: 0, // Default azimuth of the camera
    minDistance: 25, // Minimum distance from the target
    leftMouse: 2, // Mouse button for panning
    rightMouse: 0, // Mouse button for no action
};

export const camPositionUpdateInterval: number = 200; // Interval for updating the camera position

export const gridConfig: GridConfig = {
    size: 150, // Size of the grid
    divisions: 75, // Number of divisions in the grid
    primaryColor: savedTheme === "dark" ? "#131313" : "#d5d5d5", // Primary color of the grid
    secondaryColor: savedTheme === "dark" ? "#434343" : "#e3e3e3", // Secondary color of the grid

    position2D: [0, 0.1, 0], // Position of the grid in 2D view
    position3D: [0, -0.5, 0], // Position of the grid in 3D view
};

export const threeDimension: ThreeDimension = {
    defaultPosition: [0, 40, 30], // Default position of the camera
    defaultTarget: [0, 0, 0], // Default target of the camera
    defaultRotation: [0, 0, 0], // Default rotation of the camera
    defaultAzimuth: 0, // Default azimuth of the camera
    boundaryBottom: [-gridConfig.size / 2, 0, -gridConfig.size / 2], // Bottom boundary of the camera movement
    boundaryTop: [gridConfig.size / 2, 100, gridConfig.size / 2], // Top boundary of the camera movement
    minDistance: 1, // Minimum distance from the target
    leftMouse: 2, // Mouse button for panning
    rightMouse: 1, // Mouse button for rotation
};

export const planeConfig: PlaneConfig = {
    position2D: [0, -0.5, 0], // Position of the plane
    position3D: [0, -0.65, 0], // Position of the plane
    rotation: -Math.PI / 2, // Rotation of the plane

    width: 150, // Width of the plane
    height: 150, // Height of the plane
    color: savedTheme === "dark" ? "#323232" : "#f3f3f3", // Color of the plane
};

export const shadowConfig: ShadowConfig = {
    shadowOffset: 50, // Offset of the shadow
    // shadowmapSizewidth: 1024, // Width of the shadow map
    // shadowmapSizeheight: 1024, // Height of the shadow map
    shadowmapSizewidth: 2048, // Width of the shadow map
    shadowmapSizeheight: 2048, // Height of the shadow map
    // shadowmapSizewidth: 8192, // Width of the shadow map
    // shadowmapSizeheight: 8192, // Height of the shadow map
    shadowcamerafar: 70, // Far plane of the shadow camera
    shadowcameranear: 0.1, // Near plane of the shadow camera
    shadowcameratop: 30, // Top plane of the shadow camera
    shadowcamerabottom: -30, // Bottom plane of the shadow camera
    shadowcameraleft: -30, // Left plane of the shadow camera
    shadowcameraright: 30, // Right plane of the shadow camera
    shadowbias: -0.001, // Bias of the shadow
    shadownormalBias: 0.02, // Normal bias of the shadow
    shadowMaterialPosition: [0, 0.01, 0], // Position of the shadow material
    shadowMaterialRotation: [-Math.PI / 2, 0, 0], // Rotation of the shadow material
    shadowMaterialOpacity: 0.1, // Opacity of the shadow material
};

export const skyConfig: SkyConfig = {
    defaultTurbidity: 10.0, // Default turbidity of the sky
    maxTurbidity: 20.0, // Maximum turbidity of the sky
    minTurbidity: 0.0, // Minimum turbidity of the sky
    defaultRayleigh: 1.9, // Default Rayleigh scattering coefficient
    mieCoefficient: 0.1, // Mie scattering coefficient
    mieDirectionalG: 1.0, // Mie directional G
    skyDistance: 2000, // Distance of the sky
};

export const assetConfig: AssetConfig = {
    defaultScaleBeforeGsap: [0.1, 0.1, 0.1], // Default scale of the assets
    defaultScaleAfterGsap: [1, 1, 1], // Default scale of the assets
};

export const pointConfig: PointConfig = {
    defaultInnerColor: "#ffffff", // Default inner color of the points
    defaultOuterColor: "#ffffff", // Default outer color of the points
    deleteColor: "#ff0000", // Color of the points when deleting
    boxScale: [0.5, 0.5, 0.5], // Scale of the points
    wallOuterColor: "#C7C7C7", // Outer color of the wall points
    floorOuterColor: "#808080", // Outer color of the floor points
    aisleOuterColor: "#FBBC05", // Outer color of the aisle points
    zoneOuterColor: "#007BFF", // Outer color of the zone points
    snappingThreshold: 1, // Threshold for snapping
    helperColor: "#C164FF", // Color of the helper lines
};

export const lineConfig: LineConfig = {
    tubularSegments: 64, // Number of tubular segments
    radius: 0.15, // Radius of the lines
    radialSegments: 8, // Number of radial segments
    wallName: "WallLine", // Name of the wall lines
    floorName: "FloorLine", // Name of the floor lines
    aisleName: "AisleLine", // Name of the aisle lines
    zoneName: "ZoneLine", // Name of the zone lines
    referenceName: "ReferenceLine", // Name of the reference lines
    lineIntersectionPoints: 300, // Number of intersection points
    defaultColor: "#000000", // Default color of the lines
    wallColor: "#C7C7C7", // Color of the wall lines
    floorColor: "#808080", // Color of the floor lines
    aisleColor: "#FBBC05", // Color of the aisle lines
    zoneColor: "#007BFF", // Color of the zone lines
    deleteColor: "#ff0000", // Color of the line when deleting
    helperColor: "#C164FF", // Color of the helper lines
};

export const wallConfig: WallConfig = {
    defaultColor: "#f2f2f2", // Default color of the walls
    height: 7.5, // Height of the walls
    width: 0.05, // Width of the walls
};

export const floorConfig: FloorConfig = {
    defaultColor: "grey", // Default color of the floors
    height: 0.1, // Height of the floors
    textureScale: 1, // Scale of the floor texture
};

export const roofConfig: RoofConfig = {
    defaultColor: "grey", // Default color of the roofs
    height: 0.1, // Height of the roofs
};

export const aisleConfig: AisleConfig = {
    width: 0.1, // Width of the aisles
    height: 0.01, // Height of the aisles
    defaultColor: '#E2AC09', // Default color of the aisles
};

export const zoneConfig: ZoneConfig = {
    defaultColor: "black", // Default color of the zones
    height: 3,
    color: "#8656DF", // Color of the zones
};

export const columnConfig: ColumnConfig = {
    defaultColor: "White", // Default color of the columns
};

export const outlineConfig: OutlineConfig = {
    assetSelectColor: 0x0054fe, // Color of the selected assets
    assetDeleteColor: 0xff0000, // Color of the deleted assets
};

export const distanceConfig: DistanceConfig = {
    minDistance: 20,
    maxDistance: 75,
};

export const undoRedoConfig: undoRedoCount = {
    undoRedoCount: 50,
}