@php
use App\Models\ComplaintAgainst;

$departments =
ComplaintAgainst::where('status',1)
->orderBy('name')
->get();

@endphp

@extends('layouts.app')

@section('content')
<style>
    .container {
        background: url('{{ asset('loginwall5.jpg') }}') no-repeat center center fixed;
        background-size: cover;
    }
    .card {
        background: rgba(255, 255, 255, 0.9);
        backdrop-filter: blur(10px);
        box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.9);
        border-radius: 20px;
        border: 1px solid rgba(255, 255, 255, 0.18);
    }
    .card-header {
        background: transparent;
        border-bottom: none;
    }
    .form-control {
        border-radius: 10px;
    }
    .btn-primary {
        background-color: #d9534f;
        border: none;
        border-radius: 10px;
        padding: 10px 20px;
        font-weight: bold;
        letter-spacing: 1px;
    }
    .btn-primary:hover {
        background-color: #c9302c;
    }
</style>

<div class="container py-5">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card shadow-lg">
                <div class="card-header text-center mb-2">
                    <h4 class="fw-bold text-uppercase  text-danger" style="letter-spacing: 2px;">
                         Home & Tribal Affair's Department <br> Khyber Pakhtunkhwa <br> Complaint Cell
                    </h4>
                    <h5 class="fw-bold text-uppercase text-danger">
                        User Registration
                    </h5>
                </div>

                <div class="card-body p-4">
                    <form method="POST" action="{{ route('register') }}">
                    @csrf


                    <div class="mb-3">
                    <label>Name</label>

                    <input type="text"
                    class="form-control"
                    name="name"
                    value="{{old('name')}}"
                    required>

                    </div>



                    <div class="mb-3">

                    <label>Email Address</label>

                    <input type="email"
                    class="form-control"
                    name="email"
                    value="{{old('email')}}"
                    required>

                    </div>




                    <div class="mb-3">

                    <label>User Role</label>

                    <select name="role"
                    class="form-control"
                    id="role"
                    required>

                    <option value="">Select Role</option>

                    <option value="operator">
                    Operator
                    </option>

                    <option value="coordinator">
                    Coordinator
                    </option>

                    <option value="department">
                    Department User
                    </option>

                    <option value="admin">
                    Admin
                    </option>


                    </select>

                    </div>











                    <div class="mb-3"
                    id="departmentBox"
                    style="display:none;">


                    <label class="form-label">
                    Department / Section
                    </label>



                    <select name="complaint_against_id"
                    class="form-control">


                    <option value="">
                    Select Department
                    </option>


                    @foreach($departments as $dept)

                    <option value="{{ $dept->id }}">

                    {{ $dept->name }}

                    </option>


                    @endforeach


                    </select>


                    </div>

        <script>

        document
        .getElementById('role')
        .addEventListener('change',function(){


        if(this.value=="department")
        {

        document
        .getElementById('departmentBox')
        .style.display='block';


        }

        else
        {

        document
        .getElementById('departmentBox')
        .style.display='none';


        }



        });


        </script>


                    <div class="mb-3">


                    <label>Password</label>


                    <input type="password"
                    class="form-control"
                    name="password"
                    required>


                    </div>




                    <div class="mb-4">


                    <label>Confirm Password</label>


                    <input type="password"
                    class="form-control"
                    name="password_confirmation"
                    required>


                    </div>




                    <div class="form-check mb-3">


                    <input class="form-check-input"
                    type="checkbox"
                    name="is_admin"
                    value="1">


                    <label class="form-check-label">

                    Administrator

                    </label>


                    </div>





                    <button type="submit"
                    class="btn btn-primary w-100">

                    Register

                    </button>


                    </form>





                    <script>

                    document.getElementById('role')
                    .addEventListener('change',function(){


                    if(this.value=="department")
                    {

                    document.getElementById('departmentBox')
                    .style.display='block';

                    }

                    else
                    {

                    document.getElementById('departmentBox')
                    .style.display='none';

                    }


                    });


                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
