{"version":3,"file":"conflictHandlerManager.mjs","sources":["../../../../../../src/inAppMessaging/providers/pinpoint/utils/conflictHandlerManager.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n/**\n * The default conflict handler. Can be overridden by `setConflictHandler`.\n */\nlet conflictHandler = (messages) => {\n    // default behavior is to return the message closest to expiry\n    // this function assumes that messages processed by providers already filters out expired messages\n    const sorted = messages.sort((a, b) => {\n        const endDateA = a.metadata?.endDate;\n        const endDateB = b.metadata?.endDate;\n        // if both message end dates are falsy or have the same date string, treat them as equal\n        if (endDateA === endDateB) {\n            return 0;\n        }\n        // if only message A has an end date, treat it as closer to expiry\n        if (endDateA && !endDateB) {\n            return -1;\n        }\n        // if only message B has an end date, treat it as closer to expiry\n        if (!endDateA && endDateB) {\n            return 1;\n        }\n        // otherwise, compare them\n        return new Date(endDateA) < new Date(endDateB) ? -1 : 1;\n    });\n    // always return the top sorted\n    return sorted[0];\n};\n/**\n * Sets conflict handler.\n *\n * @internal\n */\nexport const setConflictHandler = (input) => {\n    conflictHandler = input;\n};\n/**\n * Returns the current conflict handler.\n *\n * @internal\n */\nexport const getConflictHandler = () => conflictHandler;\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA,IAAI,eAAe,GAAG,CAAC,QAAQ,KAAK;AACpC;AACA;AACA,IAAI,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK;AAC3C,QAAQ,MAAM,QAAQ,GAAG,CAAC,CAAC,QAAQ,EAAE,OAAO;AAC5C,QAAQ,MAAM,QAAQ,GAAG,CAAC,CAAC,QAAQ,EAAE,OAAO;AAC5C;AACA,QAAQ,IAAI,QAAQ,KAAK,QAAQ,EAAE;AACnC,YAAY,OAAO,CAAC;AACpB,QAAQ;AACR;AACA,QAAQ,IAAI,QAAQ,IAAI,CAAC,QAAQ,EAAE;AACnC,YAAY,OAAO,EAAE;AACrB,QAAQ;AACR;AACA,QAAQ,IAAI,CAAC,QAAQ,IAAI,QAAQ,EAAE;AACnC,YAAY,OAAO,CAAC;AACpB,QAAQ;AACR;AACA,QAAQ,OAAO,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;AAC/D,IAAI,CAAC,CAAC;AACN;AACA,IAAI,OAAO,MAAM,CAAC,CAAC,CAAC;AACpB,CAAC;AACD;AACA;AACA;AACA;AACA;AACY,MAAC,kBAAkB,GAAG,CAAC,KAAK,KAAK;AAC7C,IAAI,eAAe,GAAG,KAAK;AAC3B;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,kBAAkB,GAAG,MAAM;;;;"}