from flask_wtf import FlaskForm
from wtforms import StringField, TextAreaField, SelectField, EmailField, PasswordField, BooleanField, SubmitField
from wtforms.validators import DataRequired, Email, Length, Optional

class ContactForm(FlaskForm):
    name = StringField('Full Name', validators=[
        DataRequired(message="Please enter your full name"),
        Length(min=2, max=100, message="Name must be between 2 and 100 characters")
    ])
    email = EmailField('Email Address', validators=[
        DataRequired(message="Please enter your email address"),
        Email(message="Please enter a valid email address")
    ])
    phone = StringField('Phone Number', validators=[
        Optional(),
        Length(max=20, message="Phone number is too long")
    ])
    subject = SelectField('Subject', choices=[
        ('', 'Select a subject'),
        ('general', 'General Inquiry'),
        ('enrollment', 'Enrollment Information'),
        ('grade10', 'Grade 10 Subjects'),
        ('grade11', 'Grade 11 Subjects'),
        ('grade12', 'Grade 12 Subjects'),
        ('rewrite', 'Grade 12 Rewrite/Upgrade'),
        ('cat', 'Computer Applications Technology'),
        ('science', 'Science Subjects'),
        ('fees', 'Fee Structure'),
        ('other', 'Other')
    ], validators=[DataRequired(message="Please select a subject")])
    message = TextAreaField('Message', validators=[
        DataRequired(message="Please enter your message"),
        Length(min=10, max=2000, message="Message must be between 10 and 2000 characters")
    ])
    submit = SubmitField('Send Message')

class ReplyForm(FlaskForm):
    reply_message = TextAreaField('Reply Message', validators=[
        DataRequired(message="Please enter your reply"),
        Length(min=10, max=3000, message="Reply must be between 10 and 3000 characters")
    ])
    submit = SubmitField('Send Reply')

class LoginForm(FlaskForm):
    username = StringField('Username', validators=[
        DataRequired(message="Please enter your username")
    ])
    password = PasswordField('Password', validators=[
        DataRequired(message="Please enter your password")
    ])
    remember_me = BooleanField('Remember Me')
    submit = SubmitField('Sign In')

class ContentForm(FlaskForm):
    section = SelectField('Section', choices=[
        ('hero', 'Hero Section'),
        ('about', 'About Section'),
        ('subjects', 'Subjects Section'),
        ('contact', 'Contact Section'),
        ('footer', 'Footer')
    ], validators=[DataRequired()])
    key = StringField('Key', validators=[
        DataRequired(),
        Length(max=100)
    ])
    value = TextAreaField('Content', validators=[DataRequired()])
    content_type = SelectField('Content Type', choices=[
        ('text', 'Plain Text'),
        ('html', 'HTML'),
        ('image', 'Image URL')
    ], default='text')
    submit = SubmitField('Save Content')

class SubjectForm(FlaskForm):
    name = StringField('Subject Name', validators=[DataRequired(), Length(max=100)])
    code = StringField('Subject Code', validators=[DataRequired(), Length(max=20)])
    grade_level = SelectField('Grade Level', choices=[
        ('10', 'Grade 10'),
        ('11', 'Grade 11'),
        ('12', 'Grade 12'),
        ('rewrite', 'Grade 12 Rewrite/Upgrade')
    ], validators=[DataRequired()])
    description = TextAreaField('Description', validators=[Optional()])
    icon = StringField('Icon Class (Bootstrap Icons)', default='bi-book')
    color = SelectField('Color Theme', choices=[
        ('primary', 'Blue (Primary)'),
        ('success', 'Green (Success)'),
        ('info', 'Cyan (Info)'),
        ('warning', 'Yellow (Warning)'),
        ('danger', 'Red (Danger)'),
        ('secondary', 'Gray (Secondary)')
    ], default='primary')
    display_order = StringField('Display Order', default='0')
    is_active = BooleanField('Active', default=True)
    submit = SubmitField('Save Subject')
