"""
Example calculator app demonstrating basic Gradio functionality.
"""

import gradio as gr
from apps.base_app import BaseApp


class CalculatorApp(BaseApp):
    """Simple calculator app for demonstration."""
    
    def add(self, a: float, b: float) -> float:
        """Add two numbers."""
        return a + b
    
    def subtract(self, a: float, b: float) -> float:
        """Subtract b from a."""
        return a - b
    
    def multiply(self, a: float, b: float) -> float:
        """Multiply two numbers."""
        return a * b
    
    def divide(self, a: float, b: float) -> float:
        """Divide a by b."""
        if b == 0:
            return "Error: Division by zero"
        return a / b
    
    def create_interface(self) -> gr.Blocks:
        """Create the calculator interface."""
        with gr.Blocks() as interface:
            gr.Markdown("## Calculator")
            gr.Markdown("Perform basic arithmetic operations")
            
            with gr.Row():
                num1 = gr.Number(label="First Number", value=0)
                num2 = gr.Number(label="Second Number", value=0)
            
            with gr.Row():
                add_btn = gr.Button("Add ➕")
                sub_btn = gr.Button("Subtract ➖")
                mul_btn = gr.Button("Multiply ✖️")
                div_btn = gr.Button("Divide ➗")
            
            result = gr.Number(label="Result")
            
            # Connect buttons to functions
            add_btn.click(fn=self.add, inputs=[num1, num2], outputs=result)
            sub_btn.click(fn=self.subtract, inputs=[num1, num2], outputs=result)
            mul_btn.click(fn=self.multiply, inputs=[num1, num2], outputs=result)
            div_btn.click(fn=self.divide, inputs=[num1, num2], outputs=result)
        
        return interface


# Export the app class
app = CalculatorApp
