import {ad as w, r as R, j as e, S as L, ae as $, a1 as U, af as v, ac as p, a2 as I, a3 as x, a4 as m, a7 as f, a5 as M, a6 as P, ag as O, t as Q, ah as G, ai as _, s as V, e as b, X as E, aj as A, ak as N, al as z, am as q, an as T, c as H} from "./index-CdMy-Rhi.js"; import {L as F} from "./List-Xt0hH74q.js"; import {s as D} from "./ServicesPage.module-BAnCpO1K.js"; /** * @license @tabler/icons-react v3.21.0 - MIT * * This source code is licensed under the MIT license. * See the LICENSE file in the root directory of this source tree. */ var X = w("outline", "arrow-down", "IconArrowDown", [["path", { d: "M12 5l0 14", key: "svg-0" }], ["path", { d: "M18 13l-6 6", key: "svg-1" }], ["path", { d: "M6 13l6 6", key: "svg-2" }]]); /** * @license @tabler/icons-react v3.21.0 - MIT * * This source code is licensed under the MIT license. * See the LICENSE file in the root directory of this source tree. */ var J = w("outline", "arrow-up", "IconArrowUp", [["path", { d: "M12 5l0 14", key: "svg-0" }], ["path", { d: "M18 11l-6 -6", key: "svg-1" }], ["path", { d: "M6 11l6 -6", key: "svg-2" }]]); /** * @license @tabler/icons-react v3.21.0 - MIT * * This source code is licensed under the MIT license. * See the LICENSE file in the root directory of this source tree. */ var W = w("outline", "download", "IconDownload", [["path", { d: "M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2v-2", key: "svg-0" }], ["path", { d: "M7 11l5 5l5 -5", key: "svg-1" }], ["path", { d: "M12 4l0 12", key: "svg-2" }]]); /** * @license @tabler/icons-react v3.21.0 - MIT * * This source code is licensed under the MIT license. * See the LICENSE file in the root directory of this source tree. */ var Y = w("outline", "file-type-pdf", "IconFileTypePdf", [["path", { d: "M14 3v4a1 1 0 0 0 1 1h4", key: "svg-0" }], ["path", { d: "M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4", key: "svg-1" }], ["path", { d: "M5 18h1.5a1.5 1.5 0 0 0 0 -3h-1.5v6", key: "svg-2" }], ["path", { d: "M17 18h2", key: "svg-3" }], ["path", { d: "M20 15h-3v6", key: "svg-4" }], ["path", { d: "M11 15v6h1a2 2 0 0 0 2 -2v-2a2 2 0 0 0 -2 -2h-1z", key: "svg-5" }]]); const Z = () => { const t = r => r.priceRanges.length == 0 ? e.jsxs(e.Fragment, { children: [r.price, "₽"] }) : e.jsx(e.Fragment, { children: e.jsx(F, { children: r.priceRanges.map(n => e.jsx(F.Item, { children: `${n.fromQuantity} - ${n.toQuantity}: ${n.price}₽` }, n.id)) }) }); return R.useMemo( () => [{ accessorKey: "category", header: "Категория", accessorFn: r => `${r.category.name}`, enableColumnOrdering: !0, enableSorting: !1 }, { accessorKey: "name", header: "Услуга", enableGrouping: !1, enableSorting: !1, Cell: ({row: r, cell: n}) => r.original.isPlaceholder ? "" : n.renderValue() }, { accessorKey: "price", header: "Цена", enableGrouping: !1, enableSorting: !1, Cell: ({row: r}) => r.original.isPlaceholder ? "" : t(r.original) }, { accessorKey: "cost", header: "Себестоимость", enableGrouping: !1, enableSorting: !1, Cell: ({row: r}) => r.original.isPlaceholder ? "" : `${r.original.cost}₽` }], []) } ; var h = (t => (t[t.DEAL_SERVICE = 0] = "DEAL_SERVICE", t[t.PRODUCT_SERVICE = 1] = "PRODUCT_SERVICE", t[t.SERVICES_KITS = 2] = "SERVICES_KITS", t))(h || {}); const ee = [{ label: "Для товара", value: "1" }, { label: "Для сделки", value: "0" }, { label: "Наборы услуг", value: "2" }] , te = t => e.jsx(L, { data: ee, ...t }) , re = ({items: t, onDelete: r, onChange: n, serviceType: u, editMode: S}) => { const s = $() , l = Z() , C = t.map(a => a.category).map(a => u === h.DEAL_SERVICE ? a.dealServiceRank : a.productServiceRank) , d = C.sort()[0] , c = C.sort()[C.length - 1] , g = a => { n && f.openContextModal({ modal: "createService", title: "Создание услуги", withCloseButton: !1, innerProps: { onChange: o => n(o), element: a } }) } ; return e.jsx(U, { data: t, columns: l, restProps: { enableGrouping: !0, initialState: { grouping: ["category"] }, state: { columnVisibility: { "mrt-row-drag": S } }, enableColumnActions: !1, enableRowOrdering: !0, mantineRowDragHandleProps: ({table: a}) => ({ onDragEnd: () => { const {draggingRow: o, hoveredRow: i} = a.getState(); !(i != null && i.original) || !(o != null && o.original) || v.reorderService({ requestBody: { drainingServiceId: o.original.id, hoveredServiceId: i.original.id } }).then( ({ok: y, message: K}) => { if (!y) { p.guess(y, { message: K }); return } s.invalidateQueries({ queryKey: ["getAllServices"] }).then( () => {} ) } ) } }), displayColumnDefOptions: { "mrt-row-drag": { AggregatedCell: ({row: a}) => { const o = u === h.DEAL_SERVICE ? a.original.category.dealServiceRank : a.original.category.productServiceRank; return e.jsxs(I, { gap: "xs", children: [e.jsx(x, { label: "Поднять вверх", children: e.jsx(m, { disabled: o === d, onClick: () => { v.reorderServiceCategory({ requestBody: { serviceType: u, categoryId: a.original.category.id, moveDown: !1, moveUp: !0 } }).then( ({ok: i, message: y}) => { if (!i) { p.guess(i, { message: y }); return } s.invalidateQueries({ queryKey: ["getAllServices"] }).then( () => {} ) } ) } , variant: "default", children: e.jsx(J, {}) }) }), e.jsx(x, { label: "Опустить вниз", children: e.jsx(m, { disabled: o === c, onClick: () => { v.reorderServiceCategory({ requestBody: { serviceType: u, categoryId: a.original.category.id, moveDown: !0, moveUp: !1 } }).then( ({ok: i, message: y}) => { if (!i) { p.guess(i, { message: y }); return } s.invalidateQueries({ queryKey: ["getAllServices"] }).then( () => {} ) } ) } , variant: "default", children: e.jsx(X, {}) }) })] }) } }, "mrt-row-actions": { AggregatedCell: ({row: a}) => S && e.jsxs(I, { gap: "xs", children: [e.jsx(x, { label: "Редактировать категорию", children: e.jsx(m, { onClick: () => { f.openContextModal({ modal: "createServiceCategory", title: "Создание категории", withCloseButton: !1, innerProps: { element: a.original.category, onChange: o => { v.updateServiceCategory({ requestBody: { category: o } }).then( ({ok: i, message: y}) => { p.guess(i, { message: y }), i && s.invalidateQueries({ queryKey: ["getAllServices"] }).then( () => {} ) } ) } } }) } , variant: "default", children: e.jsx(M, {}) }) }), e.jsx(x, { label: "Удалить категорию", children: e.jsx(m, { onClick: () => { f.openConfirmModal({ title: "Удаление категории", children: `Вы уверены, что хотите удалить категорию: ${a.original.category.name}?`, onConfirm: () => { v.deleteServiceCategory({ requestBody: { categoryId: a.original.category.id } }).then( ({ok: o, message: i}) => { p.guess(o, { message: i }), o && s.invalidateQueries({ queryKey: ["getAllServices"] }).then( () => {} ) } ) } }) } , variant: "default", children: e.jsx(P, {}) }) })] }) } }, enableRowActions: !0, renderRowActions: ({row: a}) => e.jsxs(I, { display: a.original.isPlaceholder ? "none" : "flex", gap: "xs", children: [e.jsx(x, { label: "Редактировать", children: e.jsx(m, { onClick: () => g(a.original), variant: "default", children: e.jsx(M, {}) }) }), e.jsx(x, { label: "Удалить", children: e.jsx(m, { onClick: () => { r && r(a.original) } , variant: "default", children: e.jsx(P, {}) }) })] }) } }) } , ae = () => R.useMemo( () => [{ accessorKey: "name", header: "Название набора" }, { header: "Кол-во услуг", Cell: ({row: t}) => t.original.services.length }], []) , ne = ({items: t, onDelete: r, onChange: n}) => { const u = ae() , S = s => { n && f.openContextModal({ modal: "serviceKitModalForm", title: "Создание набора услуг", withCloseButton: !1, innerProps: { element: s, onChange: n } }) } ; return e.jsx(U, { data: t, columns: u, restProps: { enableSorting: !1, enableColumnActions: !1, enableRowActions: !0, renderRowActions: ({row: s}) => e.jsxs(I, { gap: "md", children: [e.jsx(x, { label: "Редактировать", children: e.jsx(m, { onClick: () => S(s.original), variant: "default", children: e.jsx(M, {}) }) }), e.jsx(x, { label: "Удалить", children: e.jsx(m, { onClick: () => {} , variant: "default", children: e.jsx(P, {}) }) })] }) } }) } , se = () => { const {services: t, refetch: r} = O({ withPlaceholders: !0 }) , n = () => { f.openContextModal({ modal: "createService", title: "Создание услуги", withCloseButton: !1, innerProps: { onCreate: u } }) } , u = d => { v.createService({ requestBody: { service: d } }).then(async ({ok: c, message: g}) => { p.guess(c, { message: g }), c && await r() } ) } , S = () => { f.openContextModal({ modal: "createServiceCategory", title: "Создание категории", withCloseButton: !1, innerProps: { onCreate: s } }) } , s = d => { v.createServiceCategory({ requestBody: { category: d } }).then( ({ok: c, message: g}) => p.guess(c, { message: g })) } ; return { services: t, onCreateClick: n, onServiceDelete: d => { f.openConfirmModal({ title: "Удаление услуги", children: e.jsxs(Q, { children: ['Вы уверены, что хотите удалить услугу "', d.name, '"?'] }), onConfirm: () => { v.deleteService({ requestBody: { serviceId: d.id } }).then(async ({ok: c, message: g}) => { p.guess(c, { message: g }), c && await r() } ) } , labels: { confirm: "Удалить", cancel: "Отмена" } }) } , onServiceUpdate: d => { v.updateService({ requestBody: { data: d } }).then(async ({ok: c, message: g}) => { p.guess(c, { message: g }), c && await r() } ) } , onCreateCategoryClick: S } } , ie = () => { const {objects: t, refetch: r} = G() , n = s => { v.createServicesKit({ requestBody: { data: { ..._.omit(s, ["services", "id"]), servicesIds: s.services.map(l => l.id) } } }).then(async ({ok: l, message: C}) => { p.guess(l, { message: C }), l && await r() } ) } ; return { onKitCreateClick: () => { f.openContextModal({ modal: "serviceKitModalForm", title: "Создание набора услуг", withCloseButton: !1, innerProps: { onCreate: n } }) } , onKitUpdate: s => { v.updateServicesKit({ requestBody: { data: { ..._.omit(s, ["services"]), servicesIds: s.services.map(l => l.id) } } }).then(async ({ok: l, message: C}) => { p.guess(l, { message: C }), l && await r() } ) } , servicesKits: t } } , oe = () => { const [t,r] = R.useState(h.DEAL_SERVICE) , [n,u] = R.useState(!1) , {services: S, onServiceDelete: s, onServiceUpdate: l, onCreateClick: C, onCreateCategoryClick: d} = se() , {servicesKits: c, onKitUpdate: g, onKitCreateClick: a} = ie() , o = () => { switch (t) { case h.SERVICES_KITS: return e.jsx(ne, { items: c, onChange: g }); case h.DEAL_SERVICE: case h.PRODUCT_SERVICE: { const j = S.filter(k => k.serviceType === t).sort( (k, B) => t === h.DEAL_SERVICE ? k.category.dealServiceRank.localeCompare(B.category.dealServiceRank) : k.category.productServiceRank.localeCompare(B.category.productServiceRank)); return e.jsx(re, { onDelete: s, onChange: l, items: j, serviceType: t, editMode: n }) } } } , i = () => { switch (t) { case h.SERVICES_KITS: return e.jsx(E, { onClick: a, variant: "default", children: "Создать набор" }); case h.DEAL_SERVICE: case h.PRODUCT_SERVICE: return e.jsxs(I, { align: "center", gap: b(10), children: [e.jsxs("div", { style: { display: "grid", gridAutoFlow: "column", gridAutoColumns: "1fr", width: "max-content", gap: b(10) }, children: [e.jsx(E, { onClick: C, variant: "default", children: "Создать услугу" }), e.jsx(E, { onClick: d, variant: "default", children: "Создать категорию" }), e.jsxs(A, { withArrow: !0, shadow: "md", children: [e.jsx(A.Target, { children: e.jsx(E, { leftSection: e.jsx(W, {}), variant: "default", children: "Скачать" }) }), e.jsx(A.Dropdown, { children: e.jsxs(I, { direction: "column", gap: b(10), children: [ e.jsx(E, { onClick: y, variant: "default", leftSection: e.jsx(Y, {}), children: "В формате PDF" }), /* e.jsx(E, { onClick: K, variant: "default", leftSection: e.jsx(N, {}), children: "В формате Excel" }) */ ] }) })] })] }), e.jsx(z, { variant: "default", label: "Режим редактирования", checked: n, onChange: () => u(!n) })] }) } } , y = () => { const j = q(); T.saveAs("/api/v1/service/export-list/pdf", `прайс_лист_${j}.pdf`) } , K = () => { const j = q(); T.saveAs("/api/v1/service/export-list/excel", `прайс_лист_${j}.xlsx`) } ; return e.jsxs("div", { className: D.container, children: [e.jsx(V, { children: e.jsxs("div", { className: D["top-panel"], children: [i(), e.jsx(te, { className: D["top-panel-last-item"], value: t.toString(), onChange: j => r(parseInt(j)) })] }) }), e.jsx(V, { children: o() })] }) } , ue = H("/services")({ component: oe }); export {ue as Route};