"use strict";
(() => {
var exports = {};
exports.id = 1715;
exports.ids = [1715];
exports.modules = {

/***/ 4159:
/***/ ((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": () => (__WEBPACK_DEFAULT_EXPORT__),
/* harmony export */   "getServerSideProps": () => (/* binding */ getServerSideProps)
/* harmony export */ });
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(997);
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _components_layout_dashboard__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(4047);
/* harmony import */ var _components_layout_content__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(9413);
/* harmony import */ var cookies__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(640);
/* harmony import */ var cookies__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(cookies__WEBPACK_IMPORTED_MODULE_3__);
/* harmony import */ var _components_ui_Button__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(5911);
/* harmony import */ var _components_ui_Input__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(9821);
/* harmony import */ var react_toastify__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(3590);
/* harmony import */ var cookie_cutter__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(4957);
/* harmony import */ var cookie_cutter__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(cookie_cutter__WEBPACK_IMPORTED_MODULE_7__);
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(6689);
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_8___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_8__);
/* harmony import */ var _components_ui_DropDown__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(7474);
/* harmony import */ var react_multi_date_picker__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(3456);
/* harmony import */ var react_multi_date_picker__WEBPACK_IMPORTED_MODULE_10___default = /*#__PURE__*/__webpack_require__.n(react_multi_date_picker__WEBPACK_IMPORTED_MODULE_10__);
/* harmony import */ var react_multi_date_picker_plugins_time_picker__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(4371);
/* harmony import */ var react_multi_date_picker_plugins_time_picker__WEBPACK_IMPORTED_MODULE_11___default = /*#__PURE__*/__webpack_require__.n(react_multi_date_picker_plugins_time_picker__WEBPACK_IMPORTED_MODULE_11__);
/* harmony import */ var moment_jalaali__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(100);
/* harmony import */ var moment_jalaali__WEBPACK_IMPORTED_MODULE_12___default = /*#__PURE__*/__webpack_require__.n(moment_jalaali__WEBPACK_IMPORTED_MODULE_12__);
var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_components_layout_dashboard__WEBPACK_IMPORTED_MODULE_1__, react_toastify__WEBPACK_IMPORTED_MODULE_6__]);
([_components_layout_dashboard__WEBPACK_IMPORTED_MODULE_1__, react_toastify__WEBPACK_IMPORTED_MODULE_6__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);













const Edit = ({ status , data , roles , users  })=>{
    const [selectedManager, setSelectedManager] = (0,react__WEBPACK_IMPORTED_MODULE_8__.useState)({
        ...users.filter((e)=>e.id === data.userDetail.manager_id).map((x)=>{
            return {
                value: x.id,
                label: x.userDetail.first_name + " " + x.userDetail.last_name
            };
        })[0]
    });
    const [statusValue, setStatusValue] = (0,react__WEBPACK_IMPORTED_MODULE_8__.useState)({});
    const [roleValue, setRoleValue] = (0,react__WEBPACK_IMPORTED_MODULE_8__.useState)({});
    const [delayTime, setDelayTime] = (0,react__WEBPACK_IMPORTED_MODULE_8__.useState)(new Date(moment_jalaali__WEBPACK_IMPORTED_MODULE_12__().set({
        hour: data.userDetail.delay_time.slice(0, 2),
        minute: data.userDetail.delay_time.slice(3, 5)
    })));
    const handleStatusValue = (e)=>{
        setStatusValue(e);
    };
    const handleRoleValue = (e)=>{
        setRoleValue(e);
    };
    const handleSubmit = async (event)=>{
        event.preventDefault();
        const el = {
            email: event.target.email.value,
            first_name: event.target.first_name.value,
            last_name: event.target.last_name.value,
            phone: event.target.phone.value,
            status: statusValue.value ? statusValue.value : data.status,
            role_id: roleValue.value ? roleValue.value : data.role_id,
            delay_time: new moment_jalaali__WEBPACK_IMPORTED_MODULE_12__(delayTime).format("hh:mm"),
            delay_ratio: event.target.delay_ratio.value,
            vacation_remained: event.target.vacation_remained.value,
            manager_id: selectedManager.value
        };
        const token = cookie_cutter__WEBPACK_IMPORTED_MODULE_7___default().get("token");
        fetch("/api/user/edit/" + data.id, {
            body: JSON.stringify(el),
            method: "POST",
            headers: {
                Authorization: "bearer " + token
            }
        }).then(async (r)=>{
            if (r.status === 200) {
                react_toastify__WEBPACK_IMPORTED_MODULE_6__.toast.success("با موفقیت بروز رسانی شد.");
            } else {
                react_toastify__WEBPACK_IMPORTED_MODULE_6__.toast.error("خظا!");
            }
        });
    };
    const handelSelectManager = (items)=>{
        setSelectedManager(items);
    };
    const InputComponent = ({ openCalendar , value , handleValueChange , label  })=>{
        return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_ui_Input__WEBPACK_IMPORTED_MODULE_5__/* ["default"] */ .Z, {
            label: label,
            id: "time",
            onFocus: openCalendar,
            defaultValue: value,
            onChange: handleValueChange
        });
    };
    const handleChangeTime = (e)=>{
        setDelayTime(new Date(moment_jalaali__WEBPACK_IMPORTED_MODULE_12__().set({
            hour: e.hour,
            minute: e.minute
        })));
    };
    return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_layout_dashboard__WEBPACK_IMPORTED_MODULE_1__/* ["default"] */ .Z, {
        title: "کاربران - ویرایش",
        children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_layout_content__WEBPACK_IMPORTED_MODULE_2__/* ["default"] */ .Z, {
            title: "ویرایش",
            children: /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("form", {
                onSubmit: handleSubmit,
                children: [
                    /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", {
                        className: "grid grid-cols-3 space-x-2 space-x-reverse",
                        children: [
                            /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_ui_Input__WEBPACK_IMPORTED_MODULE_5__/* ["default"] */ .Z, {
                                type: "text",
                                label: "ایمیل",
                                defaultValue: data.email,
                                id: "email",
                                name: "email"
                            }),
                            /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_ui_Input__WEBPACK_IMPORTED_MODULE_5__/* ["default"] */ .Z, {
                                type: "text",
                                label: "نام",
                                defaultValue: data.userDetail.first_name,
                                id: "first_name",
                                name: "first_name"
                            }),
                            /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_ui_Input__WEBPACK_IMPORTED_MODULE_5__/* ["default"] */ .Z, {
                                type: "text",
                                label: "نام خانوادگی",
                                defaultValue: data.userDetail.last_name,
                                id: "last_name",
                                name: "last_name"
                            }),
                            /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_ui_Input__WEBPACK_IMPORTED_MODULE_5__/* ["default"] */ .Z, {
                                type: "text",
                                label: "شماره تماس",
                                defaultValue: data.phone,
                                id: "phone",
                                name: "phone"
                            }),
                            /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx((react_multi_date_picker__WEBPACK_IMPORTED_MODULE_10___default()), {
                                disableDayPicker: true,
                                format: "HH:mm",
                                plugins: [
                                    /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx((react_multi_date_picker_plugins_time_picker__WEBPACK_IMPORTED_MODULE_11___default()), {
                                        hideSeconds: true
                                    }, "")
                                ],
                                render: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(InputComponent, {
                                    label: "زمان تاخیر"
                                }),
                                value: delayTime,
                                onChange: handleChangeTime
                            }),
                            /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_ui_Input__WEBPACK_IMPORTED_MODULE_5__/* ["default"] */ .Z, {
                                type: "number",
                                label: "ضریب تاخیر",
                                defaultValue: data.userDetail.delay_ratio,
                                id: "delay_ratio",
                                name: "delay_ratio"
                            }),
                            /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_ui_Input__WEBPACK_IMPORTED_MODULE_5__/* ["default"] */ .Z, {
                                type: "text",
                                label: "مرخصی باقی مانده",
                                defaultValue: data.userDetail.vacation_remained,
                                id: "vacation_remained",
                                name: "vacation_remained"
                            }),
                            /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_ui_Input__WEBPACK_IMPORTED_MODULE_5__/* ["default"] */ .Z, {
                                type: "text",
                                label: "شماره پرسنلی",
                                defaultValue: data.userDetail.personal_code,
                                id: "personal_code",
                                name: "personal_code",
                                disabled: true
                            }),
                            /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_ui_DropDown__WEBPACK_IMPORTED_MODULE_9__/* ["default"] */ .Z, {
                                id: "manager",
                                dataSet: handelSelectManager,
                                label: "مدیر شخص",
                                defaultValue: data.userDetail.manager_id,
                                options: [
                                    {
                                        value: "null",
                                        label: "بدون مدیر"
                                    },
                                    ...users.map((user)=>{
                                        return {
                                            value: user.id,
                                            label: user.userDetail.first_name + " " + user.userDetail.last_name
                                        };
                                    })
                                ]
                            }),
                            /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_ui_DropDown__WEBPACK_IMPORTED_MODULE_9__/* ["default"] */ .Z, {
                                id: "role_id",
                                label: "نقش",
                                options: roles.map((el)=>{
                                    return {
                                        value: el.id,
                                        label: el.name
                                    };
                                }),
                                defaultValue: data.role_id,
                                dataSet: handleRoleValue
                            }),
                            /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_ui_DropDown__WEBPACK_IMPORTED_MODULE_9__/* ["default"] */ .Z, {
                                id: "status",
                                label: "وضعیت",
                                options: [
                                    {
                                        value: "active",
                                        label: "فعال"
                                    },
                                    {
                                        value: "pending",
                                        label: "در حال بررسی"
                                    },
                                    {
                                        value: "inactive",
                                        label: "غیر فعال"
                                    }
                                ],
                                defaultValue: data.status,
                                dataSet: handleStatusValue
                            })
                        ]
                    }),
                    /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("div", {
                        className: "text-left mt-3",
                        children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_ui_Button__WEBPACK_IMPORTED_MODULE_4__/* ["default"] */ .Z, {
                            type: "submit",
                            label: "بروزرسانی"
                        })
                    })
                ]
            })
        })
    });
};
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Edit);
async function getServerSideProps(context) {
    const { params  } = context;
    const cookies = new (cookies__WEBPACK_IMPORTED_MODULE_3___default())(context.req, context.res);
    const locale = context.locale;
    const token = cookies.get("token");
    if (!token) {
        return {
            redirect: {
                permanent: false,
                destination: "/Login?return=/Manager/Users/Edit/" + params.id
            }
        };
    }
    const roles = await fetch("https://dashboard.iotacademy.ir" + "/api/user/roles", {
        headers: {
            Authorization: "Bearer " + token
        }
    });
    const users = await fetch("https://dashboard.iotacademy.ir" + "/api/user/list", {
        headers: {
            Authorization: "Bearer " + token
        }
    });
    return await fetch("https://dashboard.iotacademy.ir" + "/api/user/" + params.id, {
        headers: {
            Authorization: "Bearer " + token
        }
    }).then(async (data)=>{
        if (data.status === 200) {
            return {
                props: {
                    data: await data.json(),
                    roles: await roles.json(),
                    users: await users.json(),
                    status: data.status
                }
            };
        } else if (data.status === 404) {
            return {
                notFound: true
            };
        } else {
            return {
                props: {
                    data: [],
                    status: data.status
                }
            };
        }
    });
}

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

