var Wick = (window.Wick = window.Wick || {});

function returnErrorCreatePayload() {
    return {
        message: 'Min. characters 5, max. characters 59, only use characters A-Z and 0-9',
    };
}

function returnErrorSelectPayload() {
    return {
        message: 'Something went wrong',
    };
}

function returnSuccessSelectPayload() {
    return {
        currentProjectList: {
            name: 'Loremipsumdolorsitamet,consecteturadipiscingelit,seddoeiusmodtemporincididuntutlaboreetdoloremagnaaliqua.Utenimadminimveniam',
            id: 123,
            link: '/page_my-shopping-list.html',
            isFull: true,
            products: [
                {
                    name: 'BoschPSB1800LI218VLiIonCordlessCombiDrillExamplewithlongtitleintworaws',
                    image: '//media.wickes.co.uk/is/image/wickes/B3182_221100_00?$largeNormal$&defaultImage=wickes/2018-Wickes-Missing-Product-650x650',
                    itemTotal: '£2.00',
                    itemTotalExcVat: '£1.99',
                    quantity: 1,
                },
                {
                    name: 'Bosch PSB 1800 LI-2 18V Li-Ion Cordless Combi Drill Example with long title in two raws',
                    image: '//media.wickes.co.uk/is/image/wickes/B3182_224661_00?$largeNormal$&defaultImage=wickes/2018-Wickes-Missing-Product-650x650',
                    itemTotal: '£1.00',
                    itemTotalExcVat: '£1.99',
                    quantity: 2,
                },
                {
                    name: 'Bosch PSB 1800 LI-2 18V Li-Ion Cordless Combi Drill Example with long title in two raws',
                    image: '//media.wickes.co.uk/is/image/wickes/M3549_144650_00?$largeNormal$&defaultImage=wickes/2018-Wickes-Missing-Product-650x650',
                    itemTotal: '£3.00',
                    itemTotalExcVat: '£1.99',
                    quantity: 3,
                },
                {
                    name: 'Bosch PSB 1800 LI-2 18V Li-Ion Cordless Combi Drill Example with long title in two raws',
                    image: '//media.wickes.co.uk/is/image/wickes/R1478_131881_00?$largeNormal$&defaultImage=wickes/2018-Wickes-Missing-Product-650x650',
                    itemTotal: '£3.00',
                    itemTotalExcVat: '£1.99',
                    quantity: 3,
                },
                {
                    name: 'Bosch PSB 1800 LI-2 18V Li-Ion Cordless Combi Drill Example with long title in two raws',
                    image: '//media.wickes.co.uk/is/image/wickes/B3182_154100_00?$largeNormal$&defaultImage=wickes/2018-Wickes-Missing-Product-650x650',
                    itemTotal: '£3.00',
                    itemTotalExcVat: '£1.99',
                    quantity: 3,
                },
                {
                    name: 'Bosch PSB 1800 LI-2 18V Li-Ion Cordless Combi Drill Example with long title in two raws',
                    image: '//media.wickes.co.uk/is/image/wickes/R1478_131882_00?$largeNormal$&defaultImage=wickes/2018-Wickes-Missing-Product-650x650',
                    itemTotal: '£3.00',
                    itemTotalExcVat: '£1.99',
                    quantity: 3,
                },
                {
                    name: 'Bosch PSB 1800 LI-2 18V Li-Ion Cordless Combi Drill Example with long title in two raws',
                    image: '//media.wickes.co.uk/is/image/wickes/T3274_103040_00?$largeNormal$&defaultImage=wickes/2018-Wickes-Missing-Product-650x650',
                    itemTotal: '£3.00',
                    itemTotalExcVat: '£1.99',
                    quantity: 3,
                },
                {
                    name: 'Bosch PSB 1800 LI-2 18V Li-Ion Cordless Combi Drill Example with long title in two raws',
                    image: '//media.wickes.co.uk/is/image/wickes/T3274_103015_00?$largeNormal$&defaultImage=wickes/2018-Wickes-Missing-Product-650x650',
                    itemTotal: '£3.00',
                    itemTotalExcVat: '£1.99',
                    quantity: 3,
                },
                {
                    name: 'Bosch PSB 1800 LI-2 18V Li-Ion Cordless Combi Drill Example with long title in two raws',
                    image: '//media.wickes.co.uk/is/image/wickes/T3274_103043_00?$largeNormal$&defaultImage=wickes/2018-Wickes-Missing-Product-650x650',
                    itemTotal: '£3.00',
                    itemTotalExcVat: '£1.99',
                    quantity: 3,
                },
                {
                    name: 'Bosch PSB 1800 LI-2 18V Li-Ion Cordless Combi Drill Example with long title in two raws',
                    image: '//media.wickes.co.uk/is/image/wickes/O0032_109450_00?$largeNormal$&defaultImage=wickes/2018-Wickes-Missing-Product-650x650',
                    itemTotal: '£3.00',
                    itemTotalExcVat: '£1.99',
                    quantity: 3,
                },
                {
                    name: 'Bosch PSB 1800 LI-2 18V Li-Ion Cordless Combi Drill Example with long title in two raws',
                    image: '//media.wickes.co.uk/is/image/wickes/O0032_109451_00?$largeNormal$&defaultImage=wickes/2018-Wickes-Missing-Product-650x650',
                    itemTotal: '£3.00',
                    itemTotalExcVat: '£1.99',
                    quantity: 3,
                },
                {
                    name: 'Bosch PSB 1800 LI-2 18V Li-Ion Cordless Combi Drill Example with long title in two raws',
                    image: '//media.wickes.co.uk/is/image/wickes/GPID_5000030119_00?$largeNormal$&defaultImage=wickes/2018-Wickes-Missing-Product-650x650',
                    itemTotal: '£3.00',
                    itemTotalExcVat: '£1.99',
                    quantity: 3,
                },
                {
                    name: 'Bosch PSB 1800 LI-2 18V Li-Ion Cordless Combi Drill Example with long title in two raws',
                    image: '//media.wickes.co.uk/is/image/wickes/X0041_165857_00?$largeNormal$&defaultImage=wickes/2018-Wickes-Missing-Product-650x650',
                    itemTotal: '£3.00',
                    itemTotalExcVat: '£1.99',
                    quantity: 3,
                },
                {
                    name: 'Bosch PSB 1800 LI-2 18V Li-Ion Cordless Combi Drill Example with long title in two raws',
                    image: '//media.wickes.co.uk/is/image/wickes/R0486_180900_00?$largeNormal$&defaultImage=wickes/2018-Wickes-Missing-Product-650x650',
                    itemTotal: '£3.00',
                    itemTotalExcVat: '£1.99',
                    quantity: 3,
                },
            ],
        },
    };
}

