"use client";
import { jsxs as s, jsx as r } from "react/jsx-runtime";
import { Popover as n } from "../../shared/popover.js";
import { useAppDispatch as C } from "../../../hooks/use-app-dispatch.js";
import { useAppSelector as S } from "../../../hooks/use-app-selector.js";
import { getActiveTheme as T } from "../../../../../../store/selectors.js";
import { setActiveThemeSettings as j } from "../../../store/theme-slice.js";
import { useState as A, useCallback as f } from "react";
import t from "../../../../../../node_modules/.pnpm/react-hot-toast@2.5.2_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/react-hot-toast/dist/index.js";
import { AiOutlineImport as N, AiOutlineExport as E } from "../../../../../../node_modules/.pnpm/react-icons@5.5.0_react@19.0.0/node_modules/react-icons/ai/index.js";
import { BsThreeDots as F } from "../../../../../../node_modules/.pnpm/react-icons@5.5.0_react@19.0.0/node_modules/react-icons/bs/index.js";
import { FiSave as k } from "../../../../../../node_modules/.pnpm/react-icons@5.5.0_react@19.0.0/node_modules/react-icons/fi/index.js";
const V = () => {
  const i = S(T), p = C(), [u, c] = A(!1), x = () => {
    console.log("Saving theme...");
  }, v = async () => {
    try {
      c(!0), await x(), c(!1), t.success("Theme settings saved successfully");
    } catch {
      c(!1), t.error("Failed to save theme settings.");
    }
  }, b = f(() => {
    if (!(typeof document > "u"))
      try {
        const e = JSON.stringify(i.settings), m = new Blob([e], { type: "application/json" }), a = URL.createObjectURL(m), o = document.createElement("a");
        o.href = a, o.download = `theme-${i.name.toLowerCase().split(" ").join("-")}-${Date.now()}.json`, o.click(), t.success("Theme settings exported successfully");
      } catch (e) {
        console.error("Error exporting theme settings:", e), t.error("Failed to export theme settings");
      }
  }, [i.settings, i.name, t]), y = f(() => {
    if (!(typeof document > "u"))
      try {
        const e = document.createElement("input");
        e.type = "file", e.accept = "application/json", e.onchange = (m) => {
          var h;
          const a = (h = m.target.files) == null ? void 0 : h[0];
          if (!a)
            return;
          const o = new FileReader();
          o.readAsText(a, "UTF-8"), o.onload = (w) => {
            var g;
            try {
              const l = (g = w.target) == null ? void 0 : g.result;
              if (!l)
                return;
              const d = JSON.parse(l.toString());
              if (!d.color && !d.typography) {
                t.error("Invalid theme settings format");
                return;
              }
              p(j(d)), t.success("Theme settings imported successfully");
            } catch (l) {
              console.error("Error parsing imported theme settings:", l), t.error("Failed to parse imported theme settings");
            }
          };
        }, e.click();
      } catch (e) {
        console.error("Error importing theme settings:", e), t.error("Failed to import theme settings");
      }
  }, [p, t]);
  return /* @__PURE__ */ s("div", { className: "flex h-9 divide-x divide-indigo-700 overflow-hidden rounded-sm bg-slate-900 text-white", children: [
    /* @__PURE__ */ s(
      "button",
      {
        className: "flex h-full grow items-center justify-center gap-2 px-5 text-sm enabled:hover:bg-indigo-700 disabled:cursor-not-allowed disabled:opacity-50",
        onClick: v,
        disabled: u,
        children: [
          /* @__PURE__ */ r(k, { size: 16 }),
          "Save Changes"
        ]
      }
    ),
    /* @__PURE__ */ s(n, { modal: !0, children: [
      /* @__PURE__ */ r(n.Trigger, { asChild: !0, children: /* @__PURE__ */ r("button", { className: "h-full px-2.5 enabled:hover:bg-indigo-700", children: /* @__PURE__ */ r(F, {}) }) }),
      /* @__PURE__ */ r(n.Portal, { children: /* @__PURE__ */ s(n.Content, { className: "w-[160px] overflow-hidden bg-slate-800 px-0 py-1", align: "end", children: [
        /* @__PURE__ */ s(
          n.Close,
          {
            onClick: y,
            className: "flex w-full items-center gap-2 px-4 py-2 text-sm text-slate-100 enabled:hover:bg-slate-700",
            children: [
              /* @__PURE__ */ r(N, {}),
              " Import Settings"
            ]
          }
        ),
        /* @__PURE__ */ s(
          n.Close,
          {
            onClick: b,
            className: "flex w-full items-center gap-2 px-4 py-2 text-sm text-slate-100 enabled:hover:bg-slate-700",
            children: [
              /* @__PURE__ */ r(E, {}),
              " Export Settings"
            ]
          }
        )
      ] }) })
    ] })
  ] });
};
export {
  V as default
};
//# sourceMappingURL=theme-action-dropdown.js.map