/***/ }),

/***/ 4957:
/***/ ((module) => {

module.exports = require("cookie-cutter");

/***/ }),

/***/ 640:
/***/ ((module) => {

module.exports = require("cookies");

/***/ }),

/***/ 100:
/***/ ((module) => {

module.exports = require("moment-jalaali");

/***/ }),

/***/ 3918:
/***/ ((module) => {

module.exports = require("next/dist/shared/lib/amp-context.js");

/***/ }),

/***/ 5732:
/***/ ((module) => {

module.exports = require("next/dist/shared/lib/amp-mode.js");

/***/ }),

/***/ 3280:
/***/ ((module) => {

module.exports = require("next/dist/shared/lib/app-router-context.js");

/***/ }),

/***/ 2796:
/***/ ((module) => {

module.exports = require("next/dist/shared/lib/head-manager-context.js");

/***/ }),

/***/ 4014:
/***/ ((module) => {

module.exports = require("next/dist/shared/lib/i18n/normalize-locale-path.js");

/***/ }),

/***/ 4486:
/***/ ((module) => {

module.exports = require("next/dist/shared/lib/image-blur-svg.js");

/***/ }),

/***/ 744:
/***/ ((module) => {

module.exports = require("next/dist/shared/lib/image-config-context.js");

/***/ }),

