from django import forms
from .models import WorkLog, Project, Team, Worker

class AttendanceLogForm(forms.ModelForm):
    class Meta:
        model = WorkLog
        fields = ['date', 'project', 'team', 'workers', 'supervisor', 'overtime_amount', 'notes']
        widgets = {
            'date': forms.DateInput(attrs={'type': 'date', 'class': 'form-control'}),
            'project': forms.Select(attrs={'class': 'form-select'}),
            'team': forms.Select(attrs={'class': 'form-select'}),
            'workers': forms.CheckboxSelectMultiple(attrs={'class': 'form-check-input'}),
            'supervisor': forms.Select(attrs={'class': 'form-select'}),
            'overtime_amount': forms.Select(attrs={'class': 'form-select'}),
            'notes': forms.Textarea(attrs={'class': 'form-control', 'rows': 3}),
        }

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['workers'].queryset = Worker.objects.filter(active=True)
        self.fields['project'].queryset = Project.objects.filter(active=True)
        self.fields['team'].queryset = Team.objects.filter(active=True)