function returnSuccessCreatePayload() {
    return {
        currentProjectList: {
            name: 'Loremipsumdolorsitamet,consecteturadipiscingelit,seddoeiusmodtemporincididuntutlaboreetdoloremagnaaliqua.Utenimadminimveniam',
            id: 123,
            link: '/page_my-shopping-list.html',
            isFull: true,
            products: [
                {
                    name: 'BoschPSB1800LI218VLiIonCordlessCombiDrillExamplewithlongtitleintworaws',
                    image: '//media.wickes.co.uk/is/image/wickes/B3182_221100_00?$largeNormal$&defaultImage=wickes/2018-Wickes-Missing-Product-650x650',
                    itemTotal: '£2.00',
                    itemTotalExcVat: '£1.99',
                    quantity: 1,
                },
                {
                    name: 'Bosch PSB 1800 LI-2 18V Li-Ion Cordless Combi Drill Example with long title in two raws',
                    image: '//media.wickes.co.uk/is/image/wickes/B3182_224661_00?$largeNormal$&defaultImage=wickes/2018-Wickes-Missing-Product-650x650',
                    itemTotal: '£1.00',
                    itemTotalExcVat: '£1.99',
                    quantity: 2,
                },
                {
                    name: 'Bosch PSB 1800 LI-2 18V Li-Ion Cordless Combi Drill Example with long title in two raws',
                    image: '//media.wickes.co.uk/is/image/wickes/M3549_144650_00?$largeNormal$&defaultImage=wickes/2018-Wickes-Missing-Product-650x650',
                    itemTotal: '£3.00',
                    itemTotalExcVat: '£1.99',
                    quantity: 3,
                },
                {
                    name: 'Bosch PSB 1800 LI-2 18V Li-Ion Cordless Combi Drill Example with long title in two raws',
                    image: '//media.wickes.co.uk/is/image/wickes/R1478_131881_00?$largeNormal$&defaultImage=wickes/2018-Wickes-Missing-Product-650x650',
                    itemTotal: '£3.00',
                    itemTotalExcVat: '£1.99',
                    quantity: 3,
                },
                {
                    name: 'Bosch PSB 1800 LI-2 18V Li-Ion Cordless Combi Drill Example with long title in two raws',
                    image: '//media.wickes.co.uk/is/image/wickes/B3182_154100_00?$largeNormal$&defaultImage=wickes/2018-Wickes-Missing-Product-650x650',
                    itemTotal: '£3.00',
                    itemTotalExcVat: '£1.99',
                    quantity: 3,
                },
                {
                    name: 'Bosch PSB 1800 LI-2 18V Li-Ion Cordless Combi Drill Example with long title in two raws',
                    image: '//media.wickes.co.uk/is/image/wickes/R1478_131882_00?$largeNormal$&defaultImage=wickes/2018-Wickes-Missing-Product-650x650',
                    itemTotal: '£3.00',
                    itemTotalExcVat: '£1.99',
                    quantity: 3,
                },
                {
                    name: 'Bosch PSB 1800 LI-2 18V Li-Ion Cordless Combi Drill Example with long title in two raws',
                    image: '//media.wickes.co.uk/is/image/wickes/T3274_103040_00?$largeNormal$&defaultImage=wickes/2018-Wickes-Missing-Product-650x650',
                    itemTotal: '£3.00',
                    itemTotalExcVat: '£1.99',
                    quantity: 3,
                },
                {
                    name: 'Bosch PSB 1800 LI-2 18V Li-Ion Cordless Combi Drill Example with long title in two raws',
                    image: '//media.wickes.co.uk/is/image/wickes/T3274_103015_00?$largeNormal$&defaultImage=wickes/2018-Wickes-Missing-Product-650x650',
                    itemTotal: '£3.00',
                    itemTotalExcVat: '£1.99',
                    quantity: 3,
                },
                {
                    name: 'Bosch PSB 1800 LI-2 18V Li-Ion Cordless Combi Drill Example with long title in two raws',
                    image: '//media.wickes.co.uk/is/image/wickes/T3274_103043_00?$largeNormal$&defaultImage=wickes/2018-Wickes-Missing-Product-650x650',
                    itemTotal: '£3.00',
                    itemTotalExcVat: '£1.99',
                    quantity: 3,
                },
                {
                    name: 'Bosch PSB 1800 LI-2 18V Li-Ion Cordless Combi Drill Example with long title in two raws',
                    image: '//media.wickes.co.uk/is/image/wickes/O0032_109450_00?$largeNormal$&defaultImage=wickes/2018-Wickes-Missing-Product-650x650',
                    itemTotal: '£3.00',
                    itemTotalExcVat: '£1.99',
                    quantity: 3,
                },
                {
                    name: 'Bosch PSB 1800 LI-2 18V Li-Ion Cordless Combi Drill Example with long title in two raws',
                    image: '//media.wickes.co.uk/is/image/wickes/O0032_109451_00?$largeNormal$&defaultImage=wickes/2018-Wickes-Missing-Product-650x650',
                    itemTotal: '£3.00',
                    itemTotalExcVat: '£1.99',
                    quantity: 3,
                },
                {
                    name: 'Bosch PSB 1800 LI-2 18V Li-Ion Cordless Combi Drill Example with long title in two raws',
                    image: '//media.wickes.co.uk/is/image/wickes/GPID_5000030119_00?$largeNormal$&defaultImage=wickes/2018-Wickes-Missing-Product-650x650',
                    itemTotal: '£3.00',
                    itemTotalExcVat: '£1.99',
                    quantity: 3,
                },
                {
                    name: 'Bosch PSB 1800 LI-2 18V Li-Ion Cordless Combi Drill Example with long title in two raws',
                    image: '//media.wickes.co.uk/is/image/wickes/X0041_165857_00?$largeNormal$&defaultImage=wickes/2018-Wickes-Missing-Product-650x650',
                    itemTotal: '£3.00',
                    itemTotalExcVat: '£1.99',
                    quantity: 3,
                },
                {
                    name: 'Bosch PSB 1800 LI-2 18V Li-Ion Cordless Combi Drill Example with long title in two raws',
                    image: '//media.wickes.co.uk/is/image/wickes/R0486_180900_00?$largeNormal$&defaultImage=wickes/2018-Wickes-Missing-Product-650x650',
                    itemTotal: '£3.00',
                    itemTotalExcVat: '£1.99',
                    quantity: 3,
                },
            ],
        },
        projectListLength: 10,
        maxAmountOfProjects: 2,
    };
}

