export const configuratorMock = {
    enabled: false,
    url: '/en-US/apps/283573/tag-and-track-device/configure',
    selectedEdition: {
        name: 'Tag and track - Monthly edition',
        id: 582927,
        primary: true,
        productEditionRefId: 'f8d6bb58-045a-4678-80e7-c9cd20accee910',
        plans: [
            {
                costs: {
                    unitPrice: [
                        {
                            id: 'UNIT',
                            usageRange: [
                                {
                                    formattedPrice: '$150.00',
                                    formattedFullPrice: '$150.00 / Unit / Month',
                                    formattedFullPriceElements: [
                                        '$150.00',
                                        '/ Unit',
                                        '/ Month'
                                    ],
                                    unit: {
                                        min: 1,
                                        max: null,
                                        label: 'Unit',
                                        dependency: '',
                                        id: 'UNIT',
                                        limitLabel: 'For 1 Unit And Above'
                                    },
                                    frequency: {
                                        shortLabel: 'Mo',
                                        label: 'Month',
                                        id: 'MONTHLY'
                                    },
                                    price: {
                                        symbol: '$',
                                        currency: 'USD',
                                        amount: 150,
                                        value: 150,
                                        originalValue: 150,
                                        discountValue: 0,
                                        editionStartingPrice: 150,
                                        formatted: {
                                            originalPrice: '$150.00',
                                            originalFullPrice: '$150.00 / Unit / Month',
                                            originalFullPriceElements: [
                                                '$150.00',
                                                '/ Unit',
                                                '/ Month'
                                            ],
                                            meteredUsage: 'For 1 Unit And Above'
                                        }
                                    }
                                }
                            ]
                        }
                    ]
                },
                setupFees: [
                    {
                        formattedPrice: '$100.00',
                        formattedFullPrice: '$100.00 Setup fee',
                        formattedFullPriceElements: [
                            '$100.00',
                            'Setup fee',
                            ''
                        ],
                        unit: {
                            min: 0,
                            max: null,
                            label: 'Setup fee',
                            dependency: '',
                            id: 'ONE_TIME_SETUP'
                        },
                        frequency: {
                            shortLabel: '',
                            label: '',
                            id: 'MONTHLY'
                        },
                        price: {
                            symbol: '$',
                            currency: 'USD',
                            amount: 100,
                            value: 100,
                            originalValue: 100,
                            discountValue: 0,
                            editionStartingPrice: 150,
                            formatted: {
                                originalPrice: '$100.00',
                                originalFullPrice: '$100.00 Setup fee',
                                originalFullPriceElements: [
                                    '$100.00',
                                    'Setup fee',
                                    ''
                                ]
                            }
                        }
                    }
                ],
                contractFees: [],
                contractLength: null,
                formattedContract: false,
                discount: false,
                uuid: 'd771928f-3579-4295-883e-149a5e2fc30e'
            }
        ],
        bullets: [],
        callToAction: {
            label: 'Add to Cart',
            tooltip: '',
            isPrimary: true,
            eppid: 'd771928f-3579-4295-883e-149a5e2fc30e',
            enabled: true,
            url: 'https://engage19billing.test.devappdirect.me/api/internal/storefront/v1/cta?productId=283573&type=ADD_TO_CART&editionId=582927&eppid=d771928f-3579-4295-883e-149a5e2fc30e',
            actionType: 'ADD_TO_CART',
            popup: {},
            isSecondary: false
        },
        audience: [],
        items: [
            {
                content: '1 User'
            }
        ],
        invisible: false,
        leadGen: false,
        revenueType: 'RECURRING'
    },
    selectedAddons: [],
    cartItemId: null,
    editionInCartItemId: null,
    isInCart: false,
    backAction: {
        label: 'Back to Tag and Track device',
        url: '/en-US/apps/283573/tag-and-track-device'
    },
    i18n: {
        availableAddons: 'Available Add-ons',
        backTop: 'Back to top',
        changeEdition: 'Change Edition',
        close: 'Close',
        hide: 'Hide',
        hideDetails: 'Hide Details',
        more: 'more',
        selectAddons: 'Add-ons available for selected edition',
        selectEdition: 'Select an edition for this product',
        selectEditionTitle: 'Select an edition for this product',
        selectedAddons: 'Selected Add-on',
        selectedEdition: 'Selected Edition',
        selectedProducts: 'Selected Products',
        startingAt: 'Starting At',
        viewAddons: 'product.configurator.view.addons',
        viewDetails: 'View Details',
        viewEditions: 'product.configurator.view.editions'
    },
    crossSellManagementEnabled: false,
    productId: 283573
};

