import Foundation
import Metal

public class RepeatedSlideRenderable: ConfiguredQuadRenderable<RepeatedSlideRenderable.Config> {
    public var map: MTLTexture?

    public struct Config: QuadRenderConfiguration {
        let display_size: ADVector2
        let global_scale: ADFloat
        let circle_rotation: ADFloat
        let mapped_color: ADVector3
        let ratio_size: ADFloat
        let u_offset: ADFloat
        let v_offset: ADFloat

        public init(
            displaySize: ADVector2 = .ones,
            globalScale: ADFloat = 1.0,
            rotation: ADFloat = 0.0,
            mappedColor: ADVector3 = .ones,
            ratioSize: ADFloat = 1.0,
            uOffset: ADFloat = 0.0,
            vOffset: ADFloat = 0.0
        ) {
            display_size = displaySize
            global_scale = globalScale
            circle_rotation = rotation
            mapped_color = mappedColor
            ratio_size = ratioSize
            u_offset = uOffset
            v_offset = vOffset
        }

        public static var defaultConfiguration: Config {
            return Config()
        }
    }

    override public var configureAction: ConfigureAction {
        guard let mapTexture = map else { return super.configureAction }

        return { encoder in
            super.configureAction(encoder)
            encoder?.setFragmentTexture(mapTexture, index: 0)
        }
    }

    override var fragmentShaderName: String {
        return "repeated_slide"
    }
}