function returnSuccessGetPayload(currentPage) {
    return {
        currentPage: currentPage,
        pagesLength: 101,
        projectLists: [
            {
                name: `Bathroom ${currentPage}`,
                id: 'bathroom',
                isFull: true,
            },
            {
                name: `Dining room ${currentPage}`,
                id: 'dining-room',
                isFull: false,
            },
            {
                name: `Driveway ${currentPage}`,
                id: 'driveway',
                isFull: false,
            },
            {
                name: `Floors ${currentPage}`,
                id: 'floors',
                isFull: false,
            },
            {
                name: `Garage ${currentPage}`,
                id: 'garage',
                isFull: true,
            },
            {
                name: `Garden ${currentPage}`,
                id: 'garden',
                isFull: false,
            },
            {
                name: `Garden shed ${currentPage}`,
                id: 'garden-shed',
                isFull: false,
            },
            {
                name: `Gym ${currentPage}`,
                id: 'gym',
                isFull: false,
            },
            {
                name: `Kids room ${currentPage}`,
                id: 'kids-room',
                isFull: false,
            },
            {
                name: `Kitchen update ${currentPage}`,
                id: 'kitchen-update',
                isFull: false,
            },
            {
                name: `Living room ${currentPage}`,
                id: 'living-room',
                isFull: false,
            },
            {
                name: `Paint ${currentPage}`,
                id: 'paint',
                isFull: true,
            },
        ],
    };
}

