<?xml version="1.0" encoding="UTF-8"?>
<CustomMetadata xmlns="http://soap.sforce.com/2006/04/metadata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <label>Shift Attendance Distance Filter</label>
    <protected>false</protected>
    <values>
        <field>b3s__Javascript_Code__c</field>
        <value xsi:type="xsd:string"><![CDATA[
{
    name: "shift_attendance_distance",
    label: "Clock / Check-in Distance",
    type: 'shift',
    //Requires b3s__Clock_In_Distance__c, b3s__Clock_Out_Distance__c and
    //b3s__Check_In_Distance__c (metres from the Work Site) in the shift
    //definition's additionalFields.
    inputs: [
        {
            name: "events",
            type: "multiselect",
            label: "Recorded at",
            required: true,
            default: ["b3s__Clock_In_Distance__c"],
            options: [
                { label: "Clock in", value: "b3s__Clock_In_Distance__c" },
                { label: "Clock out", value: "b3s__Clock_Out_Distance__c" },
                { label: "Check in", value: "b3s__Check_In_Distance__c" }
            ]
        },
        {
            name: "distance",
            type: "select",
            label: "Further from the site than",
            required: true,
            default: "0.5",
            options: [
                { label: "500 m", value: "0.5" },
                { label: "1 km", value: "1" },
                { label: "5 km", value: "5" },
                { label: "10 km", value: "10" }
            ]
        }
    ],
    //Keeps shifts where any selected location is further from the site than
    //the threshold. Blank distances (no GPS, or site without a location) never match.
    matchesItems: function(event, items) {
        if (event.title !== 'shift') return true;

        const values = items[0] ?? {};
        const record = event.extendedProps?.record ?? {};
        const metres = Number(values.distance) * 1000;

        return (values.events ?? []).some((field) => record[field] != null && record[field] > metres);
    }
}
        ]]></value>
    </values>
    <values>
        <field>b3s__Order__c</field>
        <value xsi:type="xsd:double">12.0</value>
    </values>
</CustomMetadata>
