import { r as reactExports, U as jsxRuntimeExports } from "./worker-entry-Xz__m-MI.js";
import { u as useSuspenseQuery } from "./useSuspenseQuery-CUxLKZvE.js";
import { h as businessSettingsQueryOptions, i as useQueryClient, e as deliverySettingsQueryOptions, j as paymentSettingsQueryOptions, t as toast, s as supabase, k as DEFAULT_BUSINESS_SETTINGS, D as DEFAULT_DELIVERY_SETTINGS } from "./router-CHpUX3w1.js";
import { C as Card } from "./card-Cu-N09iC.js";
import { I as Input } from "./input-79qqvIMV.js";
import { L as Label } from "./label-BQmy2bHJ.js";
import { B as Button } from "./button-DpKP5ewx.js";
import { U as Upload, S as Switch, u as uploadProductImage } from "./upload-DM4WBTnj.js";
import { a as Smartphone, S as Separator } from "./separator-QYwxpaB0.js";
import { T as Textarea } from "./textarea-CV9jx0-G.js";
import { e as useControllableState, b as Primitive, f as useId, a as composeEventHandlers, P as Presence, c as createContextScope } from "./index-P9m2NEcT.js";
import { R as Root, I as Item, c as createRovingFocusGroupScope } from "./index-C7lwDevP.js";
import { u as useDirection } from "./index-BGCFm29u.js";
import { c as cn } from "./utils-Bz4m9VPB.js";
import { S as Store } from "./store-CVl2rX4g.js";
import { T as Truck } from "./truck-z30CqIo1.js";
import { L as LoaderCircle } from "./loader-circle-ON2Oh-nH.js";
import { c as createLucideIcon } from "./createLucideIcon-4cZKQB6y.js";
import "node:events";
import "node:async_hooks";
import "node:stream/web";
import "node:stream";
import "./index-GGTY6NM3.js";
const __iconNode$1 = [
  [
    "path",
    {
      d: "M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z",
      key: "e79jfc"
    }
  ],
  ["circle", { cx: "13.5", cy: "6.5", r: ".5", fill: "currentColor", key: "1okk4w" }],
  ["circle", { cx: "17.5", cy: "10.5", r: ".5", fill: "currentColor", key: "f64h9f" }],
  ["circle", { cx: "6.5", cy: "12.5", r: ".5", fill: "currentColor", key: "qy21gx" }],
  ["circle", { cx: "8.5", cy: "7.5", r: ".5", fill: "currentColor", key: "fotxhn" }]
];
const Palette = createLucideIcon("palette", __iconNode$1);
const __iconNode = [
  [
    "path",
    {
      d: "M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",
      key: "1c8476"
    }
  ],
  ["path", { d: "M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7", key: "1ydtos" }],
  ["path", { d: "M7 3v4a1 1 0 0 0 1 1h7", key: "t51u73" }]
];
const Save = createLucideIcon("save", __iconNode);
var TABS_NAME = "Tabs";
var [createTabsContext] = createContextScope(TABS_NAME, [
  createRovingFocusGroupScope
]);
var useRovingFocusGroupScope = createRovingFocusGroupScope();
var [TabsProvider, useTabsContext] = createTabsContext(TABS_NAME);
var Tabs$1 = reactExports.forwardRef(
  (props, forwardedRef) => {
    const {
      __scopeTabs,
      value: valueProp,
      onValueChange,
      defaultValue,
      orientation = "horizontal",
      dir,
      activationMode = "automatic",
      ...tabsProps
    } = props;
    const direction = useDirection(dir);
    const [value, setValue] = useControllableState({
      prop: valueProp,
      onChange: onValueChange,
      defaultProp: defaultValue ?? "",
      caller: TABS_NAME
    });
    return /* @__PURE__ */ jsxRuntimeExports.jsx(
      TabsProvider,
      {
        scope: __scopeTabs,
        baseId: useId(),
        value,
        onValueChange: setValue,
        orientation,
        dir: direction,
        activationMode,
        children: /* @__PURE__ */ jsxRuntimeExports.jsx(
          Primitive.div,
          {
            dir: direction,
            "data-orientation": orientation,
            ...tabsProps,
            ref: forwardedRef
          }
        )
      }
    );
  }
);
Tabs$1.displayName = TABS_NAME;
var TAB_LIST_NAME = "TabsList";
var TabsList$1 = reactExports.forwardRef(
  (props, forwardedRef) => {
    const { __scopeTabs, loop = true, ...listProps } = props;
    const context = useTabsContext(TAB_LIST_NAME, __scopeTabs);
    const rovingFocusGroupScope = useRovingFocusGroupScope(__scopeTabs);
    return /* @__PURE__ */ jsxRuntimeExports.jsx(
      Root,
      {
        asChild: true,
        ...rovingFocusGroupScope,
        orientation: context.orientation,
        dir: context.dir,
        loop,
        children: /* @__PURE__ */ jsxRuntimeExports.jsx(
          Primitive.div,
          {
            role: "tablist",
            "aria-orientation": context.orientation,
            ...listProps,
            ref: forwardedRef
          }
        )
      }
    );
  }
);
TabsList$1.displayName = TAB_LIST_NAME;
var TRIGGER_NAME = "TabsTrigger";
var TabsTrigger$1 = reactExports.forwardRef(
  (props, forwardedRef) => {
    const { __scopeTabs, value, disabled = false, ...triggerProps } = props;
    const context = useTabsContext(TRIGGER_NAME, __scopeTabs);
    const rovingFocusGroupScope = useRovingFocusGroupScope(__scopeTabs);
    const triggerId = makeTriggerId(context.baseId, value);
    const contentId = makeContentId(context.baseId, value);
    const isSelected = value === context.value;
    return /* @__PURE__ */ jsxRuntimeExports.jsx(
      Item,
      {
        asChild: true,
        ...rovingFocusGroupScope,
        focusable: !disabled,
        active: isSelected,
        children: /* @__PURE__ */ jsxRuntimeExports.jsx(
          Primitive.button,
          {
            type: "button",
            role: "tab",
            "aria-selected": isSelected,
            "aria-controls": contentId,
            "data-state": isSelected ? "active" : "inactive",
            "data-disabled": disabled ? "" : void 0,
            disabled,
            id: triggerId,
            ...triggerProps,
            ref: forwardedRef,
            onMouseDown: composeEventHandlers(props.onMouseDown, (event) => {
              if (!disabled && event.button === 0 && event.ctrlKey === false) {
                context.onValueChange(value);
              } else {
                event.preventDefault();
              }
            }),
            onKeyDown: composeEventHandlers(props.onKeyDown, (event) => {
              if ([" ", "Enter"].includes(event.key)) context.onValueChange(value);
            }),
            onFocus: composeEventHandlers(props.onFocus, () => {
              const isAutomaticActivation = context.activationMode !== "manual";
              if (!isSelected && !disabled && isAutomaticActivation) {
                context.onValueChange(value);
              }
            })
          }
        )
      }
    );
  }
);
TabsTrigger$1.displayName = TRIGGER_NAME;
var CONTENT_NAME = "TabsContent";
var TabsContent$1 = reactExports.forwardRef(
  (props, forwardedRef) => {
    const { __scopeTabs, value, forceMount, children, ...contentProps } = props;
    const context = useTabsContext(CONTENT_NAME, __scopeTabs);
    const triggerId = makeTriggerId(context.baseId, value);
    const contentId = makeContentId(context.baseId, value);
    const isSelected = value === context.value;
    const isMountAnimationPreventedRef = reactExports.useRef(isSelected);
    reactExports.useEffect(() => {
      const rAF = requestAnimationFrame(() => isMountAnimationPreventedRef.current = false);
      return () => cancelAnimationFrame(rAF);
    }, []);
    return /* @__PURE__ */ jsxRuntimeExports.jsx(Presence, { present: forceMount || isSelected, children: ({ present }) => /* @__PURE__ */ jsxRuntimeExports.jsx(
      Primitive.div,
      {
        "data-state": isSelected ? "active" : "inactive",
        "data-orientation": context.orientation,
        role: "tabpanel",
        "aria-labelledby": triggerId,
        hidden: !present,
        id: contentId,
        tabIndex: 0,
        ...contentProps,
        ref: forwardedRef,
        style: {
          ...props.style,
          animationDuration: isMountAnimationPreventedRef.current ? "0s" : void 0
        },
        children: present && children
      }
    ) });
  }
);
TabsContent$1.displayName = CONTENT_NAME;
function makeTriggerId(baseId, value) {
  return `${baseId}-trigger-${value}`;
}
function makeContentId(baseId, value) {
  return `${baseId}-content-${value}`;
}
var Root2 = Tabs$1;
var List = TabsList$1;
var Trigger = TabsTrigger$1;
var Content = TabsContent$1;
const Tabs = Root2;
const TabsList = reactExports.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntimeExports.jsx(
  List,
  {
    ref,
    className: cn(
      "inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground",
      className
    ),
    ...props
  }
));
TabsList.displayName = List.displayName;
const TabsTrigger = reactExports.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntimeExports.jsx(
  Trigger,
  {
    ref,
    className: cn(
      "inline-flex items-center justify-center whitespace-nowrap rounded-md px-3 py-1 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow",
      className
    ),
    ...props
  }
));
TabsTrigger.displayName = Trigger.displayName;
const TabsContent = reactExports.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntimeExports.jsx(
  Content,
  {
    ref,
    className: cn(
      "mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
      className
    ),
    ...props
  }
));
TabsContent.displayName = Content.displayName;
function SettingsPage() {
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx("h1", { className: "text-2xl font-semibold mb-6", children: "সেটিংস" }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs(Tabs, { defaultValue: "business", className: "max-w-3xl", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs(TabsList, { children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs(TabsTrigger, { value: "business", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Store, { className: "h-4 w-4 mr-2" }),
          " বিজনেস"
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs(TabsTrigger, { value: "delivery", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Truck, { className: "h-4 w-4 mr-2" }),
          " ডেলিভারি"
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs(TabsTrigger, { value: "payment", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Smartphone, { className: "h-4 w-4 mr-2" }),
          " পেমেন্ট"
        ] })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(TabsContent, { value: "business", className: "mt-4", children: /* @__PURE__ */ jsxRuntimeExports.jsx(reactExports.Suspense, { fallback: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-muted-foreground", children: "লোড হচ্ছে..." }), children: /* @__PURE__ */ jsxRuntimeExports.jsx(BusinessSettingsCard, {}) }) }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(TabsContent, { value: "delivery", className: "mt-4", children: /* @__PURE__ */ jsxRuntimeExports.jsx(reactExports.Suspense, { fallback: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-muted-foreground", children: "লোড হচ্ছে..." }), children: /* @__PURE__ */ jsxRuntimeExports.jsx(DeliverySettingsCard, {}) }) }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(TabsContent, { value: "payment", className: "mt-4", children: /* @__PURE__ */ jsxRuntimeExports.jsx(reactExports.Suspense, { fallback: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-muted-foreground", children: "লোড হচ্ছে..." }), children: /* @__PURE__ */ jsxRuntimeExports.jsx(PaymentSettingsCard, {}) }) })
    ] })
  ] });
}
function BusinessSettingsCard() {
  const {
    data
  } = useSuspenseQuery(businessSettingsQueryOptions());
  const queryClient = useQueryClient();
  const [form, setForm] = reactExports.useState(data);
  const [saving, setSaving] = reactExports.useState(false);
  const [uploading, setUploading] = reactExports.useState(null);
  reactExports.useEffect(() => {
    setForm(data);
  }, [data]);
  const update = (key, value) => setForm((p) => ({
    ...p,
    [key]: value
  }));
  const uploadAsset = async (file, kind) => {
    setUploading(kind);
    try {
      const url = await uploadProductImage(file, "business");
      update(kind === "logo" ? "logo_url" : "favicon_url", url);
      toast.success("ছবি আপলোড হয়েছে");
    } catch (e) {
      toast.error("আপলোড ব্যর্থ", {
        description: e.message
      });
    } finally {
      setUploading(null);
    }
  };
  const handleSave = async () => {
    if (!form.site_name.trim()) {
      toast.error("সাইটের নাম দিন");
      return;
    }
    if (!/^#[0-9a-fA-F]{6}$/.test(form.primary_color)) {
      toast.error("কালার অবশ্যই #RRGGBB ফরম্যাটে হতে হবে");
      return;
    }
    setSaving(true);
    const {
      error
    } = await supabase.from("app_settings").upsert({
      key: "business",
      value: form
    });
    setSaving(false);
    if (error) {
      toast.error("সেভ করতে সমস্যা", {
        description: error.message
      });
      return;
    }
    toast.success("বিজনেস সেটিংস আপডেট হয়েছে");
    queryClient.invalidateQueries({
      queryKey: ["settings", "business"]
    });
  };
  const handleReset = () => setForm(DEFAULT_BUSINESS_SETTINGS);
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(Card, { className: "p-6", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-start gap-3 mb-6", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-10 w-10 rounded-lg bg-primary/10 text-primary flex items-center justify-center", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Store, { className: "h-5 w-5" }) }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx("h2", { className: "text-lg font-semibold", children: "বিজনেস ইনফরমেশন" }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-muted-foreground", children: "সাইটের নাম, লোগো, ফ্যাভিকন ও থিম কালার এখান থেকে নিয়ন্ত্রণ করুন।" })
      ] })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-5", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-2", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs(Label, { htmlFor: "site-name", children: [
          "সাইটের নাম ",
          /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-destructive", children: "*" })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(Input, { id: "site-name", value: form.site_name, onChange: (e) => update("site_name", e.target.value), placeholder: "BarakShop" })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-2", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(Label, { htmlFor: "tagline", children: "ট্যাগলাইন" }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(Input, { id: "tagline", value: form.tagline, onChange: (e) => update("tagline", e.target.value), placeholder: "আপনার পছন্দের সব কিছু এক জায়গায়" })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Separator, {}),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-2", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(Label, { children: "লোগো" }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-4", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-16 w-32 rounded border bg-muted flex items-center justify-center overflow-hidden", children: form.logo_url ? /* @__PURE__ */ jsxRuntimeExports.jsx("img", { src: form.logo_url, alt: "logo", className: "max-h-full max-w-full object-contain" }) : /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-xs text-muted-foreground", children: "No logo" }) }),
          /* @__PURE__ */ jsxRuntimeExports.jsxs("label", { className: "flex-1", children: [
            /* @__PURE__ */ jsxRuntimeExports.jsx("input", { type: "file", accept: "image/*", className: "hidden", onChange: (e) => {
              const f = e.target.files?.[0];
              if (f) uploadAsset(f, "logo");
            } }),
            /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "border-2 border-dashed rounded-md py-3 px-4 text-sm text-muted-foreground hover:border-primary cursor-pointer flex items-center gap-2", children: uploading === "logo" ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
              /* @__PURE__ */ jsxRuntimeExports.jsx(LoaderCircle, { className: "h-4 w-4 animate-spin" }),
              " আপলোড হচ্ছে..."
            ] }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
              /* @__PURE__ */ jsxRuntimeExports.jsx(Upload, { className: "h-4 w-4" }),
              " লোগো আপলোড করুন"
            ] }) })
          ] }),
          form.logo_url && /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { variant: "ghost", size: "sm", onClick: () => update("logo_url", ""), children: "সরান" })
        ] })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-2", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(Label, { children: "ফ্যাভিকন (ব্রাউজার আইকন)" }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-4", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-12 w-12 rounded border bg-muted flex items-center justify-center overflow-hidden", children: form.favicon_url ? /* @__PURE__ */ jsxRuntimeExports.jsx("img", { src: form.favicon_url, alt: "favicon", className: "max-h-full max-w-full object-contain" }) : /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-[10px] text-muted-foreground", children: "None" }) }),
          /* @__PURE__ */ jsxRuntimeExports.jsxs("label", { className: "flex-1", children: [
            /* @__PURE__ */ jsxRuntimeExports.jsx("input", { type: "file", accept: "image/*,.ico", className: "hidden", onChange: (e) => {
              const f = e.target.files?.[0];
              if (f) uploadAsset(f, "favicon");
            } }),
            /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "border-2 border-dashed rounded-md py-3 px-4 text-sm text-muted-foreground hover:border-primary cursor-pointer flex items-center gap-2", children: uploading === "favicon" ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
              /* @__PURE__ */ jsxRuntimeExports.jsx(LoaderCircle, { className: "h-4 w-4 animate-spin" }),
              " আপলোড হচ্ছে..."
            ] }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
              /* @__PURE__ */ jsxRuntimeExports.jsx(Upload, { className: "h-4 w-4" }),
              " ফ্যাভিকন আপলোড করুন"
            ] }) })
          ] }),
          form.favicon_url && /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { variant: "ghost", size: "sm", onClick: () => update("favicon_url", ""), children: "সরান" })
        ] })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Separator, {}),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-2", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(Label, { htmlFor: "color", children: "প্রাইমারি কালার" }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-3", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx("input", { type: "color", value: form.primary_color, onChange: (e) => update("primary_color", e.target.value), className: "h-10 w-16 rounded border cursor-pointer" }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(Input, { id: "color", value: form.primary_color, onChange: (e) => update("primary_color", e.target.value), placeholder: "#e11d48", className: "font-mono w-40", maxLength: 7 }),
          /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex-1 rounded-md border h-10 flex items-center justify-center text-sm font-medium text-white", style: {
            background: form.primary_color
          }, children: [
            /* @__PURE__ */ jsxRuntimeExports.jsx(Palette, { className: "h-4 w-4 mr-2" }),
            " Preview"
          ] })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-muted-foreground", children: "পুরো ওয়েবসাইটের বাটন, লিংক ও অ্যাকসেন্ট এই কালার ব্যবহার করবে।" })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Separator, {}),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid sm:grid-cols-2 gap-4", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-2", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Label, { htmlFor: "wa", children: "WhatsApp নম্বর" }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(Input, { id: "wa", value: form.whatsapp_number, onChange: (e) => update("whatsapp_number", e.target.value), placeholder: "01XXXXXXXXX" })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-2", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Label, { htmlFor: "email", children: "সাপোর্ট ইমেইল" }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(Input, { id: "email", type: "email", value: form.support_email, onChange: (e) => update("support_email", e.target.value), placeholder: "support@example.com" })
        ] })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex gap-2 pt-2", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { onClick: handleSave, disabled: saving, className: "flex-1", children: saving ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(LoaderCircle, { className: "h-4 w-4 mr-2 animate-spin" }),
          " সেভ হচ্ছে..."
        ] }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Save, { className: "h-4 w-4 mr-2" }),
          " সেভ করুন"
        ] }) }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { type: "button", variant: "outline", onClick: handleReset, disabled: saving, children: "ডিফল্ট" })
      ] })
    ] })
  ] });
}
function DeliverySettingsCard() {
  const {
    data
  } = useSuspenseQuery(deliverySettingsQueryOptions());
  const queryClient = useQueryClient();
  const [form, setForm] = reactExports.useState(data);
  const [saving, setSaving] = reactExports.useState(false);
  reactExports.useEffect(() => {
    setForm(data);
  }, [data]);
  const update = (key, value) => setForm((p) => ({
    ...p,
    [key]: value
  }));
  const handleSave = async () => {
    if (form.inside_dhaka < 0 || form.outside_dhaka < 0 || form.free_delivery_threshold < 0) {
      toast.error("চার্জ ০ বা তার বেশি হতে হবে");
      return;
    }
    setSaving(true);
    const {
      error
    } = await supabase.from("app_settings").upsert({
      key: "delivery",
      value: form
    });
    setSaving(false);
    if (error) {
      toast.error("সেভ করতে সমস্যা হয়েছে", {
        description: error.message
      });
      return;
    }
    toast.success("ডেলিভারি সেটিংস আপডেট হয়েছে");
    queryClient.invalidateQueries({
      queryKey: ["settings", "delivery"]
    });
  };
  const handleReset = () => setForm(DEFAULT_DELIVERY_SETTINGS);
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(Card, { className: "p-6", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-start gap-3 mb-6", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-10 w-10 rounded-lg bg-primary/10 text-primary flex items-center justify-center", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Truck, { className: "h-5 w-5" }) }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx("h2", { className: "text-lg font-semibold", children: "ডেলিভারি চার্জ" }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-muted-foreground", children: "অর্ডার ফর্মে কাস্টমার যে চার্জ দেখবেন এবং প্রদান করবেন সেটি এখান থেকে নিয়ন্ত্রণ করুন।" })
      ] })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-5", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid sm:grid-cols-2 gap-4", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-2", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Label, { htmlFor: "inside", children: "ঢাকার ভিতরে (৳)" }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(Input, { id: "inside", type: "number", min: 0, value: form.inside_dhaka, onChange: (e) => update("inside_dhaka", Number(e.target.value)), disabled: form.free_delivery })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-2", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Label, { htmlFor: "outside", children: "ঢাকার বাইরে (৳)" }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(Input, { id: "outside", type: "number", min: 0, value: form.outside_dhaka, onChange: (e) => update("outside_dhaka", Number(e.target.value)), disabled: form.free_delivery })
        ] })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Separator, {}),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-start justify-between gap-4 rounded-lg bg-muted/50 p-4", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex-1", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Label, { htmlFor: "free", className: "text-base font-semibold cursor-pointer", children: "সব অর্ডারে ফ্রি ডেলিভারি" }),
          /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-muted-foreground mt-1", children: "চালু করলে শহর নির্বিশেষে সব অর্ডারে শিপিং চার্জ ০ হবে।" })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(Switch, { id: "free", checked: form.free_delivery, onCheckedChange: (v) => update("free_delivery", v) })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-2", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(Label, { htmlFor: "threshold", children: "ফ্রি ডেলিভারি থ্রেশহোল্ড (৳)" }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(Input, { id: "threshold", type: "number", min: 0, value: form.free_delivery_threshold, onChange: (e) => update("free_delivery_threshold", Number(e.target.value)), disabled: form.free_delivery }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-muted-foreground", children: "অর্ডারের পরিমাণ এই মূল্যের সমান বা বেশি হলে ফ্রি ডেলিভারি। ০ দিলে নিষ্ক্রিয়।" })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex gap-2 pt-2", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { onClick: handleSave, disabled: saving, className: "flex-1", children: saving ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(LoaderCircle, { className: "h-4 w-4 mr-2 animate-spin" }),
          " সেভ হচ্ছে..."
        ] }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Save, { className: "h-4 w-4 mr-2" }),
          " সেভ করুন"
        ] }) }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { type: "button", variant: "outline", onClick: handleReset, disabled: saving, children: "ডিফল্ট" })
      ] })
    ] })
  ] });
}
function PaymentSettingsCard() {
  const {
    data
  } = useSuspenseQuery(paymentSettingsQueryOptions());
  const queryClient = useQueryClient();
  const [form, setForm] = reactExports.useState(data);
  const [saving, setSaving] = reactExports.useState(false);
  reactExports.useEffect(() => {
    setForm(data);
  }, [data]);
  const handleSave = async () => {
    if (!/^\+?[0-9]{10,15}$/.test(form.bkash_number.trim())) {
      toast.error("সঠিক বিকাশ নম্বর দিন");
      return;
    }
    setSaving(true);
    const {
      error
    } = await supabase.from("app_settings").upsert({
      key: "payment",
      value: form
    });
    setSaving(false);
    if (error) {
      toast.error("সেভ করতে সমস্যা হয়েছে", {
        description: error.message
      });
      return;
    }
    toast.success("পেমেন্ট সেটিংস আপডেট হয়েছে");
    queryClient.invalidateQueries({
      queryKey: ["settings", "payment"]
    });
  };
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(Card, { className: "p-6", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-start gap-3 mb-6", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-10 w-10 rounded-lg bg-pink-100 text-pink-600 flex items-center justify-center", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Smartphone, { className: "h-5 w-5" }) }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx("h2", { className: "text-lg font-semibold", children: "বিকাশ পেমেন্ট" }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-muted-foreground", children: "যেসব কাস্টমারের পূর্বে অর্ডার বাতিল হয়েছে তাদের অগ্রিম পেমেন্টের জন্য এই নম্বর দেখানো হবে।" })
      ] })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-2", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs(Label, { htmlFor: "bkash", children: [
          "বিকাশ নম্বর ",
          /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-destructive", children: "*" })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(Input, { id: "bkash", value: form.bkash_number, onChange: (e) => setForm((p) => ({
          ...p,
          bkash_number: e.target.value
        })), placeholder: "01XXXXXXXXX", maxLength: 15, className: "font-mono" })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-2", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(Label, { htmlFor: "type", children: "অ্যাকাউন্ট টাইপ" }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("select", { id: "type", value: form.bkash_type, onChange: (e) => setForm((p) => ({
          ...p,
          bkash_type: e.target.value
        })), className: "flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx("option", { value: "personal", children: "Personal (Send Money)" }),
          /* @__PURE__ */ jsxRuntimeExports.jsx("option", { value: "merchant", children: "Merchant (Payment)" })
        ] })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-2", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(Label, { htmlFor: "instructions", children: "কাস্টমারের জন্য নির্দেশনা" }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(Textarea, { id: "instructions", value: form.instructions, onChange: (e) => setForm((p) => ({
          ...p,
          instructions: e.target.value
        })), rows: 3, maxLength: 500 })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "rounded-lg border-2 border-pink-200 bg-pink-50/50 p-4", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-pink-700 font-semibold uppercase tracking-wide mb-2", children: "প্রিভিউ" }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "font-mono text-lg font-bold text-pink-900", children: form.bkash_number }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-pink-700 mt-1 capitalize", children: form.bkash_type })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { onClick: handleSave, disabled: saving, className: "w-full", children: saving ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(LoaderCircle, { className: "h-4 w-4 mr-2 animate-spin" }),
        " সেভ হচ্ছে..."
      ] }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(Save, { className: "h-4 w-4 mr-2" }),
        " সেভ করুন"
      ] }) })
    ] })
  ] });
}
export {
  SettingsPage as component
};
