warqadui 0.0.30 → 0.0.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1079,6 +1079,14 @@ var Input = forwardRef(
1079
1079
  const [showPassword, setShowPassword] = useState7(false);
1080
1080
  const { theme } = useWarqadConfig();
1081
1081
  const primaryColor = theme?.primaryColor;
1082
+ useEffect5(() => {
1083
+ if (form && name && props.value !== void 0 && props.value !== null && props.value !== "") {
1084
+ const currentFormValue = form.getValues(name);
1085
+ if (currentFormValue === void 0 || currentFormValue === "" || currentFormValue === 0) {
1086
+ form.setValue(name, props.value);
1087
+ }
1088
+ }
1089
+ }, [props.value, name, form]);
1082
1090
  let message = error;
1083
1091
  if (form && name) {
1084
1092
  const {
@@ -1161,39 +1169,62 @@ var Input = forwardRef(
1161
1169
  {
1162
1170
  control: form.control,
1163
1171
  name,
1164
- render: ({ field: { onChange, value, ref: fieldRef, onBlur: onBlur2 } }) => renderInput(
1165
- {
1166
- ref: fieldRef,
1167
- onBlur: () => {
1168
- onBlur2();
1169
- },
1170
- value: value ? String(value).split(".").map(
1171
- (part, index) => index === 0 ? part.replace(/\B(?=(\d{3})+(?!\d))/g, ",") : part
1172
- ).join(".") : "",
1173
- onChange: (e) => {
1174
- const rawValue = e.target.value.replace(/,/g, "");
1175
- if (!/^\d*\.?\d*$/.test(rawValue)) return;
1176
- if (rawValue === "") {
1177
- onChange("");
1178
- } else {
1179
- const numValue = Number(rawValue);
1180
- if (!isNaN(numValue) && String(numValue) === rawValue) {
1181
- onChange(numValue);
1172
+ render: ({ field: { onChange, value, ref: fieldRef, onBlur: onBlur2 } }) => {
1173
+ const hasValue = value !== void 0 && value !== null && value !== "";
1174
+ const hasPropsValue = props.value !== void 0 && props.value !== null && props.value !== "";
1175
+ const displayValue = hasValue ? value : hasPropsValue ? props.value : "";
1176
+ return renderInput(
1177
+ {
1178
+ ref: fieldRef,
1179
+ onBlur: () => {
1180
+ onBlur2();
1181
+ },
1182
+ value: displayValue !== "" ? String(displayValue).split(".").map(
1183
+ (part, index) => index === 0 ? part.replace(/\B(?=(\d{3})+(?!\d))/g, ",") : part
1184
+ ).join(".") : "",
1185
+ onChange: (e) => {
1186
+ const rawValue = e.target.value.replace(/,/g, "");
1187
+ if (!/^\d*\.?\d*$/.test(rawValue)) return;
1188
+ if (rawValue === "") {
1189
+ onChange("");
1190
+ props.onChange?.("");
1182
1191
  } else {
1183
- onChange(rawValue);
1192
+ const numValue = Number(rawValue);
1193
+ if (!isNaN(numValue) && String(numValue) === rawValue) {
1194
+ onChange(numValue);
1195
+ props.onChange?.(numValue);
1196
+ } else {
1197
+ onChange(rawValue);
1198
+ props.onChange?.(rawValue);
1199
+ }
1184
1200
  }
1185
1201
  }
1186
- props.onChange?.(e);
1187
- }
1188
- },
1189
- "text"
1190
- )
1202
+ },
1203
+ "text"
1204
+ );
1205
+ }
1191
1206
  }
1192
1207
  );
1193
1208
  }
1194
- let inputPropsObj = form && name ? form.register(name, type === "number" ? { valueAsNumber: true } : {}) : {};
1209
+ let inputPropsObj = {};
1210
+ const originalOnChange = props.onChange;
1211
+ if (form && name) {
1212
+ const registeredProps = form.register(
1213
+ name,
1214
+ type === "number" ? { valueAsNumber: true } : {}
1215
+ );
1216
+ inputPropsObj = {
1217
+ ...registeredProps,
1218
+ onChange: (e) => {
1219
+ registeredProps.onChange(e);
1220
+ const rawValue = e.target.value.replace(/,/g, "");
1221
+ originalOnChange?.(
1222
+ type === "number" ? rawValue === "" ? "" : Number(rawValue) : e.target.value
1223
+ );
1224
+ }
1225
+ };
1226
+ }
1195
1227
  if (type === "number" && (!form || !name)) {
1196
- const originalOnChange = props.onChange;
1197
1228
  inputPropsObj = {
1198
1229
  ...inputPropsObj,
1199
1230
  value: props.value !== void 0 && props.value !== null ? String(props.value).split(".").map(
@@ -1203,20 +1234,20 @@ var Input = forwardRef(
1203
1234
  const rawValue = e.target.value.replace(/,/g, "");
1204
1235
  if (!/^\d*\.?\d*$/.test(rawValue)) return;
1205
1236
  if (originalOnChange) {
1206
- const fakeEvent = {
1207
- ...e,
1208
- target: {
1209
- ...e.target,
1210
- value: rawValue,
1211
- valueAsNumber: rawValue === "" ? NaN : Number(rawValue)
1212
- }
1213
- };
1214
- originalOnChange(fakeEvent);
1237
+ originalOnChange(rawValue === "" ? "" : Number(rawValue));
1215
1238
  }
1216
1239
  }
1217
1240
  };
1218
1241
  return renderInput(inputPropsObj, "text");
1219
1242
  }
1243
+ if (!form || !name) {
1244
+ inputPropsObj = {
1245
+ ...inputPropsObj,
1246
+ onChange: (e) => {
1247
+ originalOnChange?.(e.target.value);
1248
+ }
1249
+ };
1250
+ }
1220
1251
  return renderInput(inputPropsObj, type === "number" ? "text" : type);
1221
1252
  }
1222
1253
  );
@@ -1343,6 +1374,14 @@ var useSelectContext = () => {
1343
1374
  };
1344
1375
  var Select = forwardRef3((props, ref) => {
1345
1376
  const { form, name, onChange, value, children, options = [] } = props;
1377
+ useEffect6(() => {
1378
+ if (form && name && value !== void 0 && value !== null && value !== "") {
1379
+ const currentFormValue = form.getValues(name);
1380
+ if (currentFormValue === void 0 || currentFormValue === "" || currentFormValue === 0) {
1381
+ form.setValue(name, value);
1382
+ }
1383
+ }
1384
+ }, [value, name, form]);
1346
1385
  if (form && name) {
1347
1386
  return /* @__PURE__ */ jsx19(
1348
1387
  Controller3,
@@ -1735,7 +1774,7 @@ var SelectItem = forwardRef3(
1735
1774
  SelectItem.displayName = "SelectItem";
1736
1775
 
1737
1776
  // src/components/Fields/textArea.tsx
1738
- import { forwardRef as forwardRef4, useState as useState10 } from "react";
1777
+ import { forwardRef as forwardRef4, useEffect as useEffect7, useState as useState10 } from "react";
1739
1778
  import {
1740
1779
  Controller as Controller4
1741
1780
  } from "react-hook-form";
@@ -1799,30 +1838,47 @@ var Textarea = forwardRef4(
1799
1838
  ) }),
1800
1839
  message && /* @__PURE__ */ jsx20("p", { className: "text-sm text-red-600 dark:text-red-400", children: message })
1801
1840
  ] });
1841
+ useEffect7(() => {
1842
+ if (form && name && props.value !== void 0 && props.value !== null && props.value !== "") {
1843
+ const currentFormValue = form.getValues(name);
1844
+ if (currentFormValue === void 0 || currentFormValue === "" || currentFormValue === 0) {
1845
+ form.setValue(name, props.value);
1846
+ }
1847
+ }
1848
+ }, [props.value, name, form]);
1802
1849
  if (form && name) {
1803
1850
  return /* @__PURE__ */ jsx20(
1804
1851
  Controller4,
1805
1852
  {
1806
1853
  control: form.control,
1807
1854
  name,
1808
- render: ({ field: { onChange, value, ref: fieldRef, onBlur: onBlur2 } }) => renderInput(
1809
- {
1810
- value: value || "",
1811
- // Ensure controlled input doesn't warn about uncontrolled
1812
- onChange: (e) => {
1813
- onChange(e);
1814
- props.onChange?.(e);
1855
+ render: ({ field: { onChange, value, ref: fieldRef, onBlur: onBlur2 } }) => {
1856
+ const displayValue = value !== void 0 && value !== null && value !== "" ? value : props.value;
1857
+ return renderInput(
1858
+ {
1859
+ value: displayValue || "",
1860
+ onChange: (e) => {
1861
+ onChange(e);
1862
+ props.onChange?.(e);
1863
+ },
1864
+ onBlur: () => {
1865
+ onBlur2();
1866
+ }
1815
1867
  },
1816
- onBlur: () => {
1817
- onBlur2();
1818
- }
1819
- },
1820
- fieldRef
1821
- )
1868
+ fieldRef
1869
+ );
1870
+ }
1822
1871
  }
1823
1872
  );
1824
1873
  }
1825
- return renderInput({}, ref);
1874
+ return renderInput(
1875
+ {
1876
+ onChange: (e) => {
1877
+ props.onChange?.(e);
1878
+ }
1879
+ },
1880
+ ref
1881
+ );
1826
1882
  }
1827
1883
  );
1828
1884
 
@@ -1832,7 +1888,7 @@ import {
1832
1888
  useContext as useContext4,
1833
1889
  useState as useState12,
1834
1890
  useRef as useRef4,
1835
- useEffect as useEffect7,
1891
+ useEffect as useEffect8,
1836
1892
  forwardRef as forwardRef5
1837
1893
  } from "react";
1838
1894
  import { createPortal as createPortal2 } from "react-dom";
@@ -2021,6 +2077,14 @@ var useSearchApiContext = () => {
2021
2077
  var SearchApi = forwardRef5(
2022
2078
  (props, _) => {
2023
2079
  const { form, name, onChange, onSelect, onClear, value, children, ...restProps } = props;
2080
+ useEffect8(() => {
2081
+ if (form && name && value !== void 0 && value !== null && value !== "") {
2082
+ const currentFormValue = form.getValues(name);
2083
+ if (currentFormValue === void 0 || currentFormValue === "" || currentFormValue === 0) {
2084
+ form.setValue(name, value);
2085
+ }
2086
+ }
2087
+ }, [value, name, form]);
2024
2088
  if (form && name) {
2025
2089
  return /* @__PURE__ */ jsx21(
2026
2090
  Controller5,
@@ -2135,7 +2199,7 @@ var SearchApiRoot = ({
2135
2199
  setOptions([]);
2136
2200
  }
2137
2201
  };
2138
- useEffect7(() => {
2202
+ useEffect8(() => {
2139
2203
  const timer = setTimeout(() => {
2140
2204
  if (isOpen) {
2141
2205
  fetchOptions(searchTerm);
@@ -2143,18 +2207,18 @@ var SearchApiRoot = ({
2143
2207
  }, 300);
2144
2208
  return () => clearTimeout(timer);
2145
2209
  }, [searchTerm, api, isOpen]);
2146
- useEffect7(() => {
2210
+ useEffect8(() => {
2147
2211
  if (isOpen && options.length === 0) {
2148
2212
  fetchOptions("");
2149
2213
  }
2150
2214
  }, [isOpen]);
2151
- useEffect7(() => {
2152
- if (currentValue && !selectedObject) {
2215
+ useEffect8(() => {
2216
+ if (currentValue !== void 0 && currentValue !== null && currentValue !== "" && !selectedObject) {
2153
2217
  setHasAttemptedHydration(false);
2154
2218
  fetchOptions(currentValue).finally(() => {
2155
2219
  setHasAttemptedHydration(true);
2156
2220
  });
2157
- } else if (!currentValue) {
2221
+ } else if (currentValue === void 0 || currentValue === null || currentValue === "") {
2158
2222
  setHasAttemptedHydration(true);
2159
2223
  if (selectedObject) setSelectedObject(void 0);
2160
2224
  }
@@ -2165,8 +2229,8 @@ var SearchApiRoot = ({
2165
2229
  }
2166
2230
  return option[valueKey];
2167
2231
  };
2168
- useEffect7(() => {
2169
- if (currentValue && !selectedObject && options.length > 0) {
2232
+ useEffect8(() => {
2233
+ if (currentValue !== void 0 && currentValue !== null && currentValue !== "" && !selectedObject && options.length > 0) {
2170
2234
  const found = options.find((o) => getOptionValue(o) === currentValue);
2171
2235
  if (found) {
2172
2236
  setSelectedObject(found);
@@ -2179,7 +2243,7 @@ var SearchApiRoot = ({
2179
2243
  }
2180
2244
  }
2181
2245
  }, [currentValue, options, obj]);
2182
- useEffect7(() => {
2246
+ useEffect8(() => {
2183
2247
  if (prevApiRef.current !== api) {
2184
2248
  prevApiRef.current = api;
2185
2249
  setSearchTerm("");
@@ -2204,7 +2268,7 @@ var SearchApiRoot = ({
2204
2268
  fetchOptions("");
2205
2269
  }
2206
2270
  }, [api, name, obj]);
2207
- useEffect7(() => {
2271
+ useEffect8(() => {
2208
2272
  const handleClickOutside = (event) => {
2209
2273
  const target = event.target;
2210
2274
  if (containerRef.current && !containerRef.current.contains(target) && !(dropdownContentRef.current && dropdownContentRef.current.contains(target))) {
@@ -2219,13 +2283,13 @@ var SearchApiRoot = ({
2219
2283
  }, [fieldInternalProps]);
2220
2284
  const getDisplayValue = () => {
2221
2285
  if (selectedObject) return selectedObject[labelKey];
2222
- if (options.length > 0 && currentValue) {
2286
+ if (options.length > 0 && (currentValue !== void 0 && currentValue !== null && currentValue !== "")) {
2223
2287
  const found = options.find((o) => getOptionValue(o) === currentValue);
2224
2288
  if (found) return found[labelKey];
2225
2289
  }
2226
- if (isLoading || currentValue && !hasAttemptedHydration)
2290
+ if (isLoading || currentValue !== void 0 && currentValue !== null && currentValue !== "" && !hasAttemptedHydration)
2227
2291
  return "Loading...";
2228
- return currentValue || "";
2292
+ return currentValue !== void 0 && currentValue !== null && currentValue !== "" ? currentValue : "";
2229
2293
  };
2230
2294
  const handleSelect = (option) => {
2231
2295
  const val = getOptionValue(option);
@@ -2480,7 +2544,7 @@ var SearchApiInput = forwardRef5(
2480
2544
  }
2481
2545
  };
2482
2546
  return /* @__PURE__ */ jsxs15(Fragment4, { children: [
2483
- !isOpen && selectedValue && /* @__PURE__ */ jsx21("div", { className: "absolute inset-0 flex items-center ms-1 truncate select-none", children: getDisplayValue() }),
2547
+ !isOpen && (selectedValue !== void 0 && selectedValue !== null && selectedValue !== "") && /* @__PURE__ */ jsx21("div", { className: "absolute inset-0 flex items-center ms-1 truncate select-none", children: getDisplayValue() }),
2484
2548
  /* @__PURE__ */ jsx21(
2485
2549
  "input",
2486
2550
  {
@@ -2554,7 +2618,7 @@ var SearchApiContent = forwardRef5(
2554
2618
  setDropdownStyle(newStyle);
2555
2619
  }
2556
2620
  };
2557
- useEffect7(() => {
2621
+ useEffect8(() => {
2558
2622
  if (isOpen) {
2559
2623
  updateDropdownPosition();
2560
2624
  window.addEventListener("scroll", updateDropdownPosition, true);
@@ -2774,7 +2838,7 @@ var Fields = {
2774
2838
  var Fields_default = Fields;
2775
2839
 
2776
2840
  // src/components/tables/DataTable.tsx
2777
- import React8, { useState as useState14, useMemo as useMemo3, useEffect as useEffect8 } from "react";
2841
+ import React8, { useState as useState14, useMemo as useMemo3, useEffect as useEffect9 } from "react";
2778
2842
  import {
2779
2843
  useReactTable,
2780
2844
  getCoreRowModel,
@@ -2802,7 +2866,8 @@ function DataTable({
2802
2866
  defaultExpanded = false,
2803
2867
  onChange,
2804
2868
  selectable = true,
2805
- filterables = true
2869
+ filterables = true,
2870
+ emptyState
2806
2871
  }) {
2807
2872
  const { theme } = useWarqadConfig();
2808
2873
  const primaryColor = theme?.primaryColor;
@@ -2828,7 +2893,7 @@ function DataTable({
2828
2893
  pageIndex: 0,
2829
2894
  pageSize: pageRows || 10
2830
2895
  });
2831
- useEffect8(() => {
2896
+ useEffect9(() => {
2832
2897
  if (pageRows) {
2833
2898
  setPagination((prev) => ({ ...prev, pageSize: pageRows }));
2834
2899
  }
@@ -2894,7 +2959,7 @@ function DataTable({
2894
2959
  },
2895
2960
  manualPagination: false
2896
2961
  });
2897
- useEffect8(() => {
2962
+ useEffect9(() => {
2898
2963
  if (onChange) {
2899
2964
  onChange({
2900
2965
  pagination: {
@@ -3030,7 +3095,7 @@ function DataTable({
3030
3095
  {
3031
3096
  colSpan: columns.length,
3032
3097
  className: "h-32 text-center text-sm text-gray-500",
3033
- children: "No results found."
3098
+ children: emptyState || "No results found."
3034
3099
  }
3035
3100
  ) }) }),
3036
3101
  table.getFooterGroups().some(
@@ -3092,7 +3157,13 @@ function DataTable({
3092
3157
  }
3093
3158
 
3094
3159
  // src/components/tables/PostTable.tsx
3095
- import React9, { useState as useState15, useMemo as useMemo4, useEffect as useEffect9, useRef as useRef5 } from "react";
3160
+ import React9, {
3161
+ useState as useState15,
3162
+ useMemo as useMemo4,
3163
+ useEffect as useEffect10,
3164
+ useRef as useRef5,
3165
+ useCallback as useCallback2
3166
+ } from "react";
3096
3167
  import {
3097
3168
  useReactTable as useReactTable2,
3098
3169
  getCoreRowModel as getCoreRowModel2,
@@ -3101,8 +3172,95 @@ import {
3101
3172
  getExpandedRowModel as getExpandedRowModel2,
3102
3173
  flexRender as flexRender2
3103
3174
  } from "@tanstack/react-table";
3104
- import { Plus, Edit2, Trash2, Check as Check4, X as X3, ChevronDown as ChevronDown5 } from "lucide-react";
3175
+ import {
3176
+ Plus,
3177
+ Edit2,
3178
+ Trash2,
3179
+ Check as Check4,
3180
+ X as X3,
3181
+ ChevronDown as ChevronDown5,
3182
+ Loader2 as Loader23
3183
+ } from "lucide-react";
3105
3184
  import { Fragment as Fragment6, jsx as jsx24, jsxs as jsxs18 } from "react/jsx-runtime";
3185
+ var TableCell = React9.memo(
3186
+ ({
3187
+ cell,
3188
+ rowPadding,
3189
+ verticalLines
3190
+ }) => {
3191
+ return /* @__PURE__ */ jsx24(
3192
+ "td",
3193
+ {
3194
+ className: cn(
3195
+ rowPadding,
3196
+ "text-sm text-gray-700 dark:text-gray-200",
3197
+ verticalLines && "border-x border-gray-200 dark:border-zinc-800",
3198
+ cell.column.id === "_index" && "w-[1%] min-w-[40px] max-w-[40px] whitespace-nowrap",
3199
+ cell.column.columnDef.meta?.className
3200
+ ),
3201
+ style: {
3202
+ width: cell.column.columnDef.meta?.width ?? cell.column.getSize(),
3203
+ minWidth: cell.column.columnDef.meta?.width ?? cell.column.columnDef.minSize,
3204
+ maxWidth: cell.column.columnDef.meta?.width ?? cell.column.columnDef.maxSize
3205
+ },
3206
+ children: flexRender2(cell.column.columnDef.cell, cell.getContext())
3207
+ },
3208
+ cell.id
3209
+ );
3210
+ },
3211
+ (prev, next) => {
3212
+ return prev.cell.getValue() === next.cell.getValue() && prev.cell.row.getIsExpanded() === next.cell.row.getIsExpanded() && prev.cell.row.getIsSelected() === next.cell.row.getIsSelected() && prev.rowPadding === next.rowPadding && prev.verticalLines === next.verticalLines;
3213
+ }
3214
+ );
3215
+ var TableRow = React9.memo(
3216
+ ({
3217
+ row,
3218
+ rowPadding,
3219
+ verticalLines,
3220
+ renderSubComponent,
3221
+ hasSubComponent,
3222
+ columnsCount
3223
+ }) => {
3224
+ const isExpanded = row.getIsExpanded();
3225
+ const subComponentVisible = renderSubComponent && isExpanded && hasSubComponent(row.original);
3226
+ return /* @__PURE__ */ jsxs18(React9.Fragment, { children: [
3227
+ /* @__PURE__ */ jsx24(
3228
+ "tr",
3229
+ {
3230
+ className: `border-b border-gray-200 dark:border-zinc-800 hover:bg-gray-50/50 dark:hover:bg-zinc-900/50 transition-colors last:border-b-0 ${renderSubComponent && hasSubComponent(row.original) ? "cursor-pointer" : ""}`,
3231
+ "data-state": row.getIsSelected() && "selected",
3232
+ onClick: (e) => {
3233
+ if (renderSubComponent && hasSubComponent(row.original)) {
3234
+ const target = e.target;
3235
+ if (!target.closest("button, a, input, select, textarea")) {
3236
+ row.toggleExpanded();
3237
+ }
3238
+ }
3239
+ },
3240
+ children: row.getVisibleCells().map((cell) => /* @__PURE__ */ jsx24(
3241
+ TableCell,
3242
+ {
3243
+ cell,
3244
+ rowPadding,
3245
+ verticalLines
3246
+ },
3247
+ cell.id
3248
+ ))
3249
+ }
3250
+ ),
3251
+ subComponentVisible && /* @__PURE__ */ jsx24("tr", { className: "border-b border-gray-200 dark:border-zinc-800 bg-gray-50/20 dark:bg-zinc-900/20", children: /* @__PURE__ */ jsx24("td", { colSpan: columnsCount, className: "px-2 py-0", children: /* @__PURE__ */ jsxs18("div", { className: "relative pl-6 pb-2 pr-2 pt-2 h-full", children: [
3252
+ /* @__PURE__ */ jsx24("div", { className: "absolute left-2 top-0 bottom-2 w-6 border-l-2 border-b-2 rounded-bl-xl border-(--theme-primary) dark:border-(--theme-primary) pointer-events-none" }),
3253
+ renderSubComponent({
3254
+ row: row.original,
3255
+ index: row.index
3256
+ })
3257
+ ] }) }) })
3258
+ ] });
3259
+ },
3260
+ (prev, next) => {
3261
+ return prev.row.original === next.row.original && prev.row.getIsExpanded() === next.row.getIsExpanded() && prev.row.getIsSelected() === next.row.getIsSelected() && prev.rowPadding === next.rowPadding && prev.verticalLines === next.verticalLines;
3262
+ }
3263
+ );
3106
3264
  function PostTable({
3107
3265
  columns: userColumns,
3108
3266
  data: controlledData,
@@ -3116,7 +3274,8 @@ function PostTable({
3116
3274
  renderSubComponent,
3117
3275
  hasSubComponent = () => true,
3118
3276
  // default to true if renderSubComponent is provided
3119
- defaultExpanded = false
3277
+ defaultExpanded = false,
3278
+ submitLoading = false
3120
3279
  }) {
3121
3280
  const { theme } = useWarqadConfig();
3122
3281
  const primaryColor = theme?.primaryColor;
@@ -3152,10 +3311,10 @@ function PostTable({
3152
3311
  }
3153
3312
  }, 50);
3154
3313
  };
3155
- useEffect9(() => {
3314
+ useEffect10(() => {
3156
3315
  focusAndScrollEntryRow();
3157
3316
  }, []);
3158
- useEffect9(() => {
3317
+ useEffect10(() => {
3159
3318
  if (controlledData) {
3160
3319
  setData(controlledData);
3161
3320
  }
@@ -3164,18 +3323,46 @@ function PostTable({
3164
3323
  const [editingIndex, setEditingIndex] = useState15(null);
3165
3324
  const [isSavingAsync, setIsSavingAsync] = useState15(false);
3166
3325
  const [fieldErrors, setFieldErrors] = useState15({});
3167
- const handleSaveField = async () => {
3168
- if (Object.keys(entryData).length === 0) return;
3169
- let newData = [...data];
3170
- if (editingIndex !== null) {
3171
- newData[editingIndex] = {
3172
- ...newData[editingIndex],
3173
- ...entryData
3326
+ const latestStateRef = useRef5({
3327
+ data,
3328
+ entryData,
3329
+ editingIndex,
3330
+ isSavingAsync,
3331
+ submitLoading,
3332
+ fieldErrors,
3333
+ onChange
3334
+ });
3335
+ useEffect10(() => {
3336
+ latestStateRef.current = {
3337
+ data,
3338
+ entryData,
3339
+ editingIndex,
3340
+ isSavingAsync,
3341
+ submitLoading,
3342
+ fieldErrors,
3343
+ onChange
3344
+ };
3345
+ });
3346
+ const handleSaveField = useCallback2(async () => {
3347
+ const {
3348
+ data: data2,
3349
+ entryData: entryData2,
3350
+ editingIndex: editingIndex2,
3351
+ isSavingAsync: isSavingAsync2,
3352
+ submitLoading: submitLoading2,
3353
+ onChange: onChange2
3354
+ } = latestStateRef.current;
3355
+ if (Object.keys(entryData2).length === 0) return;
3356
+ let newData = [...data2];
3357
+ if (editingIndex2 !== null) {
3358
+ newData[editingIndex2] = {
3359
+ ...newData[editingIndex2],
3360
+ ...entryData2
3174
3361
  };
3175
3362
  } else {
3176
- newData = [...newData, entryData];
3363
+ newData = [...newData, entryData2];
3177
3364
  }
3178
- if (onChange) {
3365
+ if (onChange2) {
3179
3366
  setIsSavingAsync(true);
3180
3367
  try {
3181
3368
  const actions = {
@@ -3199,9 +3386,9 @@ function PostTable({
3199
3386
  }));
3200
3387
  }
3201
3388
  };
3202
- const type = editingIndex !== null ? "edit" : "add";
3203
- const result = await onChange({
3204
- entryData,
3389
+ const type = editingIndex2 !== null ? "edit" : "add";
3390
+ const result = await onChange2({
3391
+ entryData: entryData2,
3205
3392
  actions,
3206
3393
  actionType: type,
3207
3394
  fullData: newData
@@ -3219,83 +3406,93 @@ function PostTable({
3219
3406
  setEntryData({});
3220
3407
  setFieldErrors({});
3221
3408
  setIsSavingAsync(false);
3222
- if (editingIndex !== null) {
3409
+ if (editingIndex2 !== null) {
3223
3410
  setEditingIndex(null);
3224
3411
  } else {
3225
3412
  focusAndScrollEntryRow();
3226
3413
  }
3227
- };
3228
- const handleCancelEdit = () => {
3414
+ }, []);
3415
+ const handleCancelEdit = useCallback2(() => {
3229
3416
  setEditingIndex(null);
3230
3417
  setEntryData({});
3231
3418
  setFieldErrors({});
3232
- };
3233
- const handleEdit = (index2, rowOriginal) => {
3419
+ }, []);
3420
+ const handleEdit = useCallback2((index2, rowOriginal) => {
3234
3421
  setEditingIndex(index2);
3235
3422
  setEntryData(rowOriginal);
3236
- };
3237
- const handleDelete = (index2) => {
3238
- const newData = data.filter((_, i) => i !== index2);
3239
- setData(newData);
3240
- const actions = {
3241
- focus: (columnId) => {
3242
- if (entryRowRef.current) {
3243
- const td = entryRowRef.current.querySelector(
3244
- `td[data-column-id="${columnId}"]`
3245
- );
3246
- if (td) {
3247
- const input = td.querySelector(
3248
- `input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex='0'], [id*='${columnId}']`
3423
+ }, []);
3424
+ const handleDelete = useCallback2(
3425
+ (index2) => {
3426
+ const { data: data2, editingIndex: editingIndex2, onChange: onChange2 } = latestStateRef.current;
3427
+ const newData = data2.filter((_, i) => i !== index2);
3428
+ setData(newData);
3429
+ const actions = {
3430
+ focus: (columnId) => {
3431
+ if (entryRowRef.current) {
3432
+ const td = entryRowRef.current.querySelector(
3433
+ `td[data-column-id="${columnId}"]`
3249
3434
  );
3250
- if (input) input.focus();
3435
+ if (td) {
3436
+ const input = td.querySelector(
3437
+ `input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex='0'], [id*='${columnId}']`
3438
+ );
3439
+ if (input) input.focus();
3440
+ }
3251
3441
  }
3442
+ },
3443
+ setError: (columnId, error) => {
3444
+ setFieldErrors((prev) => ({
3445
+ ...prev,
3446
+ [columnId]: error
3447
+ }));
3252
3448
  }
3253
- },
3254
- setError: (columnId, error) => {
3255
- setFieldErrors((prev) => ({
3256
- ...prev,
3257
- [columnId]: error
3258
- }));
3449
+ };
3450
+ onChange2?.({
3451
+ entryData: data2[index2],
3452
+ actions,
3453
+ actionType: "delete",
3454
+ fullData: newData
3455
+ });
3456
+ if (editingIndex2 === index2) {
3457
+ handleCancelEdit();
3458
+ } else if (editingIndex2 !== null && editingIndex2 > index2) {
3459
+ setEditingIndex(editingIndex2 - 1);
3259
3460
  }
3260
- };
3261
- onChange?.({
3262
- entryData: data[index2],
3263
- actions,
3264
- actionType: "delete",
3265
- fullData: newData
3266
- });
3267
- if (editingIndex === index2) {
3268
- handleCancelEdit();
3269
- } else if (editingIndex !== null && editingIndex > index2) {
3270
- setEditingIndex(editingIndex - 1);
3271
- }
3272
- };
3273
- const actionColumn = {
3274
- id: "actions",
3275
- header: "Actions",
3276
- cell: ({ row }) => {
3277
- return /* @__PURE__ */ jsxs18("div", { className: "flex items-center gap-2", children: [
3278
- /* @__PURE__ */ jsx24(
3279
- "button",
3280
- {
3281
- onClick: () => handleEdit(row.index, row.original),
3282
- className: "p-1 px-2 rounded-md hover:bg-gray-100 dark:hover:bg-zinc-800 text-gray-500 hover:text-(--theme-primary) dark:hover:text-(--theme-primary) transition-colors",
3283
- title: "Edit",
3284
- children: /* @__PURE__ */ jsx24(Edit2, { size: 16 })
3285
- }
3286
- ),
3287
- /* @__PURE__ */ jsx24(
3288
- "button",
3289
- {
3290
- onClick: () => handleDelete(row.index),
3291
- className: "p-1 px-2 rounded-md hover:bg-gray-100 dark:hover:bg-zinc-800 text-gray-500 hover:text-red-600 dark:hover:text-red-400 transition-colors",
3292
- title: "Delete",
3293
- children: /* @__PURE__ */ jsx24(Trash2, { size: 16 })
3294
- }
3295
- )
3296
- ] });
3297
- }
3298
- };
3461
+ },
3462
+ [handleCancelEdit]
3463
+ );
3464
+ const actionColumn = useMemo4(
3465
+ () => ({
3466
+ id: "actions",
3467
+ header: "Actions",
3468
+ cell: ({ row, table: table2 }) => {
3469
+ const { handleEdit: handleEdit2, handleDelete: handleDelete2, submitLoading: submitLoading2, isSavingAsync: isSavingAsync2 } = table2.options.meta;
3470
+ return /* @__PURE__ */ jsxs18("div", { className: "flex items-center gap-2", children: [
3471
+ /* @__PURE__ */ jsx24(
3472
+ "button",
3473
+ {
3474
+ onClick: () => handleEdit2(row.index, row.original),
3475
+ disabled: submitLoading2 || isSavingAsync2,
3476
+ className: "p-1 px-2 rounded-md hover:bg-gray-100 dark:hover:bg-zinc-800 text-gray-500 hover:text-(--theme-primary) dark:hover:text-(--theme-primary) transition-colors disabled:opacity-50",
3477
+ title: "Edit",
3478
+ children: submitLoading2 || isSavingAsync2 ? /* @__PURE__ */ jsx24(Loader23, { size: 16, className: "animate-spin" }) : /* @__PURE__ */ jsx24(Edit2, { size: 16 })
3479
+ }
3480
+ ),
3481
+ /* @__PURE__ */ jsx24(
3482
+ "button",
3483
+ {
3484
+ onClick: () => handleDelete2(row.index),
3485
+ disabled: submitLoading2 || isSavingAsync2,
3486
+ className: "p-1 px-2 rounded-md hover:bg-gray-100 dark:hover:bg-zinc-800 text-gray-500 hover:text-red-600 dark:hover:text-red-400 transition-colors disabled:opacity-50",
3487
+ title: "Delete",
3488
+ children: submitLoading2 || isSavingAsync2 ? /* @__PURE__ */ jsx24(Loader23, { size: 16, className: "animate-spin" }) : /* @__PURE__ */ jsx24(Trash2, { size: 16 })
3489
+ }
3490
+ )
3491
+ ] });
3492
+ }
3493
+ }),
3494
+ []
3495
+ );
3299
3496
  const columns = useMemo4(() => {
3300
3497
  const mappedUserColumns = userColumns.map((col) => ({
3301
3498
  ...col,
@@ -3344,6 +3541,12 @@ function PostTable({
3344
3541
  columnFilters,
3345
3542
  columnVisibility,
3346
3543
  expanded
3544
+ },
3545
+ meta: {
3546
+ handleEdit,
3547
+ handleDelete,
3548
+ submitLoading,
3549
+ isSavingAsync
3347
3550
  }
3348
3551
  });
3349
3552
  return /* @__PURE__ */ jsx24(
@@ -3398,54 +3601,18 @@ function PostTable({
3398
3601
  ))
3399
3602
  },
3400
3603
  `skeleton-${i}`
3401
- )) : table.getRowModel().rows?.length ? table.getRowModel().rows.map((row) => /* @__PURE__ */ jsxs18(React9.Fragment, { children: [
3402
- /* @__PURE__ */ jsx24(
3403
- "tr",
3404
- {
3405
- className: `border-b border-gray-200 dark:border-zinc-800 hover:bg-gray-50/50 dark:hover:bg-zinc-900/50 transition-colors last:border-b-0 ${renderSubComponent && hasSubComponent(row.original) ? "cursor-pointer" : ""}`,
3406
- "data-state": row.getIsSelected() && "selected",
3407
- onClick: (e) => {
3408
- if (renderSubComponent && hasSubComponent(row.original)) {
3409
- const target = e.target;
3410
- if (!target.closest(
3411
- "button, a, input, select, textarea"
3412
- )) {
3413
- row.toggleExpanded();
3414
- }
3415
- }
3416
- },
3417
- children: row.getVisibleCells().map((cell) => /* @__PURE__ */ jsx24(
3418
- "td",
3419
- {
3420
- className: cn(
3421
- rowPadding,
3422
- "text-sm text-gray-700 dark:text-gray-200",
3423
- verticalLines && "border-x border-gray-200 dark:border-zinc-800",
3424
- cell.column.id === "_index" && "w-[1%] min-w-[40px] max-w-[40px] whitespace-nowrap",
3425
- cell.column.columnDef.meta?.className
3426
- ),
3427
- style: {
3428
- width: cell.column.columnDef.meta?.width ?? cell.column.getSize(),
3429
- minWidth: cell.column.columnDef.meta?.width ?? cell.column.columnDef.minSize,
3430
- maxWidth: cell.column.columnDef.meta?.width ?? cell.column.columnDef.maxSize
3431
- },
3432
- children: flexRender2(
3433
- cell.column.columnDef.cell,
3434
- cell.getContext()
3435
- )
3436
- },
3437
- cell.id
3438
- ))
3439
- }
3440
- ),
3441
- renderSubComponent && row.getIsExpanded() && hasSubComponent(row.original) && /* @__PURE__ */ jsx24("tr", { className: "border-b border-gray-200 dark:border-zinc-800 bg-gray-50/20 dark:bg-zinc-900/20", children: /* @__PURE__ */ jsx24("td", { colSpan: columns.length, className: "px-2 py-0", children: /* @__PURE__ */ jsxs18("div", { className: "relative pl-6 pb-2 pr-2 pt-2 h-full", children: [
3442
- /* @__PURE__ */ jsx24("div", { className: "absolute left-2 top-0 bottom-2 w-6 border-l-2 border-b-2 rounded-bl-xl border-(--theme-primary) dark:border-(--theme-primary) pointer-events-none" }),
3443
- renderSubComponent({
3444
- row: row.original,
3445
- index: row.index
3446
- })
3447
- ] }) }) })
3448
- ] }, row.id)) : /* @__PURE__ */ jsx24("tr", { children: /* @__PURE__ */ jsx24(
3604
+ )) : table.getRowModel().rows?.length ? table.getRowModel().rows.map((row) => /* @__PURE__ */ jsx24(
3605
+ TableRow,
3606
+ {
3607
+ row,
3608
+ rowPadding,
3609
+ verticalLines,
3610
+ renderSubComponent,
3611
+ hasSubComponent,
3612
+ columnsCount: columns.length
3613
+ },
3614
+ row.id
3615
+ )) : /* @__PURE__ */ jsx24("tr", { children: /* @__PURE__ */ jsx24(
3449
3616
  "td",
3450
3617
  {
3451
3618
  colSpan: columns.length,
@@ -3481,17 +3648,23 @@ function PostTable({
3481
3648
  "button",
3482
3649
  {
3483
3650
  onClick: handleSaveField,
3484
- disabled: isSavingAsync,
3651
+ disabled: isSavingAsync || submitLoading,
3485
3652
  className: "flex-1 h-8 flex items-center justify-center rounded-lg bg-green-500/10 text-green-600 dark:bg-emerald-500/20 dark:text-emerald-400 hover:bg-green-500 hover:text-white dark:hover:bg-emerald-500 transition-colors shadow-sm active:scale-95 disabled:opacity-50 disabled:cursor-not-allowed",
3486
3653
  title: "Update",
3487
- children: isSavingAsync ? /* @__PURE__ */ jsx24("div", { className: "w-3.5 h-3.5 rounded-full border-2 border-emerald-500/30 border-t-emerald-500 animate-spin" }) : /* @__PURE__ */ jsx24(Check4, { size: 16, strokeWidth: 2.5 })
3654
+ children: isSavingAsync || submitLoading ? /* @__PURE__ */ jsx24(
3655
+ Loader23,
3656
+ {
3657
+ size: 16,
3658
+ className: "animate-spin"
3659
+ }
3660
+ ) : /* @__PURE__ */ jsx24(Check4, { size: 16, strokeWidth: 2.5 })
3488
3661
  }
3489
3662
  ),
3490
3663
  /* @__PURE__ */ jsx24(
3491
3664
  "button",
3492
3665
  {
3493
3666
  onClick: handleCancelEdit,
3494
- disabled: isSavingAsync,
3667
+ disabled: isSavingAsync || submitLoading,
3495
3668
  className: "flex-1 h-8 flex items-center justify-center rounded-lg bg-red-500/10 text-red-600 dark:bg-red-500/20 dark:text-red-400 hover:bg-red-500 hover:text-white dark:hover:bg-red-500 transition-colors shadow-sm active:scale-95 disabled:opacity-50 disabled:cursor-not-allowed",
3496
3669
  title: "Cancel",
3497
3670
  children: /* @__PURE__ */ jsx24(X3, { size: 16, strokeWidth: 2.5 })
@@ -3505,15 +3678,21 @@ function PostTable({
3505
3678
  "button",
3506
3679
  {
3507
3680
  onClick: handleSaveField,
3508
- disabled: isSavingAsync,
3681
+ disabled: isSavingAsync || submitLoading,
3509
3682
  className: "w-full cursor-pointer h-8 flex items-center justify-center gap-1.5 rounded-lg text-white text-xs font-medium transition-all shadow-sm hover:shadow-md hover:-translate-y-px active:scale-95 active:translate-y-0 hover:brightness-110 disabled:opacity-50 disabled:cursor-not-allowed",
3510
3683
  style: {
3511
3684
  backgroundColor: "var(--theme-primary)"
3512
3685
  },
3513
3686
  title: "Add Row",
3514
3687
  children: [
3515
- isSavingAsync ? /* @__PURE__ */ jsx24("div", { className: "w-3.5 h-3.5 rounded-full border-2 border-white/30 border-t-white animate-spin" }) : /* @__PURE__ */ jsx24(Plus, { size: 14, strokeWidth: 2.5 }),
3516
- /* @__PURE__ */ jsx24("span", { children: isSavingAsync ? "Adding..." : "Add" })
3688
+ isSavingAsync || submitLoading ? /* @__PURE__ */ jsx24(
3689
+ Loader23,
3690
+ {
3691
+ size: 14,
3692
+ className: "animate-spin"
3693
+ }
3694
+ ) : /* @__PURE__ */ jsx24(Plus, { size: 14, strokeWidth: 2.5 }),
3695
+ /* @__PURE__ */ jsx24("span", { children: isSavingAsync || submitLoading ? "Adding..." : "Add" })
3517
3696
  ]
3518
3697
  }
3519
3698
  ) }) })
@@ -3670,7 +3849,8 @@ function SimpleTable({
3670
3849
  startIndex = 0,
3671
3850
  isLoading = false,
3672
3851
  title,
3673
- enableSearch = false
3852
+ enableSearch = false,
3853
+ emptyState
3674
3854
  }) {
3675
3855
  const columns = useMemo5(() => {
3676
3856
  const cols = userColumns.filter((col) => !col.hide).map((col) => ({
@@ -3752,8 +3932,8 @@ function SimpleTable({
3752
3932
  "td",
3753
3933
  {
3754
3934
  colSpan: columns.length,
3755
- className: "text-center py-8 text-gray-500 font-medium",
3756
- children: "No transactions found."
3935
+ className: "text-center text-gray-500 font-medium",
3936
+ children: emptyState || /* @__PURE__ */ jsx25("div", { className: "py-8", children: "No transactions found." })
3757
3937
  }
3758
3938
  ) }) : table.getRowModel().rows.map((row) => /* @__PURE__ */ jsx25(
3759
3939
  "tr",
@@ -3853,7 +4033,7 @@ var Branding = ({
3853
4033
  };
3854
4034
 
3855
4035
  // src/hooks/Fetches/useA4DataView.tsx
3856
- import { useEffect as useEffect10, useRef as useRef6, useState as useState16 } from "react";
4036
+ import { useEffect as useEffect11, useRef as useRef6, useState as useState16 } from "react";
3857
4037
  import { useReactToPrint } from "react-to-print";
3858
4038
  import { RefreshCw, Printer, AlertCircle, FileX } from "lucide-react";
3859
4039
  import { jsx as jsx28, jsxs as jsxs20 } from "react/jsx-runtime";
@@ -3868,7 +4048,7 @@ var useA4StatementView = ({
3868
4048
  const reactToPrintFn = useReactToPrint({
3869
4049
  contentRef
3870
4050
  });
3871
- useEffect10(() => {
4051
+ useEffect11(() => {
3872
4052
  if (url) {
3873
4053
  get({ url, v, params, delay });
3874
4054
  }
@@ -3945,7 +4125,7 @@ var useA4StatementView = ({
3945
4125
  renderFooter: c.renderFooter ? c.renderFooter.toString() : ""
3946
4126
  }))
3947
4127
  });
3948
- useEffect10(() => {
4128
+ useEffect11(() => {
3949
4129
  if (filteredDisplayData && filteredDisplayData.length > 0) {
3950
4130
  setIsMeasuring(true);
3951
4131
  setPages((prev) => prev.length === 0 ? [[]] : prev);
@@ -3956,7 +4136,7 @@ var useA4StatementView = ({
3956
4136
  );
3957
4137
  }
3958
4138
  }, [depsString]);
3959
- useEffect10(() => {
4139
+ useEffect11(() => {
3960
4140
  if (!isMeasuring || filteredDisplayData.length === 0) return;
3961
4141
  const timer = setTimeout(() => {
3962
4142
  if (!measureContainerRef.current) return;
@@ -4026,24 +4206,22 @@ var useA4StatementView = ({
4026
4206
  }
4027
4207
  );
4028
4208
  const DisplayInfoGridEl = Array.isArray(info) && info.length > 0 ? /* @__PURE__ */ jsx28("div", { id: "a4-info-grid", className: "px-8", children: /* @__PURE__ */ jsx28(InfoGrid, { className: "mb-4", items: info, isLoading }) }) : null;
4029
- if (!isLoading && (error || !data || data.length === 0)) {
4030
- return /* @__PURE__ */ jsx28("div", { className: "flex flex-col relative w-full items-center justify-center p-8 min-h-96", children: /* @__PURE__ */ jsxs20("div", { className: "flex flex-col items-center justify-center p-12 bg-gray-50/50 dark:bg-zinc-900/30 rounded-2xl border border-dashed border-gray-300 dark:border-zinc-700 w-full max-w-xl text-center shadow-sm", children: [
4031
- error ? /* @__PURE__ */ jsx28("div", { className: "w-16 h-16 bg-red-100 dark:bg-red-500/10 rounded-full flex items-center justify-center mb-6", children: /* @__PURE__ */ jsx28(AlertCircle, { className: "w-8 h-8 text-red-600 dark:text-red-500" }) }) : /* @__PURE__ */ jsx28("div", { className: "w-16 h-16 bg-gray-200 dark:bg-zinc-800 rounded-full flex items-center justify-center mb-6", children: /* @__PURE__ */ jsx28(FileX, { className: "w-8 h-8 text-gray-500 dark:text-gray-400" }) }),
4032
- /* @__PURE__ */ jsx28("h3", { className: "text-xl font-bold text-gray-900 dark:text-white mb-2", children: error ? "Failed to Load Statement" : "No Records Found" }),
4033
- /* @__PURE__ */ jsx28("p", { className: "text-sm text-gray-500 dark:text-gray-400 max-w-xs mb-8 leading-relaxed", children: error ? typeof error === "string" ? error : "An unexpected error occurred while fetching the statement data." : "There are no transactions or records available in this requested statement." }),
4034
- url && /* @__PURE__ */ jsxs20(
4035
- "button",
4036
- {
4037
- onClick: () => get({ url, v, params, delay }),
4038
- className: "flex items-center gap-2 px-6 py-2.5 bg-black dark:bg-white text-white dark:text-black font-semibold rounded-lg shadow-md hover:bg-gray-800 dark:hover:bg-gray-100 transition-all active:scale-95",
4039
- children: [
4040
- /* @__PURE__ */ jsx28(RefreshCw, { size: 16 }),
4041
- "Try Again"
4042
- ]
4043
- }
4044
- )
4045
- ] }) });
4046
- }
4209
+ const emptyState = !isLoading && (error || !data || data.length === 0) ? /* @__PURE__ */ jsx28("div", { className: "flex flex-col relative w-full items-center justify-center py-12 min-h-[300px]", children: /* @__PURE__ */ jsxs20("div", { className: "flex flex-col items-center justify-center p-8 bg-gray-50/50 dark:bg-zinc-900/30 rounded-2xl border border-dashed border-gray-300 dark:border-zinc-700 w-full max-w-lg text-center shadow-sm", children: [
4210
+ error ? /* @__PURE__ */ jsx28("div", { className: "w-14 h-14 bg-red-100 dark:bg-red-500/10 rounded-full flex items-center justify-center mb-4", children: /* @__PURE__ */ jsx28(AlertCircle, { className: "w-7 h-7 text-red-600 dark:text-red-500" }) }) : /* @__PURE__ */ jsx28("div", { className: "w-14 h-14 bg-gray-200 dark:bg-zinc-800 rounded-full flex items-center justify-center mb-4", children: /* @__PURE__ */ jsx28(FileX, { className: "w-7 h-7 text-gray-500 dark:text-gray-400" }) }),
4211
+ /* @__PURE__ */ jsx28("h3", { className: "text-lg font-bold text-gray-900 dark:text-white mb-2", children: error ? "Failed to Load Statement" : "No Records Found" }),
4212
+ /* @__PURE__ */ jsx28("p", { className: "text-sm text-gray-500 dark:text-gray-400 max-w-xs mb-6 leading-relaxed", children: error ? typeof error === "string" ? error : "An unexpected error occurred while fetching the statement data." : "There are no transactions or records available in this requested statement." }),
4213
+ url && /* @__PURE__ */ jsxs20(
4214
+ "button",
4215
+ {
4216
+ onClick: () => get({ url, v, params, delay }),
4217
+ className: "flex items-center gap-2 px-5 py-2 bg-black dark:bg-white text-white dark:text-black font-semibold rounded-lg shadow-md hover:bg-gray-800 dark:hover:bg-gray-100 transition-all active:scale-95 text-sm",
4218
+ children: [
4219
+ /* @__PURE__ */ jsx28(RefreshCw, { size: 14 }),
4220
+ "Try Again"
4221
+ ]
4222
+ }
4223
+ )
4224
+ ] }) }) : void 0;
4047
4225
  return /* @__PURE__ */ jsxs20("div", { className: "flex flex-col relative w-full items-center", children: [
4048
4226
  isMeasuring && filteredDisplayData.length > 0 && /* @__PURE__ */ jsx28("div", { className: "absolute top-0 opacity-0 pointer-events-none -left-full", children: /* @__PURE__ */ jsx28(
4049
4227
  "div",
@@ -4138,7 +4316,7 @@ var useA4StatementView = ({
4138
4316
  ] }),
4139
4317
  pageIndex === 0 && /* @__PURE__ */ jsx28("div", { className: "hidden print:flex mb-4 border-b border-gray-200 print:border-gray-200 pb-2 items-center gap-2 justify-between px-2 mt-2", children: /* @__PURE__ */ jsx28("h3", { className: "text-sm font-bold text-gray-800 print:text-gray-800 uppercase tracking-wide shrink-0", children: "Recent Transactions" }) }),
4140
4318
  pageIndex > 0 && /* @__PURE__ */ jsx28("div", { className: "h-5 print:h-0" }),
4141
- (pageData.length > 0 || isLoading) && /* @__PURE__ */ jsx28(
4319
+ /* @__PURE__ */ jsx28(
4142
4320
  SimpleTable,
4143
4321
  {
4144
4322
  columns,
@@ -4148,6 +4326,7 @@ var useA4StatementView = ({
4148
4326
  index,
4149
4327
  startIndex: pages.slice(0, pageIndex).reduce((acc, curr) => acc + curr.length, 0),
4150
4328
  verticalLines,
4329
+ emptyState,
4151
4330
  isLoading: isLoading || isMeasuring && pages.length === 1 && pages[0].length === 0
4152
4331
  }
4153
4332
  ),
@@ -4175,7 +4354,7 @@ var A4DataView = (props) => {
4175
4354
  var useA4DataView_default = useA4StatementView;
4176
4355
 
4177
4356
  // src/hooks/Fetches/useTransaction.tsx
4178
- import { useEffect as useEffect11, useState as useState17 } from "react";
4357
+ import { useEffect as useEffect12, useState as useState17 } from "react";
4179
4358
  import { AlertCircle as AlertCircle2, FileX as FileX2, Plus as Plus2, RefreshCw as RefreshCw2 } from "lucide-react";
4180
4359
  import moment from "moment";
4181
4360
  import { jsx as jsx29, jsxs as jsxs21 } from "react/jsx-runtime";
@@ -4202,7 +4381,7 @@ var useTransaction = ({
4202
4381
  delay
4203
4382
  });
4204
4383
  };
4205
- useEffect11(() => {
4384
+ useEffect12(() => {
4206
4385
  getData();
4207
4386
  }, [url, v, JSON.stringify(params), delay, date]);
4208
4387
  const TransactionViewComponent = ({
@@ -4229,30 +4408,28 @@ var useTransaction = ({
4229
4408
  createTitle = "Add New",
4230
4409
  ...rest
4231
4410
  }) => {
4232
- if (!isLoading && (error || !data || data.length === 0)) {
4233
- return /* @__PURE__ */ jsx29(
4234
- "div",
4235
- {
4236
- className: `flex flex-col relative w-full items-center justify-center p-8 min-h-96 ${className}`,
4237
- children: /* @__PURE__ */ jsxs21("div", { className: "flex flex-col items-center justify-center p-12 bg-gray-50/50 dark:bg-zinc-900/30 rounded-2xl border border-dashed border-gray-300 dark:border-zinc-700 w-full max-w-xl text-center shadow-sm", children: [
4238
- error ? /* @__PURE__ */ jsx29("div", { className: "w-16 h-16 bg-red-100 dark:bg-red-500/10 rounded-full flex items-center justify-center mb-6", children: /* @__PURE__ */ jsx29(AlertCircle2, { className: "w-8 h-8 text-red-600 dark:text-red-500" }) }) : /* @__PURE__ */ jsx29("div", { className: "w-16 h-16 bg-gray-200 dark:bg-zinc-800 rounded-full flex items-center justify-center mb-6", children: /* @__PURE__ */ jsx29(FileX2, { className: "w-8 h-8 text-gray-500 dark:text-gray-400" }) }),
4239
- /* @__PURE__ */ jsx29("h3", { className: "text-xl font-bold text-gray-900 dark:text-white mb-2", children: error ? "Failed to Load Data" : "No Records Found" }),
4240
- /* @__PURE__ */ jsx29("p", { className: "text-sm text-gray-500 dark:text-gray-400 max-w-xs mb-8 leading-relaxed", children: error ? typeof error === "string" ? error : "An unexpected error occurred while fetching the data." : "There are no transactions or records available to display here." }),
4241
- url && /* @__PURE__ */ jsxs21(
4242
- "button",
4243
- {
4244
- onClick: () => get({ url, v, params, delay }),
4245
- className: "flex items-center gap-2 px-6 py-2.5 bg-black dark:bg-white text-white dark:text-black font-semibold rounded-lg shadow-md hover:bg-gray-800 dark:hover:bg-gray-100 transition-all active:scale-95",
4246
- children: [
4247
- /* @__PURE__ */ jsx29(RefreshCw2, { size: 16 }),
4248
- "Try Again"
4249
- ]
4250
- }
4251
- )
4252
- ] })
4253
- }
4254
- );
4255
- }
4411
+ const emptyState = !isLoading && (error || !data || data.length === 0) ? /* @__PURE__ */ jsx29(
4412
+ "div",
4413
+ {
4414
+ className: `flex flex-col relative w-full items-center justify-center py-12 min-h-[300px] ${className}`,
4415
+ children: /* @__PURE__ */ jsxs21("div", { className: "flex flex-col items-center justify-center p-8 bg-gray-50/50 dark:bg-zinc-900/30 rounded-2xl border border-dashed border-gray-300 dark:border-zinc-700 w-full max-w-lg text-center shadow-sm", children: [
4416
+ error ? /* @__PURE__ */ jsx29("div", { className: "w-14 h-14 bg-red-100 dark:bg-red-500/10 rounded-full flex items-center justify-center mb-4", children: /* @__PURE__ */ jsx29(AlertCircle2, { className: "w-7 h-7 text-red-600 dark:text-red-500" }) }) : /* @__PURE__ */ jsx29("div", { className: "w-14 h-14 bg-gray-200 dark:bg-zinc-800 rounded-full flex items-center justify-center mb-4", children: /* @__PURE__ */ jsx29(FileX2, { className: "w-7 h-7 text-gray-500 dark:text-gray-400" }) }),
4417
+ /* @__PURE__ */ jsx29("h3", { className: "text-lg font-bold text-gray-900 dark:text-white mb-2", children: error ? "Failed to Load Data" : "No Records Found" }),
4418
+ /* @__PURE__ */ jsx29("p", { className: "text-sm text-gray-500 dark:text-gray-400 max-w-xs mb-6 leading-relaxed", children: error ? typeof error === "string" ? error : "An unexpected error occurred while fetching the data." : "There are no transactions or records available to display here." }),
4419
+ url && /* @__PURE__ */ jsxs21(
4420
+ "button",
4421
+ {
4422
+ onClick: () => get({ url, v, params, delay }),
4423
+ className: "flex items-center gap-2 px-5 py-2 bg-black dark:bg-white text-white dark:text-black font-semibold rounded-lg shadow-md hover:bg-gray-800 dark:hover:bg-gray-100 transition-all active:scale-95 text-sm",
4424
+ children: [
4425
+ /* @__PURE__ */ jsx29(RefreshCw2, { size: 14 }),
4426
+ "Try Again"
4427
+ ]
4428
+ }
4429
+ )
4430
+ ] })
4431
+ }
4432
+ ) : void 0;
4256
4433
  return /* @__PURE__ */ jsxs21(Card, { children: [
4257
4434
  /* @__PURE__ */ jsx29(Card.Header, { children: /* @__PURE__ */ jsxs21("header", { className: "flex items-center justify-between gap-4 py-2", children: [
4258
4435
  /* @__PURE__ */ jsxs21("div", { className: "space-y-1", children: [
@@ -4296,6 +4473,7 @@ var useTransaction = ({
4296
4473
  verticalLines,
4297
4474
  index,
4298
4475
  rowPadding,
4476
+ emptyState,
4299
4477
  ...rest
4300
4478
  }
4301
4479
  ) }) })
@@ -4437,6 +4615,66 @@ var generatePdf = async (elementId, options = {}) => {
4437
4615
  throw error;
4438
4616
  }
4439
4617
  };
4618
+
4619
+ // src/utils/storage.ts
4620
+ var isBrowser = typeof window !== "undefined" && typeof localStorage !== "undefined";
4621
+ var storage = {
4622
+ set(key, value) {
4623
+ if (!isBrowser) return;
4624
+ try {
4625
+ localStorage.setItem(key, JSON.stringify(value));
4626
+ } catch (error) {
4627
+ console.error(`[storage] Error saving key "${key}":`, error);
4628
+ }
4629
+ },
4630
+ get(key) {
4631
+ if (!isBrowser) return key ? null : {};
4632
+ if (key !== void 0) {
4633
+ try {
4634
+ const item = localStorage.getItem(key);
4635
+ if (item === null) return null;
4636
+ return JSON.parse(item);
4637
+ } catch (error) {
4638
+ const rawValue = localStorage.getItem(key);
4639
+ return rawValue;
4640
+ }
4641
+ }
4642
+ const allItems = {};
4643
+ for (let i = 0; i < localStorage.length; i++) {
4644
+ const k = localStorage.key(i);
4645
+ if (k) {
4646
+ const value = localStorage.getItem(k);
4647
+ try {
4648
+ allItems[k] = value ? JSON.parse(value) : null;
4649
+ } catch {
4650
+ allItems[k] = value;
4651
+ }
4652
+ }
4653
+ }
4654
+ return allItems;
4655
+ },
4656
+ remove(key) {
4657
+ if (!isBrowser) return;
4658
+ localStorage.removeItem(key);
4659
+ },
4660
+ clear() {
4661
+ if (!isBrowser) return;
4662
+ localStorage.clear();
4663
+ },
4664
+ has(key) {
4665
+ if (!isBrowser) return false;
4666
+ return localStorage.getItem(key) !== null;
4667
+ },
4668
+ keys() {
4669
+ if (!isBrowser) return [];
4670
+ const keys = [];
4671
+ for (let i = 0; i < localStorage.length; i++) {
4672
+ const key = localStorage.key(i);
4673
+ if (key) keys.push(key);
4674
+ }
4675
+ return keys;
4676
+ }
4677
+ };
4440
4678
  export {
4441
4679
  A4DataView,
4442
4680
  Badge,
@@ -4479,6 +4717,7 @@ export {
4479
4717
  ThemeToggle,
4480
4718
  WarqadProvider,
4481
4719
  generatePdf,
4720
+ storage,
4482
4721
  useA4DataView_default as useA4StatementView,
4483
4722
  useApis_default as useApi,
4484
4723
  useModal,