from editing import *
p='resources/js/layouts/AdminLayout.vue';s=read(p).replace("return href === '/admin' ? page.url === href : page.url.startsWith(href);", "const path = page.url.split('?')[0];\n    return href === '/admin' ? path === href : path === href || path.startsWith(`${href}/`);");write(p,s)
for p in ['app/Http/Middleware/HandleInertiaRequests.php','app/Http/Controllers/Admin/DataToolsController.php','routes/web.php']:
 s=read(p)
 s=s.replace(", 'emailSearchRapport', 'emailEntrepriseRappel'",'').replace(",'emailSearchRapport','emailEntrepriseRappel'",'')
 s=s.replace(" || $user->hasPermission('emailSearchRapport') || $user->hasPermission('emailEntrepriseRappel')",'')
 write(p,s)
p='app/Http/Controllers/Admin/DataToolsController.php';s=read(p)
s=s.replace("        Entreprise::whereIn('id', $data['recipient_ids'])->whereNotNull('courriel')->each(function (Entreprise $entreprise) use ($data) {", """        $recipients = Entreprise::whereIn('id', $data['recipient_ids'])->whereNotNull('courriel')
            ->when($request->user()->isMrcManager(), fn ($q) => $q->whereHas('ville', fn ($city) => $city->where('mrc_id', $request->user()->mrc_id)))->get();
        if ($recipients->count() !== count($data['recipient_ids'])) {
            throw ValidationException::withMessages(['recipient_ids' => 'Certains destinataires n’ont pas de courriel ou ne sont pas accessibles dans votre périmètre.']);
        }
        $recipients->each(function (Entreprise $entreprise) use ($data) {""")
write(p,s)