/***/ 5843:
/***/ ((module) => {

module.exports = require("next/dist/shared/lib/image-config.js");

/***/ }),

/***/ 9552:
/***/ ((module) => {

module.exports = require("next/dist/shared/lib/image-loader");

/***/ }),

/***/ 8524:
/***/ ((module) => {

module.exports = require("next/dist/shared/lib/is-plain-object.js");

/***/ }),

/***/ 8020:
/***/ ((module) => {

module.exports = require("next/dist/shared/lib/mitt.js");

/***/ }),

/***/ 4406:
/***/ ((module) => {

module.exports = require("next/dist/shared/lib/page-path/denormalize-page-path.js");

/***/ }),

/***/ 4964:
/***/ ((module) => {

module.exports = require("next/dist/shared/lib/router-context.js");

/***/ }),

/***/ 1751:
/***/ ((module) => {

module.exports = require("next/dist/shared/lib/router/utils/add-path-prefix.js");

/***/ }),

/***/ 6220:
/***/ ((module) => {

module.exports = require("next/dist/shared/lib/router/utils/compare-states.js");

/***/ }),

/***/ 299:
/***/ ((module) => {

module.exports = require("next/dist/shared/lib/router/utils/format-next-pathname-info.js");

/***/ }),

/***/ 3938:
/***/ ((module) => {

module.exports = require("next/dist/shared/lib/router/utils/format-url.js");

/***/ }),

