from apps.subscriptions.models import Plan, PlanType
from django.conf import settings
from bs4 import BeautifulSoup


# def monthly_plans(request):
#     plans = Plan.objects.filter(plan_duration=PlanType.Monthly)
#     return {'monthly_plans':plans}

def monthly_plans(request):
    plans = Plan.objects.filter(plan_duration=PlanType.Monthly)
    for plan in plans:
        soup = BeautifulSoup(plan.describe, 'html.parser')
        plan.describe = [(p.text).replace('\n','').replace('\r','').replace('\t','').strip() for p in soup.find_all('li')]
         
    return {'monthly_plans':plans}


def yearly_plans(request):
    plans = Plan.objects.filter(plan_duration=PlanType.Yearly)
    return {'yearly_plans':plans}

def weekly_plans(request):
    plans = Plan.objects.filter(plan_duration=PlanType.Weekly)
    return {'weekly_plans':plans}


def get_plans(request):
    return {"plans":zip(
        Plan.objects.filter(plan_duration=PlanType.Weekly).order_by('price').exclude(plan_name='Free'), 
        Plan.objects.filter(plan_duration=PlanType.Monthly).order_by('price').exclude(plan_name='Free'),
        Plan.objects.filter(plan_duration=PlanType.Yearly).order_by('price').exclude(plan_name="Free")
        )
    }


# def get_plans_backup(request):
#     weekly_plans = Plan.objects.filter(plan_duration=PlanType.Weekly)
#     monthly_plans = Plan.objects.filter(plan_duration=PlanType.Monthly) 
#     yearly_plans = Plan.objects.filter(plan_duration=PlanType.Yearly)

#     for plans in (weekly_plans, monthly_plans, yearly_plans):
#         for plan in plans:
#             soup = BeautifulSoup(plan.describe, 'html.parser')
#             # plan.describe = [(p.text).replace('\n','').replace('\r','').replace('\t','').strip() for p in soup.find_all('li')]
#             new_describe = [(p.text.replace('\n','').replace('\r','').replace('\t','')).strip() for p in soup.find_all('li')]
#             plan.describe = new_describe
#     return {
#             'plans':zip(weekly_plans, monthly_plans, yearly_plans)
#             }



# def get_plans(request):
#     plan_durations = [PlanType.Weekly, PlanType.Monthly, PlanType.Yearly]
#     updated_plans = {duration: [] for duration in plan_durations}

#     for duration in plan_durations:
#         plans = Plan.objects.filter(plan_duration=duration)
#         for plan in plans:
#             soup = BeautifulSoup(plan.describe, 'html.parser')
#             new_describe = [p.text.replace('\n', '').replace('\r', '').replace('\t', '').strip() for p in soup.find_all('li')]
#             plan.describe = new_describe
#             updated_plans[duration].append({
#                 'plan_id': plan.plan_id,
#                 'plan_name': plan.plan_name,
#                 'describe': new_describe,
#                 'price':plan.price,
#                 'plan_type':plan.plan_type
#                 })
#     print(updated_plans)
#     return {
#     'plans':zip(updated_plans[PlanType.Weekly], updated_plans[PlanType.Monthly], updated_plans[PlanType.Yearly])
#     }


def paypal_info(request):
    return {
        "CLIENT_ID":settings.PAYPAL_CLIENTID
    }