export const callToActionsMock = {
    items: [
        {
            actionType: 'BUY',
            enabled: true,
            popup: {},
            isPrimary: true,
            label: 'Buy Now',
            tooltip: '',
            url: 'https://engage19billing.test.devappdirect.me/api/internal/storefront/v1/cta?productId=283573&type=BUY&editionId=582927',
            urlCreator: {
                base: 'https://engage19billing.test.devappdirect.me/api/internal/storefront/v1/cta?productId=283573&type=BUY',
                actionType: 'BUY',
                editionParam: 'eppid',
                addonParam: 'appid'
            }
        },
        {
            actionType: 'ADD_TO_CART',
            enabled: true,
            popup: {},
            isPrimary: false,
            label: 'Add to Cart',
            tooltip: '',
            url: 'https://engage19billing.test.devappdirect.me/api/internal/storefront/v1/cta?productId=283573&type=BUY&editionId=582927',
            urlCreator: {
                base: 'https://engage19billing.test.devappdirect.me/api/internal/storefront/v1/cta?productId=283573&type=BUY',
                actionType: 'BUY',
                editionParam: 'eppid',
                addonParam: 'appid'
            },
            windowFunction: 'adAddToCart'
        }
    ]
};

const summaryMock = {
    title: 'Tag and Track device',
    details: 'tracking device',
    overview: 'Tag and Track is a device which a user can attach to any asset which they\nwant to keep a track of, or want to know where it is at any given time. It\nhas a mobile connection, long battery life, and a rugged design.',
    logoSrc: 'https://d33na3ni6eqf5j.cloudfront.net/app_resources/283573/thumbs_112/image3917015750409165591.png',
    logoSrcset: {
        default: 'https://d33na3ni6eqf5j.cloudfront.net/app_resources/283573/thumbs_112/image3917015750409165591.png',
        '2x': 'https://d33na3ni6eqf5j.cloudfront.net/app_resources/283573/thumbs_112/image3917015750409165591-2x.png',
        '1x': 'https://d33na3ni6eqf5j.cloudfront.net/app_resources/283573/thumbs_112/image3917015750409165591.png'
    },
    productRibbon: null,
    merchandisingBadges: []
};