/***/ 9565:
/***/ ((module) => {

module.exports = require("next/dist/shared/lib/router/utils/get-asset-path-from-route.js");

/***/ }),

/***/ 5789:
/***/ ((module) => {

module.exports = require("next/dist/shared/lib/router/utils/get-next-pathname-info.js");

/***/ }),

/***/ 1897:
/***/ ((module) => {

module.exports = require("next/dist/shared/lib/router/utils/is-bot.js");

/***/ }),

/***/ 1428:
/***/ ((module) => {

module.exports = require("next/dist/shared/lib/router/utils/is-dynamic.js");

/***/ }),

/***/ 8854:
/***/ ((module) => {

module.exports = require("next/dist/shared/lib/router/utils/parse-path.js");

/***/ }),

/***/ 1292:
/***/ ((module) => {

module.exports = require("next/dist/shared/lib/router/utils/parse-relative-url.js");

/***/ }),

/***/ 4567:
/***/ ((module) => {

module.exports = require("next/dist/shared/lib/router/utils/path-has-prefix.js");

/***/ }),

/***/ 979:
/***/ ((module) => {

module.exports = require("next/dist/shared/lib/router/utils/querystring.js");

/***/ }),

/***/ 3297:
/***/ ((module) => {

module.exports = require("next/dist/shared/lib/router/utils/remove-trailing-slash.js");

/***/ }),

/***/ 6052:
/***/ ((module) => {

module.exports = require("next/dist/shared/lib/router/utils/resolve-rewrites.js");

/***/ }),

/***/ 4226:
/***/ ((module) => {

module.exports = require("next/dist/shared/lib/router/utils/route-matcher.js");

/***/ }),

/***/ 5052:
/***/ ((module) => {

module.exports = require("next/dist/shared/lib/router/utils/route-regex.js");

/***/ }),

/***/ 2470:
/***/ ((module) => {

module.exports = require("next/dist/shared/lib/side-effect.js");

/***/ }),

/***/ 9232:
/***/ ((module) => {

module.exports = require("next/dist/shared/lib/utils.js");

/***/ }),

/***/ 618:
/***/ ((module) => {

module.exports = require("next/dist/shared/lib/utils/warn-once.js");

/***/ }),

/***/ 968:
/***/ ((module) => {

module.exports = require("next/head");

/***/ }),

/***/ 1853:
/***/ ((module) => {

module.exports = require("next/router");

/***/ }),

/***/ 6689:
/***/ ((module) => {

module.exports = require("react");

/***/ }),

/***/ 6405:
/***/ ((module) => {

module.exports = require("react-dom");

/***/ }),

/***/ 9847:
/***/ ((module) => {

module.exports = require("react-icons/ai");

/***/ }),

/***/ 6652:
/***/ ((module) => {

module.exports = require("react-icons/bi");

/***/ }),

/***/ 2750:
/***/ ((module) => {

module.exports = require("react-icons/fi");

/***/ }),

/***/ 5856:
/***/ ((module) => {

module.exports = require("react-icons/go");

/***/ }),

/***/ 5452:
/***/ ((module) => {

module.exports = require("react-icons/rx");

/***/ }),

/***/ 3456:
/***/ ((module) => {

module.exports = require("react-multi-date-picker");

/***/ }),

/***/ 4371:
/***/ ((module) => {

module.exports = require("react-multi-date-picker/plugins/time_picker");

/***/ }),

/***/ 1929:
/***/ ((module) => {

module.exports = require("react-select");

/***/ }),

/***/ 997:
/***/ ((module) => {

module.exports = require("react/jsx-runtime");

/***/ }),

/***/ 3590:
/***/ ((module) => {

module.exports = import("react-toastify");;

/***/ })

};
;

// load runtime
var __webpack_require__ = require("../../../../webpack-runtime.js");
__webpack_require__.C(exports);
var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId))
var __webpack_exports__ = __webpack_require__.X(0, [3121,676,3061,284,6596,9413,873,7474], () => (__webpack_exec__(4159)));
module.exports = __webpack_exports__;

})();