# Ruby Calculator - Interactive calculator built with Ruby on Rails
# Author: RSK World (Molla Samser, Founder | Rima Khatun, Designer & Tester)
# Contact: help@rskworld.in | +91 93305 39277
# Website: https://rskworld.in
# Year: 2026
# Description: Build a fully functional calculator using Ruby on Rails with modern UI

class ThemeController < ApplicationController
  def update
    theme_name = params[:theme]
    
    if Theme.names.include?(theme_name)
      session[:theme] = theme_name
      respond_to do |format|
        format.html { redirect_back(fallback_location: root_path) }
        format.json { render json: { theme: theme_name, css: Theme.generate_css(theme_name) } }
      end
    else
      respond_to do |format|
        format.html { redirect_back(fallback_location: root_path), alert: "Invalid theme" }
        format.json { render json: { error: "Invalid theme" }, status: :unprocessable_entity }
      end
    end
  end
  
  def current
    theme_name = session[:theme] || 'default'
    respond_to do |format|
      format.json { render json: { theme: theme_name, css: Theme.generate_css(theme_name) } }
    end
  end
end
