'''
Created on 16-Oct-2023

@author: bthakur
'''
import inspect
import traceback

from xv.km.ui import SvgHelper         

from ..helper import BaseHelper
from xv.km.managers import BaseManager
from xv.km.kelements import KProblemTemplate

import numpy as np
import sympy as sp

# _basic_geometry_manager
# BasicGeometryManager
        
class BasicGeometryManager(BaseManager):
    '''
    Circle and its geometry
    Example:
        ke = BasicGeometryManager()
        ke
        
        ke.printProblemTypes()
        
        ke.getRandomProblem()
        ke.getRandomProblem(problem_type = 0)
        ke.getRandomProblem(problem_type = 1)
        ...
        
        ke.printProblem()
        ke.printAnswer()
        ke.printSolution()
        
        ke.printLength(2, 5, 3, -1)
        ke.printMovementLengths()        
        
        
    '''    
    def __new__(cls, *args, **kwargs):
        instance = super(BasicGeometryManager, cls).__new__(cls, *args, **kwargs)
        for base_class in BasicGeometryManager.__bases__:
            base_class.__init__(instance, *args, **kwargs)
        return instance
    
    def __init__(self, *args, **kwargs):
        self.base_helper = BaseHelper(**kwargs)
        pass

    def _init_problem_types(self, *args, **kwargs):
        self._append_problem_types([
            '_problem_represent_a_point_in_various_systems',
            '_problem_represent_unit_point_in_various_systems',
            
         ])
        pass

    def _problem_represent_a_point_in_various_systems(self, *args, **kwargs):
        
        bg_helper = self.base_helper.get_geometry_helper().get_basic_geometry_helper()
        
        
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        prob_s = f"""
        Express a point in various systems. 
        """
        problemTemplate.add_problem(prob_s.replace("\n", " ").strip())
                
        #svgHelper = SvgHelper()
        #svg_str, plot_code = svgHelper.get_svg_data(custom_code, strip_lines = True)

        soln_stmts = []
        
        soln_stmt = r"""
        <h3>2-Dimensional Space:</h3>
        $\displaystyle 
        \begin{array}{ll}
        (x, y) & \text { 2D  Cartesian } \\

        (r, \theta) & \text { 2D polar } \\

        (r, \alpha_1, \alpha_2) & \text { 2D polar where } \alpha_2 = \frac{\pi}{2} - \alpha_1 \\

        r \left( \cos \theta, \sin \theta \right) & \text { 2D polar } \\

        r \left( \cos \alpha_1, \cos \alpha_2 \right) 
        & \text { 2D polar where } \alpha_2 = \frac{\pi}{2} - \alpha_1 \\\\

        x \hat{i}+y \hat{j} & \text { 2D vector } \\

        r \left( \cos \theta  \hat{i}
                +\sin \theta  \hat{j} 
          \right) & \text { 2D vector } \\

        r \left( \cos \alpha_1  \hat{i}
                +\cos \alpha_2  \hat{j} 
          \right) & \text { 2D vector } \\\\

        x+i y & \text { imaginary space } \\

        r \left( \cos \theta+i \sin \theta \right) & \text { imaginary polar } \\

        r e^{i \theta} & \text { Euler number expression }
        \end{array}
        $
        """
        soln_stmts.append(soln_stmt.strip())

        soln_stmt = r"""
        <h3>3-Dimensional Space:</h3>
        $
        \begin{array}{ll}
        (x, y, z) & \text { 3D  Cartesian } \\

        (r, \alpha_1, \alpha_2, \alpha_3) & \text { 3D polar } \\

        r \left( \cos \alpha_1, \cos \alpha_2, \cos \alpha_3 \right) 
        & \text { 3D polar } \\\\

        x \hat{i}+y \hat{j} +z \hat{k} & \text { 3D vector } \\

        r \left( \cos \alpha_1  \hat{i}
                +\cos \alpha_2  \hat{j} 
                +\cos \alpha_3  \hat{k} 
          \right) & \text { 3D vector } \\


        (r, \theta , z) & \text { cylindrical coordinates } \\
        
        r \cos \theta, r \sin \theta, z & \text { cylindrical coordinates } \\

        (\rho, \theta , \phi) & \text { spherical coordinates } 
        \quad \rho \geq 0 \text { and } 0 \leq \phi \leq \pi \text { by convention }
        \\
        
        & \rho=\sqrt{r^2+z^2}, \quad \theta=\theta, \quad \phi=\arccos \frac{z}{\rho} \\

        



        \end{array}
        $
        """
        soln_stmts.append(soln_stmt.strip())

        soln_stmt = r"""
        """
        soln_stmts.append(soln_stmt.strip())

        soln_stmt = r"""
        """
        soln_stmts.append(soln_stmt.strip())

        soln_stmt = r"""
        """
        soln_stmts.append(soln_stmt.strip())

        soln_stmt = r"""
        """
        soln_stmts.append(soln_stmt.strip())

        soln_s = "<br/><br/>".join(soln_stmts)
        problemTemplate.add_solution(soln_s.strip())
        #problemTemplate.add_solution(svg_str, 'text/svg')

        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip())
        
        return problemTemplate
        pass
    


    def _problem_represent_unit_point_in_various_systems(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        prob_s = f"""
        Express a point in various systems. 
        """
        problemTemplate.add_problem(prob_s.replace("\n", " ").strip())
                
        #svgHelper = SvgHelper()
        #svg_str, plot_code = svgHelper.get_svg_data(custom_code, strip_lines = True)

        soln_stmts = []
        
        soln_stmt = r"""
        <h3>2-Dimensional Space:</h3>
        $\displaystyle 
        \begin{array}{ll}
        (1, 1) & \text { 2D  Cartesian } \\

        (1, \theta) & \text { 2D polar } \\

        (1, \alpha_1, \alpha_2) & \text { 2D polar where } \alpha_2 = \frac{\pi}{2} - \alpha_1 \\

        1 \left( \cos \theta, \sin \theta \right) & \text { 2D polar } \\

        1 \left( \cos \alpha_1, \cos \alpha_2 \right) 
        & \text { 2D polar where } \alpha_2 = \frac{\pi}{2} - \alpha_1 \\\\

        1 \hat{i}+1 \hat{j} & \text { 2D vector } \\

        1 \left( \cos \theta  \hat{i}
                +\sin \theta  \hat{j} 
          \right) & \text { 2D vector } \\

        1 \left( \cos \alpha_1  \hat{i}
                +\cos \alpha_2  \hat{j} 
          \right) & \text { 2D vector } \\\\

        1+1 y & \text { imaginary space } \\

        1 \left( \cos \theta+i \sin \theta \right) & \text { imaginary polar } \\

        1 e^{i \theta} & \text { Euler number expression }
        \end{array}
        $
        """
        soln_stmts.append(soln_stmt.strip())

        soln_stmt = r"""
        <h3>3-Dimensional Space:</h3>
        $
        \begin{array}{ll}
        (1, 1, 1) & \text { 3D  Cartesian } \\

        (1, \alpha_1, \alpha_2, \alpha_3) & \text { 3D polar } \\

        1 \left( \cos \alpha_1, \cos \alpha_2, \cos \alpha_3 \right) 
        & \text { 3D polar } \\\\

        1 \hat{i}+1 \hat{j} +1 \hat{k} & \text { 3D vector } \\

        1 \left( \cos \alpha_1  \hat{i}
                +\cos \alpha_2  \hat{j} 
                +\cos \alpha_3  \hat{k} 
          \right) & \text { 3D vector } 

        \end{array}
        $
        """
        soln_stmts.append(soln_stmt.strip())

        soln_stmt = r"""
        """
        soln_stmts.append(soln_stmt.strip())

        soln_stmt = r"""
        """
        soln_stmts.append(soln_stmt.strip())

        soln_stmt = r"""
        """
        soln_stmts.append(soln_stmt.strip())

        soln_stmt = r"""
        """
        soln_stmts.append(soln_stmt.strip())

        soln_s = "<br/><br/>".join(soln_stmts)
        problemTemplate.add_solution(soln_s.strip())
        #problemTemplate.add_solution(svg_str, 'text/svg')

        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip())
        
        return problemTemplate
        pass
    




