//
//  RouletteViewDialog.swift
//  SodaLive
//
//  Created by klaus on 2023/12/07.
//

import SwiftUI

struct RouletteViewDialog: View {
    @Binding var isShowing: Bool
    
    let options: [String]
    let selectedOption: String
    let complete: () -> Void
    
    var body: some View {
        let model = FortuneWheelModel(
            titles: options,
            size: 320,
            onSpinEnd: onSpinEnd,
            getWheelItemIndex: getWheelItemIndex
        )
        ZStack {
            FortuneWheel(model: model)
        }
    }
    
    private func onSpinEnd(index: Int) {
        complete()
        isShowing = false
    }
    
    private func getWheelItemIndex() -> Int {
        return options.firstIndex(of: selectedOption) ?? 0
    }
}