const editionsMock = {
    bullets: [],
    items: [
        {
            name: 'Tag and track - Quarterly edition',
            id: 582924,
            primary: false,
            productEditionRefId: 'f8d6bb58-045a-4678-80e7-c9cd20accee916',
            plans: [
                {
                    costs: {
                        unitPrice: [
                            {
                                id: 'UNIT',
                                usageRange: [
                                    {
                                        formattedPrice: '$330.00',
                                        formattedFullPrice: '$330.00 / Unit / Quarter',
                                        formattedFullPriceElements: [
                                            '$330.00',
                                            '/ Unit',
                                            '/ Quarter'
                                        ],
                                        unit: {
                                            min: 1,
                                            max: null,
                                            label: 'Unit',
                                            dependency: '',
                                            id: 'UNIT',
                                            limitLabel: 'For 1 Unit And Above'
                                        },
                                        frequency: {
                                            shortLabel: 'Qtr',
                                            label: 'Quarter',
                                            id: 'QUARTERLY'
                                        },
                                        price: {
                                            symbol: '$',
                                            currency: 'USD',
                                            amount: 330,
                                            value: 330,
                                            originalValue: 330,
                                            discountValue: 0,
                                            editionStartingPrice: 330,
                                            formatted: {
                                                originalPrice: '$330.00',
                                                originalFullPrice: '$330.00 / Unit / Quarter',
                                                originalFullPriceElements: [
                                                    '$330.00',
                                                    '/ Unit',
                                                    '/ Quarter'
                                                ],
                                                meteredUsage: 'For 1 Unit And Above'
                                            }
                                        }
                                    }
                                ]
                            }
                        ]
                    },
                    setupFees: [
                        {
                            formattedPrice: '$100.00',
                            formattedFullPrice: '$100.00 Setup fee',
                            formattedFullPriceElements: [
                                '$100.00',
                                'Setup fee',
                                ''
                            ],
                            unit: {
                                min: 0,
                                max: null,
                                label: 'Setup fee',
                                dependency: '',
                                id: 'ONE_TIME_SETUP'
                            },
                            frequency: {
                                shortLabel: '',
                                label: '',
                                id: 'QUARTERLY'
                            },
                            price: {
                                symbol: '$',
                                currency: 'USD',
                                amount: 100,
                                value: 100,
                                originalValue: 100,
                                discountValue: 0,
                                editionStartingPrice: 330,
                                formatted: {
                                    originalPrice: '$100.00',
                                    originalFullPrice: '$100.00 Setup fee',
                                    originalFullPriceElements: [
                                        '$100.00',
                                        'Setup fee',
                                        ''
                                    ]
                                }
                            }
                        }
                    ],
                    contractFees: [],
                    contractLength: null,
                    formattedContract: false,
                    discount: false,
                    uuid: '53237150-1704-43bc-934e-81c91140a934'
                }
            ],
            bullets: [],
            callToAction: {
                label: 'Add to Cart',
                tooltip: '',
                isPrimary: false,
                eppid: '53237150-1704-43bc-934e-81c91140a934',
                enabled: true,
                url: 'https://engage19billing.test.devappdirect.me/api/internal/storefront/v1/cta?productId=283573&type=ADD_TO_CART&editionId=582924&eppid=53237150-1704-43bc-934e-81c91140a934',
                actionType: 'ADD_TO_CART',
                popup: {},
                isSecondary: true
            },
            audience: [],
            items: [
                { content: '1 User' },
                { content: 'Unlimited Active Users' },
                { content: 'Unlimited Storage Gigabytes' }
            ],
            invisible: false,
            leadGen: false,
            revenueType: 'RECURRING'
        },
        {
            name: 'Tag and track - Monthly edition',
            id: 582927,
            primary: true,
            productEditionRefId: 'f8d6bb58-045a-4678-80e7-c9cd20accee931',
            plans: [
                {
                    costs: {
                        unitPrice: [
                            {
                                id: 'UNIT',
                                usageRange: [
                                    {
                                        formattedPrice: '$180.00',
                                        formattedFullPrice: '$180.00 / Unit / Month',
                                        formattedFullPriceElements: [
                                            '$180.00',
                                            '/ Unit',
                                            '/ Month'
                                        ],
                                        unit: {
                                            min: 1,
                                            max: null,
                                            label: 'Unit',
                                            dependency: '',
                                            id: 'UNIT',
                                            limitLabel: 'For 1 Unit And Above'
                                        },
                                        frequency: {
                                            shortLabel: 'Mo',
                                            label: 'Month',
                                            id: 'MONTHLY'
                                        },
                                        price: {
                                            symbol: '$',
                                            currency: 'USD',
                                            amount: 180,
                                            value: 180,
                                            originalValue: 180,
                                            discountValue: 0,
                                            editionStartingPrice: 180,
                                            formatted: {
                                                originalPrice: '$180.00',
                                                originalFullPrice: '$180.00 / Unit / Month',
                                                originalFullPriceElements: [
                                                    '$180.00',
                                                    '/ Unit',
                                                    '/ Month'
                                                ],
                                                meteredUsage: 'For 1 Unit And Above'
                                            }
                                        }
                                    }
                                ]
                            }
                        ]
                    },
                    setupFees: [
                        {
                            formattedPrice: '$100.00',
                            formattedFullPrice: '$100.00 Setup fee',
                            formattedFullPriceElements: [
                                '$100.00',
                                'Setup fee',
                                ''
                            ],
                            unit: {
                                min: 0,
                                max: null,
                                label: 'Setup fee',
                                dependency: '',
                                id: 'ONE_TIME_SETUP'
                            },
                            frequency: {
                                shortLabel: '',
                                label: '',
                                id: 'MONTHLY'
                            },
                            price: {
                                symbol: '$',
                                currency: 'USD',
                                amount: 100,
                                value: 100,
                                originalValue: 100,
                                discountValue: 0,
                                editionStartingPrice: 150,
                                formatted: {
                                    originalPrice: '$100.00',
                                    originalFullPrice: '$100.00 Setup fee',
                                    originalFullPriceElements: [
                                        '$100.00',
                                        'Setup fee',
                                        ''
                                    ]
                                }
                            }
                        }
                    ],
                    contractFees: [],
                    contractLength: null,
                    formattedContract: false,
                    discount: false,
                    uuid: 'd771928f-3579-4295-883e-149a5e2fc30e'
                }
            ],
            bullets: [],
            callToAction: {
                label: 'Add to Cart',
                tooltip: '',
                isPrimary: true,
                eppid: 'd771928f-3579-4295-883e-149a5e2fc30e',
                enabled: true,
                url: 'https://engage19billing.test.devappdirect.me/api/internal/storefront/v1/cta?productId=283573&type=ADD_TO_CART&editionId=582927&eppid=d771928f-3579-4295-883e-149a5e2fc30e',
                actionType: 'ADD_TO_CART',
                popup: {},
                isSecondary: false
            },
            audience: [],
            items: [
                {
                    content: '1 User'
                }
            ],
            invisible: false,
            leadGen: false,
            revenueType: 'RECURRING'
        }
    ],
    footnotes: [],
    i18n: {
        bulletsHeader: 'All Plans Include',
        inclusions: 'Included',
        audience: 'Ideal For',
        footnotes: 'Notes',
        invisible: 'Hidden from store customers',
        tierSeparator: 'or',
        setupFee: 'Setup Fee',
        showMoreDetails: 'Show More Info',
        hideMoreDetails: 'Hide',
        mostPopular: 'Most Popular',
        availablePricing: 'Available Pricing:',
        select: 'Select',
        selected: 'Selected',
        hideDetails: 'Hide Details',
        viewDetails: 'View Details'
    }
};

