{"version":3,"file":"minMax-ByUcegLJ.js","sources":["../../Client/shared/Common/ComparisonQuoteHelpers/index.ts","../../Client/node_modules/dayjs/plugin/minMax.js"],"sourcesContent":["import { getPath, getQuotePath } from '@app/Views';\r\nimport { ProductLine } from '@business/CommonSets';\r\nimport { ElementNames } from '@shared/Constants';\r\nimport {\r\n    ComparisonElementDescriptionModel,\r\n    ComparisonElementGroupModel,\r\n    ComparisonElementModel,\r\n    ComparisonElementsModel,\r\n    ComparisonQuoteModel,\r\n    ComparisonQuotesModel,\r\n    QuoteCreateRequestModel,\r\n    QuotePremiumErrorModel,\r\n} from '@shared/Models';\r\nimport { asNumber, isNumeric } from '..';\r\n\r\n/** Returns the comparison quote with the given quote ID, or undefined if the quote ID is not found. */\r\nexport function getComparisonQuoteOrDefault(comparisonModel: ComparisonQuotesModel, quoteId: string) {\r\n    return comparisonModel.Quotes.find(({ QuoteId }) => QuoteId === quoteId);\r\n}\r\n\r\n/** Returns a list of comparison elements which are in the given element group. */\r\nexport function getComparisonElementsByConfirmationElementNames(\r\n    comparisonElementGroups: ComparisonElementGroupModel[],\r\n    confirmationElementNames: string[] | undefined,\r\n    quoteId: string\r\n) {\r\n    if (!confirmationElementNames) {\r\n        return [];\r\n    }\r\n\r\n    const confirmationComparisonElementsList = comparisonElementGroups.flatMap(\r\n        elementGroup => elementGroup.ComparisonElements\r\n    );\r\n    const confirmationComparisonElements = confirmationComparisonElementsList.filter(comparisonElements =>\r\n        comparisonElements.Elements.some(\r\n            element => element.QuoteId === quoteId && confirmationElementNames.includes(element.ElementName)\r\n        )\r\n    );\r\n    return confirmationComparisonElements;\r\n}\r\n\r\n/** Returns the comparison element for the given quoteId. */\r\nexport function getComparisonElementByQuoteId(comparisonElements: ComparisonElementsModel, quoteId: string) {\r\n    return comparisonElements.Elements.find(({ QuoteId }) => QuoteId === quoteId);\r\n}\r\n\r\n/** Returns the list of quote element descriptions for the given carrier code. */\r\nexport function getElementDescriptionByCarrierCode(\r\n    elementDescriptions: ComparisonElementDescriptionModel[],\r\n    carrierCode: string\r\n) {\r\n    return elementDescriptions.find(elementDescription => elementDescription.carrierCode === carrierCode)?.descriptions;\r\n}\r\n\r\n/** Returns a QuotePremiumError object with an error message if the given comparisonElement has a null or empty value. */\r\nexport function getConfirmationElementValidationError(comparisonElement: ComparisonElementModel, displayName: string) {\r\n    if (!comparisonElement.Value) {\r\n        const errorMessage = `${displayName} requires an answer to bind.`;\r\n        return {\r\n            ElementName: comparisonElement.ElementName,\r\n            Header: displayName,\r\n            Message: errorMessage,\r\n        } as QuotePremiumErrorModel;\r\n    }\r\n\r\n    return undefined;\r\n}\r\n\r\n/** Returns the correct url to navigate to a quote with based on the ProductLine, if it has alternate quotes, and if it is purchased or not. */\r\nexport function getQuoteUrl(\r\n    quoteId: string,\r\n    productLine: ProductLine,\r\n    alternateQuoteCount: number = 0,\r\n    isPurchasedQuote: boolean = false,\r\n    newQuotePageForCommercialEnabled: boolean = false\r\n) {\r\n    // Commercial quotes use an entirely separate flow for now\r\n    if (productLine === ProductLine.Commercial && !newQuotePageForCommercialEnabled) {\r\n        return `/commercial/quoteModify?quoteId=${quoteId}`;\r\n    }\r\n\r\n    const path = getQuotePath(alternateQuoteCount + 1, isPurchasedQuote);\r\n    return getPath(path, { quoteId, product: productLine.lowercaseName });\r\n}\r\n\r\n/** Returns the ComparisonElementModel by the ElementName and QuoteId */\r\nexport function getComparisonElementFromComparisonModel(\r\n    comparisonModel: ComparisonQuotesModel,\r\n    elementName: string,\r\n    quoteId: string\r\n): ComparisonElementModel | null {\r\n    const { ElementGroups } = comparisonModel;\r\n    const elementGroups = ElementGroups.find(({ ComparisonElements }) =>\r\n        ComparisonElements.some(({ Elements }) => Elements.some(({ ElementName }) => ElementName === elementName))\r\n    );\r\n\r\n    if (!elementGroups) {\r\n        return null;\r\n    }\r\n\r\n    const { ComparisonElements } = elementGroups;\r\n    if (!ComparisonElements) {\r\n        return null;\r\n    }\r\n\r\n    const elements = ComparisonElements.find(({ Elements }) =>\r\n        Elements.some(({ ElementName }) => ElementName === elementName)\r\n    );\r\n\r\n    if (!elements) {\r\n        return null;\r\n    }\r\n\r\n    const { Elements } = elements;\r\n    if (!Elements) {\r\n        return null;\r\n    }\r\n\r\n    return Elements.find(({ ElementName, QuoteId }) => ElementName === elementName && QuoteId === quoteId) || null;\r\n}\r\n\r\nexport function createHardCodedElement(quoteId: string, elementDisplay: string, elementName: string, value: string) {\r\n    return {\r\n        ElementDisplay: elementDisplay,\r\n        Elements: [\r\n            {\r\n                ElementName: elementName,\r\n                Value: value,\r\n                QuoteId: quoteId,\r\n            } as ComparisonElementModel,\r\n        ],\r\n    } as ComparisonElementsModel;\r\n}\r\n\r\nexport function hasElementWithName(comparisonElements: ComparisonElementsModel, elementName: string) {\r\n    const element = comparisonElements.Elements.find(el => el.ElementName === elementName);\r\n    return !!element;\r\n}\r\n\r\nexport function getElementGroupByNameOrDefault(comparisonModel: ComparisonQuotesModel, groupName: string) {\r\n    return comparisonModel.ElementGroups.find(group => group.ElementGroupName === groupName) || null;\r\n}\r\n\r\nexport function getElementGroupByName(comparisonModel: ComparisonQuotesModel, groupName: string) {\r\n    const group = getElementGroupByNameOrDefault(comparisonModel, groupName);\r\n    if (!group) {\r\n        throw new Error('Element group was not found');\r\n    }\r\n\r\n    return group;\r\n}\r\n\r\n/** @param fromHomeowner Set this to true if fetching flood quotes from the homeowner quote page. */\r\nexport function getCreateQuoteRequestWithPropertyConfirmations(\r\n    comparisonModel: ComparisonQuotesModel,\r\n    quote: ComparisonQuoteModel,\r\n    quoteId: string,\r\n    fromHomeowner: boolean = false\r\n) {\r\n    const request = {\r\n        AddressKey: comparisonModel.QuoteProperty?.AddressKey,\r\n        Address: comparisonModel.QuoteProperty?.FullAddress,\r\n        NonSingleFamilyResidenceConfirmed: true,\r\n        RatingType: quote.RatingType,\r\n        InsuredNameFirst: quote.InsuredNameFirst,\r\n        InsuredNameMiddle: quote.InsuredNameMiddle,\r\n        InsuredNameLast: quote.InsuredNameLast,\r\n        FromHomeowner: fromHomeowner,\r\n    } as QuoteCreateRequestModel;\r\n\r\n    const roofAgeInstance = getComparisonElementFromComparisonModel(comparisonModel, ElementNames.roofAge, quoteId);\r\n    if (roofAgeInstance) {\r\n        request.RoofAge = parseFloat(roofAgeInstance?.DefaultValue || '0');\r\n    }\r\n\r\n    const yearBuiltInstance = getComparisonElementFromComparisonModel(comparisonModel, ElementNames.yearBuilt, quoteId);\r\n    if (yearBuiltInstance) {\r\n        request.YearBuilt = parseFloat(yearBuiltInstance?.DefaultValue || '0');\r\n    }\r\n\r\n    if (!comparisonModel.QuoteProperty?.LivingSpace) {\r\n        const livingSpaceElement = getComparisonElementFromComparisonModel(\r\n            comparisonModel,\r\n            ElementNames.livingSpace,\r\n            quoteId\r\n        );\r\n\r\n        if (livingSpaceElement && isNumeric(livingSpaceElement.DefaultValue)) {\r\n            request.LivingSpace = asNumber(livingSpaceElement.DefaultValue);\r\n        }\r\n    }\r\n\r\n    return request;\r\n}\r\n\r\n/** Gets all the comparison quote elements matching the provided element name (not display name) for all the quotes in a comparison quote model. */\r\nexport function getComparisonQuoteElementsByElementName(comparisonModel: ComparisonQuotesModel, elementName: string) {\r\n    const groupWithElement = comparisonModel.ElementGroups.find(({ ComparisonElements }) =>\r\n        ComparisonElements.some(({ Elements }) => Elements.some(({ ElementName }) => ElementName === elementName))\r\n    );\r\n    if (!groupWithElement?.ComparisonElements) return null;\r\n\r\n    const comparisonElements = groupWithElement.ComparisonElements.find(({ Elements }) =>\r\n        Elements.some(({ ElementName }) => ElementName === elementName)\r\n    );\r\n    return comparisonElements;\r\n}\r\n","!function(e,n){\"object\"==typeof exports&&\"undefined\"!=typeof module?module.exports=n():\"function\"==typeof define&&define.amd?define(n):(e=\"undefined\"!=typeof globalThis?globalThis:e||self).dayjs_plugin_minMax=n()}(this,(function(){\"use strict\";return function(e,n,t){var i=function(e,n){if(!n||!n.length||1===n.length&&!n[0]||1===n.length&&Array.isArray(n[0])&&!n[0].length)return null;var t;1===n.length&&n[0].length>0&&(n=n[0]);t=(n=n.filter((function(e){return e})))[0];for(var i=1;i<n.length;i+=1)n[i].isValid()&&!n[i][e](t)||(t=n[i]);return t};t.max=function(){var e=[].slice.call(arguments,0);return i(\"isAfter\",e)},t.min=function(){var e=[].slice.call(arguments,0);return i(\"isBefore\",e)}}}));"],"names":["getComparisonQuoteOrDefault","comparisonModel","quoteId","QuoteId","getComparisonElementsByConfirmationElementNames","comparisonElementGroups","confirmationElementNames","elementGroup","comparisonElements","element","getComparisonElementByQuoteId","getElementDescriptionByCarrierCode","elementDescriptions","carrierCode","_a","elementDescription","getConfirmationElementValidationError","comparisonElement","displayName","errorMessage","getQuoteUrl","productLine","alternateQuoteCount","isPurchasedQuote","newQuotePageForCommercialEnabled","ProductLine","path","getQuotePath","getPath","getComparisonElementFromComparisonModel","elementName","ElementGroups","elementGroups","ComparisonElements","Elements","ElementName","elements","createHardCodedElement","elementDisplay","value","hasElementWithName","el","getElementGroupByNameOrDefault","groupName","group","getElementGroupByName","getCreateQuoteRequestWithPropertyConfirmations","quote","fromHomeowner","request","_b","roofAgeInstance","ElementNames","yearBuiltInstance","_c","livingSpaceElement","isNumeric","asNumber","getComparisonQuoteElementsByElementName","groupWithElement","e","n","module","this","t","i"],"mappings":"mKAgBgB,SAAAA,EAA4BC,EAAwCC,EAAiB,CAC1F,OAAAD,EAAgB,OAAO,KAAK,CAAC,CAAE,QAAAE,CAAQ,IAAMA,IAAYD,CAAO,CAC3E,CAGgB,SAAAE,EACZC,EACAC,EACAJ,EACF,CACE,OAAKI,EAIsCD,EAAwB,WAC/CE,EAAa,kBACjC,EAC0E,OAAOC,GAC7EA,EAAmB,SAAS,QACbC,EAAQ,UAAYP,GAAWI,EAAyB,SAASG,EAAQ,WAAW,CAAA,CAEvG,EAVW,CAAC,CAYhB,CAGgB,SAAAC,EAA8BF,EAA6CN,EAAiB,CACjG,OAAAM,EAAmB,SAAS,KAAK,CAAC,CAAE,QAAAL,CAAQ,IAA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