<!--
     This file is part of the happyDomain (R) project.
     Copyright (c) 2022-2026 happyDomain
     Authors: Pierre-Olivier Mercier, et al.

     This program is offered under a commercial and under the AGPL license.
     For commercial licensing, contact us at <contact@happydomain.org>.

     For AGPL licensing:
     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU Affero General Public License as published by
     the Free Software Foundation, either version 3 of the License, or
     (at your option) any later version.

     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU Affero General Public License for more details.

     You should have received a copy of the GNU Affero General Public License
     along with this program.  If not, see <https://www.gnu.org/licenses/>.
-->

<script lang="ts">
    import { page } from "$app/state";

    import { t } from "$lib/translations";
    import type { Domain } from "$lib/model/domain";
    import { domainLink } from "$lib/stores/domains";
    import { checkers } from "$lib/stores/checkers";
    import CheckerConfigPage from "$lib/components/checkers/CheckerConfigPage.svelte";

    let domain: Domain = $derived(page.data.domain);
    let checkerId = $derived(page.params.checkerId!);
    let checksBase = $derived(`/domains/${domainLink(domain.id)}/checks`);
    let isDomainChecker = $derived(!!$checkers?.[checkerId]?.availability?.applyToDomain);
</script>

<CheckerConfigPage
    scope={{ domainId: domain.id }}
    {checksBase}
    {checkerId}
    domainName={domain.domain}
    showSchedule={isDomainChecker}
    editableGroups={(status) => [
        {
            label: $t("checkers.option-groups.domain-settings"),
            opts: status.options?.domainOpts || [],
        },
        {
            label: $t("checkers.detail.admin-options"),
            opts: status.options?.adminOpts || [],
        },
        {
            label: $t("checkers.detail.configuration"),
            opts: status.options?.userOpts || [],
        },
    ]}
    readOnlyGroups={(status) => [
        {
            key: "serviceOpts",
            label: $t("checkers.option-groups.service-settings"),
            opts: status.options?.serviceOpts || [],
        },
        {
            key: "runOpts",
            label: $t("checkers.option-groups.checker-parameters"),
            opts: status.options?.runOpts || [],
        },
    ]}
/>
