//
//  theme.currentTheme.swift
//  Feels (iOS)
//
//  Created by Trey Tartt on 2/4/22.
//

import SwiftUI

struct ThemeConstants {
    static let iconSize: CGFloat = 50
}

enum Theme: Int, CaseIterable {
    case system
    case iFeel
    
    var title: String {
        switch self {
        case .system:
            return SystemTheme.title
        case .iFeel:
            return IFeelTheme.title
        }
    }
    
    var currentTheme: Themeable {
        switch self {
            
        case .system:
            return SystemTheme()
        case .iFeel:
            return IFeelTheme()
        }
    }
}

protocol Themeable {
    static var title: String { get }
    var secondaryBGColor: UIColor { get }
    var bg: AnyView { get }
    var preview: AnyView { get }
}

struct IFeelTheme: Themeable {
    static var title: String {
        return "iFeel Theme"
    }
    
    var secondaryBGColor: UIColor {
        return UIColor.systemBackground
    }
    
    var bg: AnyView {
        return AnyView(
            BGView().equatable()
        )
    }
    
    var preview: AnyView {
        return AnyView(
            ZStack {
                BGView().equatable()
                    .frame(width: ThemeConstants.iconSize, height: ThemeConstants.iconSize)
                    .clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous))
            }
        )
    }
}

struct SystemTheme: Themeable {
    static var title: String {
        return "System"
    }
    
    var secondaryBGColor: UIColor {
        return UIColor.secondarySystemBackground
    }
    
    var bg: AnyView {
        return AnyView(
            ZStack {
                Rectangle()
                    .fill(Color(UIColor.systemBackground))
            }
        )
    }
    
    var preview: AnyView {
        return AnyView(
            ZStack {
                Rectangle()
                    .fill(Color(UIColor.secondarySystemBackground))
                    .frame(width: ThemeConstants.iconSize, height: ThemeConstants.iconSize)
                    .clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous))
            }
        )
    }
}