$(document).ready(function () {
    function init() {
        if (!$('.shop-list-modal').length || !Wick.SavingShoppingList) {
            return;
        }
        $(Wick.SavingShoppingList?.el.modalSavingToShopList).on(
            'show.bs.modal',
            Wick.SavingShoppingList.init
        );
        $(window).on(Wick.SavingShoppingList.CREATE_PROJECT_LIST_EVENT, function (e) {
            setTimeout(() => {
                e.detail.payload.projectListName.length >= 5
                    ? e.detail.resolve(returnSuccessCreatePayload())
                    : e.detail.reject(returnErrorCreatePayload());
            }, 1000);
        });
        $(window).on(Wick.SavingShoppingList.SELECT_PROJECT_LIST_EVENT, function (e) {
            setTimeout(() => {
                e.detail.payload.projectListId === 'dining-room'
                    ? e.detail.reject(returnErrorSelectPayload())
                    : e.detail.resolve(returnSuccessSelectPayload());
            }, 1000);
        });
        $(window).on(Wick.SavingShoppingList.GET_PROJECT_LISTS_EVENT, function (e) {
            setTimeout(() => {
                e.detail.payload.page === 4
                    ? e.detail.reject(returnErrorSelectPayload())
                    : e.detail.resolve(returnSuccessGetPayload(e.detail.payload.page));
            }, 1000);
        });
    }

    init();
});
