"use strict";
exports.id = 329;
exports.ids = [329];
exports.modules = {

/***/ 1329:
/***/ ((module, __webpack_exports__, __webpack_require__) => {

__webpack_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "default": () => (/* binding */ CouponPage)
/* harmony export */ });
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2322);
/* harmony import */ var _cromwell_core__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1815);
/* harmony import */ var _cromwell_core_frontend__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(4536);
/* harmony import */ var _heroicons_react_24_outline__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(2135);
/* harmony import */ var _heroicons_react_24_outline__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_heroicons_react_24_outline__WEBPACK_IMPORTED_MODULE_3__);
/* harmony import */ var _mui_material__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(5692);
/* harmony import */ var _mui_material__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_mui_material__WEBPACK_IMPORTED_MODULE_4__);
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(6689);
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_5__);
/* harmony import */ var _components_buttons_IconButton__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(4137);
/* harmony import */ var _components_entity_entityEdit_EntityEdit__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(4342);
/* harmony import */ var _components_inputs_Search_SearchInput__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(9376);
/* harmony import */ var _components_inputs_TextInput_TextInput__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(2032);
/* harmony import */ var _components_loadBox_LoadBox__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(8596);
/* harmony import */ var _constants_PageInfos__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(379);
var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_components_entity_entityEdit_EntityEdit__WEBPACK_IMPORTED_MODULE_7__, _components_inputs_Search_SearchInput__WEBPACK_IMPORTED_MODULE_8__]);
([_components_entity_entityEdit_EntityEdit__WEBPACK_IMPORTED_MODULE_7__, _components_inputs_Search_SearchInput__WEBPACK_IMPORTED_MODULE_8__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);












function CouponPage() {
    const client = (0,_cromwell_core_frontend__WEBPACK_IMPORTED_MODULE_2__.getGraphQLClient)();
    return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_entity_entityEdit_EntityEdit__WEBPACK_IMPORTED_MODULE_7__/* ["default"] */ .Z, {
        entityCategory: _cromwell_core__WEBPACK_IMPORTED_MODULE_1__.EDBEntity.Coupon,
        entityListRoute: _constants_PageInfos__WEBPACK_IMPORTED_MODULE_11__/* .couponListPageInfo.route */ .KY.route,
        entityBaseRoute: _constants_PageInfos__WEBPACK_IMPORTED_MODULE_11__/* .couponPageInfo.baseRoute */ .F7.baseRoute,
        listLabel: "Coupons",
        entityLabel: "Coupon",
        disableMeta: true,
        getById: client.getCouponById,
        update: client.updateCoupon,
        create: client.createCoupon,
        deleteOne: client.deleteCoupon,
        fields: [
            {
                key: "code",
                type: "custom",
                label: "Code",
                required: true,
                width: {
                    sm: 6
                },
                component: ({ value , onChange , canValidate , error  })=>{
                    const handleGenerateCode = ()=>{
                        onChange((0,_cromwell_core__WEBPACK_IMPORTED_MODULE_1__.getRandStr)(8).toUpperCase());
                    };
                    return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_inputs_TextInput_TextInput__WEBPACK_IMPORTED_MODULE_9__/* .TextInput */ .o, {
                        label: "Code",
                        value: value || "",
                        onChange: (e)=>{
                            onChange(e.target.value);
                        },
                        error: canValidate && error,
                        endAdornment: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("div", {
                            className: "flex items-center",
                            children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_mui_material__WEBPACK_IMPORTED_MODULE_4__.Tooltip, {
                                title: "Generate code",
                                children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_buttons_IconButton__WEBPACK_IMPORTED_MODULE_6__/* .IconButton */ .h, {
                                    "aria-label": "Generate code",
                                    onClick: handleGenerateCode,
                                    children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_heroicons_react_24_outline__WEBPACK_IMPORTED_MODULE_3__.SparklesIcon, {
                                        className: "w-5 h-5"
                                    })
                                })
                            })
                        })
                    });
                }
            },
            {
                key: "discountType",
                type: "Select",
                label: "Discount type",
                width: {
                    sm: 6
                },
                // getInitialValue: (value) => value ?? 'fixed',
                options: [
                    {
                        value: "fixed",
                        label: "Fixed"
                    },
                    {
                        value: "percentage",
                        label: "Percentage"
                    }
                ],
                required: true
            },
            {
                key: "value",
                type: "Simple text",
                simpleTextType: "float",
                label: "Discount value",
                width: {
                    sm: 6
                },
                required: true
            },
            {
                key: "description",
                type: "Simple text",
                label: "Description",
                simpleTextType: "textarea",
                width: {
                    sm: 6
                }
            },
            {
                key: "minimumSpend",
                type: "Currency",
                label: "Cart total minimum",
                width: {
                    sm: 6
                }
            },
            {
                key: "maximumSpend",
                type: "Currency",
                label: "Cart total maximum",
                width: {
                    sm: 6
                }
            },
            {
                key: "expiryDate",
                type: "Datetime",
                label: "Expiry date",
                width: {
                    sm: 6
                }
            },
            {
                key: "usageLimit",
                type: "Simple text",
                simpleTextType: "integer",
                label: "Usage limit",
                width: {
                    sm: 6
                }
            },
            {
                key: "categoryIds",
                type: "custom",
                component: ({ value , onChange  })=>{
                    const categoryIds = value;
                    const [pickedCategories, setPickedCategories] = (0,react__WEBPACK_IMPORTED_MODULE_5__.useState)(null);
                    const handleSearchCategory = async (text, params)=>{
                        return client?.getProductCategories({
                            filterParams: {
                                nameSearch: text
                            },
                            pagedParams: params
                        });
                    };
                    const init = async ()=>{
                        if (categoryIds?.length) {
                            const categories = await Promise.all(categoryIds.map(async (id)=>{
                                try {
                                    return await client.getProductCategoryById(Number(id));
                                } catch (error) {
                                    console.error(error);
                                }
                            }));
                            setPickedCategories(categories ?? []);
                        } else setPickedCategories([]);
                    };
                    (0,react__WEBPACK_IMPORTED_MODULE_5__.useEffect)(()=>{
                        init();
                    }, []);
                    return pickedCategories ? /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_inputs_Search_SearchInput__WEBPACK_IMPORTED_MODULE_8__/* .SearchInput */ .M, {
                        multiple: true,
                        style: {
                            margin: "10px 0"
                        },
                        loader: handleSearchCategory,
                        onSelect: (data)=>{
                            if (!data?.length) onChange(null);
                            else onChange(data.map((cat)=>cat.id));
                        },
                        getOptionLabel: (data)=>`${data.name} (id: ${data.id}${data?.parent?.id ? `; parent id: ${data.parent.id}` : ""})`,
                        getOptionValue: (data)=>data.name,
                        fullWidth: true,
                        defaultValue: pickedCategories,
                        label: "Categories"
                    }) : /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_loadBox_LoadBox__WEBPACK_IMPORTED_MODULE_10__/* ["default"] */ .Z, {
                        size: 30
                    });
                }
            },
            {
                key: "productIds",
                type: "custom",
                component: ({ value , onChange  })=>{
                    const productIds = value;
                    const [pickedProducts, setPickedProducts] = (0,react__WEBPACK_IMPORTED_MODULE_5__.useState)(null);
                    const handleSearchProduct = async (text, params)=>{
                        return client?.getProducts({
                            filterParams: {
                                nameSearch: text
                            },
                            pagedParams: params
                        });
                    };
                    const init = async ()=>{
                        if (productIds?.length) {
                            const products = await Promise.all(productIds.map(async (id)=>{
                                try {
                                    return await client.getProductById(Number(id));
                                } catch (error) {
                                    console.error(error);
                                }
                            }));
                            setPickedProducts(products ?? []);
                        } else setPickedProducts([]);
                    };
                    (0,react__WEBPACK_IMPORTED_MODULE_5__.useEffect)(()=>{
                        init();
                    }, []);
                    return pickedProducts ? /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_inputs_Search_SearchInput__WEBPACK_IMPORTED_MODULE_8__/* .SearchInput */ .M, {
                        multiple: true,
                        style: {
                            margin: "10px 0"
                        },
                        loader: handleSearchProduct,
                        onSelect: (data)=>{
                            if (!data?.length) onChange(null);
                            else onChange(data.map((cat)=>cat.id));
                        },
                        getOptionLabel: (data)=>`${data.name} (id: ${data.id})`,
                        getOptionValue: (data)=>data.name,
                        fullWidth: true,
                        defaultValue: pickedProducts,
                        label: "Products"
                    }) : /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_loadBox_LoadBox__WEBPACK_IMPORTED_MODULE_10__/* ["default"] */ .Z, {
                        size: 30
                    });
                }
            }
        ]
    });
}

__webpack_async_result__();
} catch(e) { __webpack_async_result__(e); } });

/***/ })

};
;