@extends('layouts.app')

@section('title', 'Create Savings Product')

@section('content')
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-header">
                    <h3 class="card-title">Create Savings Product</h3>
                    <div class="card-tools">
                        <a href="{{ route('savings.products.index') }}" class="btn btn-secondary btn-sm">
                            <i class="fas fa-arrow-left"></i> Back
                        </a>
                    </div>
                </div>
                <form action="{{ route('savings.products.store') }}" method="POST">
                    @csrf
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label for="name">Product Name *</label>
                                    <input type="text" class="form-control @error('name') is-invalid @enderror" id="name" name="name" value="{{ old('name') }}" required>
                                    @error('name')
                                        <div class="invalid-feedback">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label for="code">Product Code *</label>
                                    <input type="text" class="form-control @error('code') is-invalid @enderror" id="code" name="code" value="{{ old('code') }}" required>
                                    @error('code')
                                        <div class="invalid-feedback">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="description">Description</label>
                            <textarea class="form-control @error('description') is-invalid @enderror" id="description" name="description" rows="3">{{ old('description') }}</textarea>
                            @error('description')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label for="type">Product Type *</label>
                                    <select class="form-control @error('type') is-invalid @enderror" id="type" name="type" required>
                                        <option value="">Select Type</option>
                                        <option value="savings" {{ old('type') == 'savings' ? 'selected' : '' }}>Savings</option>
                                        <option value="fixed_deposit" {{ old('type') == 'fixed_deposit' ? 'selected' : '' }}>Fixed Deposit</option>
                                        <option value="current" {{ old('type') == 'current' ? 'selected' : '' }}>Current</option>
                                    </select>
                                    @error('type')
                                        <div class="invalid-feedback">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label for="interest_rate">Interest Rate (%) *</label>
                                    <input type="number" step="0.01" class="form-control @error('interest_rate') is-invalid @enderror" id="interest_rate" name="interest_rate" value="{{ old('interest_rate', 0) }}" required>
                                    @error('interest_rate')
                                        <div class="invalid-feedback">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label for="interest_calculation">Interest Calculation *</label>
                                    <select class="form-control @error('interest_calculation') is-invalid @enderror" id="interest_calculation" name="interest_calculation" required>
                                        <option value="">Select Frequency</option>
                                        <option value="daily" {{ old('interest_calculation') == 'daily' ? 'selected' : '' }}>Daily</option>
                                        <option value="monthly" {{ old('interest_calculation') == 'monthly' ? 'selected' : '' }}>Monthly</option>
                                        <option value="quarterly" {{ old('interest_calculation') == 'quarterly' ? 'selected' : '' }}>Quarterly</option>
                                        <option value="annually" {{ old('interest_calculation') == 'annually' ? 'selected' : '' }}>Annually</option>
                                    </select>
                                    @error('interest_calculation')
                                        <div class="invalid-feedback">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label for="interest_posting">Interest Posting *</label>
                                    <select class="form-control @error('interest_posting') is-invalid @enderror" id="interest_posting" name="interest_posting" required>
                                        <option value="">Select Frequency</option>
                                        <option value="daily" {{ old('interest_posting') == 'daily' ? 'selected' : '' }}>Daily</option>
                                        <option value="monthly" {{ old('interest_posting') == 'monthly' ? 'selected' : '' }}>Monthly</option>
                                        <option value="quarterly" {{ old('interest_posting') == 'quarterly' ? 'selected' : '' }}>Quarterly</option>
                                        <option value="annually" {{ old('interest_posting') == 'annually' ? 'selected' : '' }}>Annually</option>
                                    </select>
                                    @error('interest_posting')
                                        <div class="invalid-feedback">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label for="minimum_opening_balance">Minimum Opening Balance *</label>
                                    <input type="number" step="0.01" class="form-control @error('minimum_opening_balance') is-invalid @enderror" id="minimum_opening_balance" name="minimum_opening_balance" value="{{ old('minimum_opening_balance', 0) }}" required>
                                    @error('minimum_opening_balance')
                                        <div class="invalid-feedback">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label for="minimum_balance">Minimum Balance *</label>
                                    <input type="number" step="0.01" class="form-control @error('minimum_balance') is-invalid @enderror" id="minimum_balance" name="minimum_balance" value="{{ old('minimum_balance', 0) }}" required>
                                    @error('minimum_balance')
                                        <div class="invalid-feedback">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label for="maximum_balance">Maximum Balance</label>
                                    <input type="number" step="0.01" class="form-control @error('maximum_balance') is-invalid @enderror" id="maximum_balance" name="maximum_balance" value="{{ old('maximum_balance') }}">
                                    @error('maximum_balance')
                                        <div class="invalid-feedback">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label for="opening_fee">Opening Fee *</label>
                                    <input type="number" step="0.01" class="form-control @error('opening_fee') is-invalid @enderror" id="opening_fee" name="opening_fee" value="{{ old('opening_fee', 0) }}" required>
                                    @error('opening_fee')
                                        <div class="invalid-feedback">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label for="closing_fee">Closing Fee *</label>
                                    <input type="number" step="0.01" class="form-control @error('closing_fee') is-invalid @enderror" id="closing_fee" name="closing_fee" value="{{ old('closing_fee', 0) }}" required>
                                    @error('closing_fee')
                                        <div class="invalid-feedback">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label for="monthly_fee">Monthly Fee *</label>
                                    <input type="number" step="0.01" class="form-control @error('monthly_fee') is-invalid @enderror" id="monthly_fee" name="monthly_fee" value="{{ old('monthly_fee', 0) }}" required>
                                    @error('monthly_fee')
                                        <div class="invalid-feedback">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label for="withdrawal_fee">Withdrawal Fee *</label>
                                    <input type="number" step="0.01" class="form-control @error('withdrawal_fee') is-invalid @enderror" id="withdrawal_fee" name="withdrawal_fee" value="{{ old('withdrawal_fee', 0) }}" required>
                                    @error('withdrawal_fee')
                                        <div class="invalid-feedback">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <div class="custom-control custom-checkbox">
                                        <input class="custom-control-input" type="checkbox" id="allows_withdrawals" name="allows_withdrawals" value="1" {{ old('allows_withdrawals', true) ? 'checked' : '' }}>
                                        <label for="allows_withdrawals" class="custom-control-label">Allows Withdrawals</label>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <div class="custom-control custom-checkbox">
                                        <input class="custom-control-input" type="checkbox" id="allows_deposits" name="allows_deposits" value="1" {{ old('allows_deposits', true) ? 'checked' : '' }}>
                                        <label for="allows_deposits" class="custom-control-label">Allows Deposits</label>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <div class="custom-control custom-checkbox">
                                        <input class="custom-control-input" type="checkbox" id="requires_approval" name="requires_approval" value="1" {{ old('requires_approval') ? 'checked' : '' }}>
                                        <label for="requires_approval" class="custom-control-label">Requires Approval</label>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <div class="custom-control custom-checkbox">
                                        <input class="custom-control-input" type="checkbox" id="is_active" name="is_active" value="1" {{ old('is_active', true) ? 'checked' : '' }}>
                                        <label for="is_active" class="custom-control-label">Active</label>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="card-footer">
                        <button type="submit" class="btn btn-primary">Create Product</button>
                        <a href="{{ route('savings.products.index') }}" class="btn btn-secondary">Cancel</a>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
@endsection
