from django import forms
from .models import Book, Transaction

class BookForm(forms.ModelForm):
    class Meta:
        model = Book
        fields = ['title', 'author', 'isbn', 'total_copies']
        widgets = {
            'title': forms.TextInput(attrs={'class': 'form-control'}),
            'author': forms.TextInput(attrs={'class': 'form-control'}),
            'isbn': forms.TextInput(attrs={'class': 'form-control'}),
            'total_copies': forms.NumberInput(attrs={'class': 'form-control'}),
        }

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['total_copies'].initial = 1

class IssueBookForm(forms.ModelForm):
    class Meta:
        model = Transaction
        fields = ['borrower_name']
        widgets = {
            'borrower_name': forms.TextInput(attrs={'class': 'form-control'}),
        }