const getProductVariantsInitMock = () => ({
    id: '351ed1a0-3684-11ec-8d3d-0242ac130003',
    version: 'PUBLISHED',
    type: 'PHYSICAL_PRODUCT',
    callToActions: callToActionsMock,
    configurator: configuratorMock,
    editions: editionsMock,
    summary: summaryMock,
    variants: [],
    variantOptions: [{
        code: 'model',
        name: 'Model',
        inputType: 'TEXT',
        values: [
            {
                code: 'iphone-13-mini',
                name: 'iPhone 13 mini',
                secondaryInformation: '5.4-inch display'
            },
            {
                code: 'iphone-13',
                name: 'iPhone 13',
                secondaryInformation: '6.1-inch display'
            }
        ],
        defaultValue: {
            code: 'iphone-13',
            name: 'iPhone 13',
            secondaryInformation: '6.1-inch display'
        }
    },
    {
        code: 'colour',
        name: 'Colour',
        inputType: 'COLOUR',
        values: [
            {
                code: 'pink',
                name: 'Pink',
                hexcode: '#fbe2dd',
                secondaryInformation: ''
            },
            {
                code: 'blue',
                name: 'Blue',
                hexcode: '#437790',
                secondaryInformation: ''
            },
            {
                code: 'midnight',
                name: 'Midnight',
                hexcode: '#42474c',
                secondaryInformation: ''
            },
            {
                code: 'starlight',
                name: 'Starlight',
                hexcode: '#faf7f4',
                secondaryInformation: ''
            },
            {
                code: 'product-red',
                name: 'Red',
                hexcode: '#c72433',
                secondaryInformation: ''
            }
        ],
        defaultValue: {
            code: 'midnight',
            name: 'Midnight',
            hexcode: '#42474c',
            secondaryInformation: ''
        }
    },
    {
        code: 'capacity',
        name: 'Capacity',
        inputType: 'TEXT',
        values: [
            {
                code: '128gb',
                name: '128 GB',
                secondaryInformation: 'The Minimalist Option'
            },
            {
                code: '256gb',
                name: '256 GB',
                secondaryInformation: 'The Pragmatist Option'
            },
            {
                code: '512gb',
                name: '512 GB',
                secondaryInformation: 'The Power User Option'
            }
        ],
        defaultValue: {
            code: '128gb',
            name: '128 GB',
            secondaryInformation: 'The Minimalist Option'
        }
    }]
});

const generateVariantConfigurations = variantOptions => variantOptions
    .reduce((configurations, option) => configurations
        .flatMap(config => option.values.map(value => [
            ...config,
            { optionCode: option.code, valueCode: value.code }
        ])), [[]]);

const getValueCodeForOptionCode = (variantConfig, optionCode) => variantConfig.find(
    config => config.optionCode === optionCode
).valueCode;

