<template>
    <section
        class="card"
        role="region"
    >
        <div class="card-header bg-primary-dark">
            <h3 class="card-title">
                {{ $gettext('SoundExchange Report') }}
            </h3>
        </div>

        <form
            id="report-form"
            class="form vue-form"
            method="GET"
            :action="apiUrl"
            target="_blank"
        >
            <div class="card-body">
                <b-form-fieldset>
                    <p>
                        This report is intended for licensing in the United States only, for webcasters paying royalties
                        via SoundExchange. Learn more about the requirements for reporting and classification on the
                        <a
                            href="https://www.soundexchange.com/service-provider/reporting-requirements/"
                            target="_blank"
                        >
                            SoundExchange web site
                        </a>.
                    </p>

                    <ul>
                        <li>
                            AzuraCast assumes that your station fits SoundExchange Transmission Category A, "Eligible
                            nonsubscription transmissions other than broadcast simulcasts and transmissions of non-music
                            programming." If your station does not fall within this category, update the transmission
                            category field accordingly.
                        </li>
                        <li>
                            The data collected by AzuraCast meets the SoundExchange standard for Actual Total
                            Performances (ATP) by tracking unique listeners across all song plays. All other information
                            is derived from the metadata of the uploaded songs themselves, and may not be completely
                            accurate.
                        </li>
                        <li>
                            Reporting requirements for SoundExchange may change at any time. AzuraCast is non-commercial
                            community-built software and cannot guarantee that its reporting format will always be
                            up-to-date.
                        </li>
                        <li>
                            You should always verify the report generated by AzuraCast before sending it. In particular,
                            either the ISRC (International Standard Recording Code) or *both* the album and label are
                            required for every row, and may not be provided in the song metadata. To locate an ISRC for
                            a track, you should use <a
                                href="https://isrc.soundexchange.com"
                                target="_blank"
                            >SoundExchange's
                                ISRC search tool</a>.
                        </li>
                    </ul>
                </b-form-fieldset>

                <b-form-fieldset>
                    <b-wrapped-form-group
                        id="form_start_date"
                        name="start_date"
                        :field="v$.start_date"
                        input-type="date"
                    >
                        <template #label>
                            {{ $gettext('Start Date') }}
                        </template>
                    </b-wrapped-form-group>

                    <b-wrapped-form-group
                        id="form_end_date"
                        name="end_date"
                        :field="v$.end_date"
                        input-type="date"
                    >
                        <template #label>
                            {{ $gettext('End Date') }}
                        </template>
                    </b-wrapped-form-group>

                    <b-wrapped-form-checkbox
                        id="form_edit_fetch_isrc"
                        name="fetch_isrc"
                        :field="v$.fetch_isrc"
                    >
                        <template #label>
                            {{ $gettext('Attempt to Automatically Retrieve ISRC When Missing') }}
                        </template>
                        <template #description>
                            {{
                                $gettext('If enabled, AzuraCast will connect to the MusicBrainz database to attempt to find an ISRC for any files where one is missing. Disabling this may improve performance.')
                            }}
                        </template>
                    </b-wrapped-form-checkbox>
                </b-form-fieldset>

                <b-button
                    type="submit"
                    size="lg"
                    :variant="(v$.$invalid) ? 'danger' : 'primary'"
                    class="mt-2"
                >
                    {{ $gettext('Generate Report') }}
                </b-button>
            </div>
        </form>
    </section>
</template>

<script setup>
import {required} from '@vuelidate/validators';
import BWrappedFormGroup from "~/components/Form/BWrappedFormGroup";
import BFormFieldset from "~/components/Form/BFormFieldset";
import BWrappedFormCheckbox from "~/components/Form/BWrappedFormCheckbox";
import {useVuelidateOnForm} from "~/functions/useVuelidateOnForm";

const props = defineProps({
    apiUrl: {
        type: String,
        required: true
    },
    startDate: {
        type: String,
        required: true
    },
    endDate: {
        type: String,
        required: true
    }
});

const {v$} = useVuelidateOnForm(
    {
        start_date: {required},
        end_date: {required},
        fetch_isrc: {}
    },
    {
        start_date: props.startDate,
        end_date: props.endDate,
        fetch_isrc: false
    }
);
</script>
