@extends('layouts.default')
@section('title', $page_title)
@section('content')
<div class="container-fluid">
    @include('admin.partials.page-header', ['actions' => new \Illuminate\Support\HtmlString('<a href="'.route('admin.clients.portal-users.index', $client).'" class="btn btn-light">Listeye Dön</a>')])

    @if($errors->any())
        <div class="alert alert-danger">
            <strong>Kontrol et:</strong>
            <ul class="mb-0 mt-2">
                @foreach($errors->all() as $error)
                    <li>{{ $error }}</li>
                @endforeach
            </ul>
        </div>
    @endif

    <div class="card">
        <div class="card-header border-0 pb-0">
            <div>
                <h4 class="card-title mb-1">{{ $client->company_name }}</h4>
                <p class="text-muted mb-0">Yeni kullanıcı oluşturabilir veya aynı e-posta ile mevcut kullanıcıyı bu müşteriye bağlayabilirsin.</p>
            </div>
        </div>
        <div class="card-body">
            <form action="{{ route('admin.clients.portal-users.store', $client) }}" method="POST">
                @csrf
                <div class="row">
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Ad Soyad</label>
                        <input type="text" name="name" value="{{ old('name') }}" class="form-control" required>
                    </div>
                    <div class="col-md-6 mb-3">
                        <label class="form-label">E-posta</label>
                        <input type="email" name="email" value="{{ old('email') }}" class="form-control" required>
                    </div>
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Şifre</label>
                        <input type="password" name="password" class="form-control" placeholder="Boş bırakırsan geçici şifre üretir">
                    </div>
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Şifre Tekrar</label>
                        <input type="password" name="password_confirmation" class="form-control">
                    </div>
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Rol</label>
                        <select name="role" class="form-control">
                            <option value="viewer" @selected(old('role') === 'viewer')>Görüntüleyici</option>
                            <option value="report_viewer" @selected(old('role') === 'report_viewer')>Rapor Kullanıcısı</option>
                            <option value="manager" @selected(old('role') === 'manager')>Müşteri Yetkilisi</option>
                        </select>
                    </div>
                    <div class="col-md-6 mb-3 d-flex align-items-end">
                        <label class="mb-2">
                            <input type="checkbox" name="is_active" value="1" checked> Portal erişimi aktif olsun
                        </label>
                    </div>
                </div>
                <button class="btn btn-primary" type="submit">Portal Kullanıcısını Kaydet</button>
            </form>
        </div>
    </div>
</div>
@endsection