const getVariantImages = variantConfig => {
    const model = getValueCodeForOptionCode(variantConfig, 'model');
    const color = getValueCodeForOptionCode(variantConfig, 'colour');
    if (color === 'pink') {
        return [];
    }
    return [
        {
            name: `${model} ${color}`,
            imageUrl: `https://store.storeimages.cdn-apple.com/4982/as-images.apple.com/is/${model}-${color}-select-2021?wid=470&amp;hei=556&amp;fmt=png-alpha&amp;.v=1629842712000`,
            imageUrlSrcset: {
                default: `https://store.storeimages.cdn-apple.com/4982/as-images.apple.com/is/${model}-${color}-select-2021?wid=470&amp;hei=556&amp;fmt=png-alpha&amp;.v=1629842712000`,
                '1x': `https://store.storeimages.cdn-apple.com/4982/as-images.apple.com/is/${model}-${color}-select-2021?wid=470&amp;hei=556&amp;fmt=png-alpha&amp;.v=1629842712000`,
                '2x': `https://store.storeimages.cdn-apple.com/4982/as-images.apple.com/is/${model}-${color}-select-2021?wid=940&amp;hei=1112&amp;fmt=png-alpha&amp;.v=1629842712000`
            }
        }
    ];
};

const getEnabledFlag = variantConfig => {
    const model = getValueCodeForOptionCode(variantConfig, 'model');
    const color = getValueCodeForOptionCode(variantConfig, 'colour');
    return !(model === 'iphone-13' && color === 'product-red');
};

const generateVariants = variantConfigs => variantConfigs.map((variantConfig, index) => ({
    id: `ae2c36ac-604f-468c-904b-5caa25eda8${index + 10}`,
    editionId: `f8d6bb58-045a-4678-80e7-c9cd20accee9${index + 10}`,
    version: 'WORKING',
    configuration: variantConfig,
    price: (989.99 + (index * 10)).toString(),
    images: getVariantImages(variantConfig),
    isEnabled: getEnabledFlag(variantConfig)
}));


const getProductVariantsMock = () => {
    const productVariantsInitMock = getProductVariantsInitMock();
    const variantConfigurations = generateVariantConfigurations(productVariantsInitMock.variantOptions);
    productVariantsInitMock.variants = generateVariants(variantConfigurations);
    return productVariantsInitMock;
};

const getProductVariantsMockWithoutDefaults = () => {
    const productVariantsMock = getProductVariantsMock();
    productVariantsMock.variantOptions = productVariantsMock.variantOptions.map(option => ({
        ...option,
        defaultValue: undefined
    }));
    return productVariantsMock;
};

/*
    The variants array of the productVariantsMock is generated dynamically to avoid
    the hardcoding and maintenance.
*/
export const productVariantsMock = getProductVariantsMock();
export const productVariantsMockWithoutDefaults = getProductVariantsMockWithoutDefaults();
export const disableOption = option => ({
    ...option,
    values: option.values.map(value => ({ ...value, isDisabled: true }))
});

export const variantImages = [
    {
        name: 'iphone 13 blue',
        imageUrl: 'https://store.storeimages.cdn-apple.com/4982/as-images.apple.com/is/iphone-13-blue-select-2021?wid=470&amp;hei=556&amp;fmt=png-alpha&amp;.v=1629842712000',
        imageUrlSrcset: {
            default: 'https://store.storeimages.cdn-apple.com/4982/as-images.apple.com/is/iphone-13-blue-select-2021?wid=470&amp;hei=556&amp;fmt=png-alpha&amp;.v=1629842712000',
            '1x': 'https://store.storeimages.cdn-apple.com/4982/as-images.apple.com/is/iphone-13-blue-select-2021?wid=470&amp;hei=556&amp;fmt=png-alpha&amp;.v=1629842712000',
            '2x': 'https://store.storeimages.cdn-apple.com/4982/as-images.apple.com/is/iphone-13-blue-select-2021?wid=940&amp;hei=1112&amp;fmt=png-alpha&amp;.v=1629842712000'
        }
    }
];

export const selectedOptionsAllValid = [
    { optionName: 'Operating System', optionValue: 'Windows 10 Pro' },
    { optionName: 'Memory', optionValue: '4 GB, 1x4 GB 3200MHz DDR4' },
    { optionName: 'Hard Drive', optionValue: 'M.2 128GB PCIe NVMe Cl…' }
];

export const selectedOptionsNotAllValid = [
    { optionName: 'Operating System', optionValue: 'Windows 10 Pro' },
    { optionName: 'Option null', optionValue: null },
    { optionName: 'Hard Drive', optionValue: 'M.2 128GB PCIe NVMe Cl…' },
    { optionName: 'Option undefined', optionValue: undefined },
    { optionName: 'Option Zero', optionValue: 0 },
    { optionName: 'Option empty string', optionValue: '' }
];

export const selectedOptionsNoneValid = [
    { optionName: 'Option null', optionValue: null },
    { optionName: 'Option undefined', optionValue: undefined },
    { optionName: 'Option empty string', optionValue: '' }
];
