@extends('layouts.admin')

@section('heading', 'Staff roles')
@section('subheading', 'Create custom roles for your shop and control what each one can access.')

@section('actions')
  <a href="{{ route('shop.roles.create') }}" class="px-4 py-2 rounded-lg text-sm font-medium text-white" style="background:#C2185B;">+ New role</a>
@endsection

@section('content')
@include('partials.master-tabs')
@if (session('status'))
  <div class="mb-4 text-sm rounded-lg px-4 py-3" style="background:#E1F5EE; color:#0F6E56;">
    {{ session('status') }}
  </div>
@endif

<div class="card p-6">
  <table class="w-full text-sm">
    <thead>
      <tr class="text-left" style="color:#a19a8f;">
        <th class="pb-3 font-medium text-xs">Role</th>
        <th class="pb-3 font-medium text-xs">Permissions</th>
        <th class="pb-3 font-medium text-xs">Staff assigned</th>
        <th class="pb-3 font-medium text-xs text-right">Actions</th>
      </tr>
    </thead>
    <tbody style="color:#1A1625;">
      @forelse($roles as $role)
        <tr class="border-t" style="border-color:#f2ece0;">
          <td class="py-3 font-medium">{{ $role->name }}</td>
          <td class="py-3">{{ $role->permissions->count() }} permission(s)</td>
          <td class="py-3">{{ $role->users_count }}</td>
          <td class="py-3 text-right">
            <a href="{{ route('shop.roles.edit', $role) }}" class="text-xs font-medium" style="color:#5E35B1;">Edit</a>
            <form method="POST" action="{{ route('shop.roles.destroy', $role) }}" class="inline" onsubmit="return confirm('Remove this role?');">
              @csrf @method('DELETE')
              <button type="submit" class="text-xs font-medium ml-3" style="color:#C2185B;">Delete</button>
            </form>
          </td>
        </tr>
      @empty
        <tr><td colspan="4" class="py-6 text-center text-sm" style="color:#a19a8f;">No roles yet — create your first one (e.g. Cutter, Cashier).</td></tr>
      @endforelse
    </tbody>
  </table>
</div>

@endsection
