<x-app-layout title="Settings">
    <div class="mx-auto max-w-2xl">
        <h1 class="text-xl font-semibold text-slate-900">Organization settings</h1>

        <form method="POST" action="{{ route('meet.settings.update') }}" enctype="multipart/form-data" class="mt-6 space-y-5 rounded-2xl border border-slate-200 bg-white p-6">
            @csrf @method('PUT')

            <div>
                <label class="block text-sm font-medium text-slate-700">Organization name</label>
                <input type="text" name="name" value="{{ old('name', $organization->name) }}" @disabled(! $canManage) required class="mt-1 w-full rounded-lg border-slate-300 text-sm">
            </div>

            <div>
                <label class="block text-sm font-medium text-slate-700">Organization type</label>
                <select name="org_type" @disabled(! $canManage) class="mt-1 w-full rounded-lg border-slate-300 text-sm">
                    @foreach ($orgTypes as $value => $label)
                        <option value="{{ $value }}" @selected(old('org_type', data_get($organization->settings, 'org_type', 'business')) === $value)>{{ $label }}</option>
                    @endforeach
                </select>
            </div>

            <div>
                <label class="block text-sm font-medium text-slate-700">Timezone</label>
                <select name="timezone" @disabled(! $canManage) class="mt-1 w-full rounded-lg border-slate-300 text-sm">
                    @foreach (timezone_identifiers_list() as $tz)
                        <option value="{{ $tz }}" @selected(old('timezone', $organization->timezone) === $tz)>{{ $tz }}</option>
                    @endforeach
                </select>
            </div>

            @if ($canManage)
                <div>
                    <label class="block text-sm font-medium text-slate-700">Logo</label>
                    <input type="file" name="logo" accept="image/png,image/jpeg,image/webp,image/svg+xml" class="mt-2 block w-full text-sm">
                    @if (\App\Support\OrganizationBranding::hasCustomLogo($organization))
                        <label class="mt-2 flex items-center gap-2 text-sm"><input type="checkbox" name="remove_logo" value="1"> Remove current logo</label>
                    @endif
                </div>
                <button type="submit" class="btn-primary">Save settings</button>
            @endif
        </form>

        @if ($isAdmin ?? false)
            <div class="mt-6 rounded-2xl border border-slate-200 bg-white p-6">
                <h2 class="text-sm font-semibold text-slate-900">Advanced</h2>
                <ul class="mt-3 space-y-2 text-sm">
                    <li><a href="{{ route('meet.settings.security') }}" class="text-indigo-600 hover:text-indigo-800">Security policy</a></li>
                    <li><a href="{{ route('meet.settings.calendar') }}" class="text-indigo-600 hover:text-indigo-800">Calendar connections</a></li>
                    <li><a href="{{ route('meet.settings.webhooks') }}" class="text-indigo-600 hover:text-indigo-800">Webhooks</a></li>
                </ul>
            </div>
        @endif

        <p class="mt-4 text-sm text-slate-500">{{ $branchCount }} branch(es) configured.</p>
    </div>
</x-app-layout>
