@php
    $record = $record ?? null;
    $selectedCategory = old('courseware_category_id', $record->courseware_category_id ?? null);
    $selectedPartner = old('authorised_partner_id', $record?->authorised_partner_id);
@endphp
@include('iqec.partials.partner-personal-fields', ['record' => $record])
<h4 class="mb-3">Official Information</h4>
<div class="row">
    <div class="col-md-6 mb-3">
        <label class="form-label">Name of Institute / Organization</label>
        <input type="text" name="institute_name" class="form-control" value="{{ old('institute_name', $record->institute_name ?? '') }}">
    </div>
    @if (auth()->user()->isSuperAdmin())
        <div class="col-md-6 mb-3">
            <label class="form-label">Authorised Partner</label>
            <select name="authorised_partner_id" class="form-control js-select2 @error('authorised_partner_id') is-invalid @enderror" data-placeholder="Search and select authorised partner">
                <option value="">Select authorised partner</option>
                @foreach ($authorisedPartners as $partner)
                    <option value="{{ $partner->id }}" @selected((string) $selectedPartner === (string) $partner->id)>
                        {{ $partner->applicant_name }}@if ($partner->email) ({{ $partner->email }})@endif
                    </option>
                @endforeach
            </select>
            @error('authorised_partner_id')
                <div class="invalid-feedback d-block">{{ $message }}</div>
            @enderror
        </div>
    @endif
    <div class="col-md-6 mb-3">
        <label class="form-label">Building No/Name</label>
        <input type="text" name="official_building" class="form-control" value="{{ old('official_building', $record->official_building ?? '') }}">
    </div>
    <div class="col-md-6 mb-3">
        <label class="form-label">Street</label>
        <input type="text" name="official_street" class="form-control" value="{{ old('official_street', $record->official_street ?? '') }}">
    </div>
    <div class="col-md-6 mb-3">
        <label class="form-label">City</label>
        <input type="text" name="official_city" class="form-control" value="{{ old('official_city', $record->official_city ?? '') }}">
    </div>
    <div class="col-md-6 mb-3">
        <label class="form-label">State</label>
        <input type="text" name="official_state" class="form-control" value="{{ old('official_state', $record->official_state ?? '') }}">
    </div>
    <div class="col-md-6 mb-3">
        <label class="form-label">Postal code</label>
        <input type="text" name="official_postal_code" class="form-control" value="{{ old('official_postal_code', $record->official_postal_code ?? '') }}">
    </div>
    <div class="col-md-6 mb-3">
        <label class="form-label">Country</label>
        <input type="text" name="official_country" class="form-control" value="{{ old('official_country', $record->official_country ?? '') }}">
    </div>
    <div class="col-md-6 mb-3">
        <label class="form-label">Email</label>
        <input type="email" name="official_email" class="form-control" value="{{ old('official_email', $record->official_email ?? '') }}" autocomplete="email" autocapitalize="none" spellcheck="false">
    </div>
    <div class="col-md-6 mb-3">
        <label class="form-label">Phone Number with Country Code</label>
        <input type="text" name="official_phone" class="form-control" value="{{ old('official_phone', $record->official_phone ?? '') }}">
    </div>
    <div class="col-md-6 mb-3">
        <label class="form-label">Website</label>
        <input type="text" name="website" class="form-control" value="{{ old('website', $record->website ?? '') }}">
    </div>
    <div class="col-md-6 mb-3">
        <label class="form-label">Second Contact Person Name</label>
        <input type="text" name="second_contact_name" class="form-control" value="{{ old('second_contact_name', $record->second_contact_name ?? '') }}">
    </div>
    <div class="col-md-6 mb-3">
        <label class="form-label">Email Address</label>
        <input type="email" name="second_contact_email" class="form-control" value="{{ old('second_contact_email', $record->second_contact_email ?? '') }}" autocomplete="email" autocapitalize="none" spellcheck="false">
    </div>
    <div class="col-md-6 mb-3">
        <label class="form-label">Phone Number with Country Code</label>
        <input type="text" name="second_contact_phone" class="form-control" value="{{ old('second_contact_phone', $record->second_contact_phone ?? '') }}">
    </div>
    <div class="col-md-6 mb-3">
        <label class="form-label">Mobile Number with Country Code</label>
        <input type="text" name="mobile" class="form-control" value="{{ old('mobile', $record->mobile ?? '') }}">
    </div>
    <div class="col-md-6 mb-3">
        <label class="form-label">Practical Lab (Area in sq feet)</label>
        <input type="text" name="practical_lab_area" class="form-control" value="{{ old('practical_lab_area', $record->practical_lab_area ?? '') }}">
    </div>
    <div class="col-md-6 mb-3">
        <label class="form-label">Theory Class Room (Area in sq feet)</label>
        <input type="text" name="theory_classroom_area" class="form-control" value="{{ old('theory_classroom_area', $record->theory_classroom_area ?? '') }}">
    </div>
</div>
<h4 class="mb-3">Category</h4>
<div class="mb-3">
    <label class="form-label">Select category</label>
    <select name="courseware_category_id" class="form-control js-select2 @error('courseware_category_id') is-invalid @enderror" data-placeholder="Search and select category">
        <option value="">Select category</option>
        @foreach ($categories ?? [] as $category)
            <option value="{{ $category->id }}" @selected((string) $selectedCategory === (string) $category->id)>{{ $category->name }}</option>
        @endforeach
    </select>
    @error('courseware_category_id')
        <div class="invalid-feedback d-block">{{ $message }}</div>
    @enderror
</div>
<div class="mb-3">
    <label class="form-label">Your Requirements</label>
    <textarea name="requirements" class="form-control" rows="4">{{ old('requirements', $record->requirements ?? '') }}</textarea>
</div>
