// src/lib/hooks/use-breakpoint.ts
import { useSyncExternalStore } from "react";
var screens = {
  sm: "640px",
  md: "768px",
  lg: "1024px",
  xl: "1280px",
  "2xl": "1536px"
};
var useBreakpoint = (size) => {
  return useSyncExternalStore(
    (onStoreChange) => {
      if (typeof window === "undefined") {
        return () => {
        };
      }
      const breakpoint = window.matchMedia(`(min-width: ${screens[size]})`);
      breakpoint.addEventListener("change", onStoreChange);
      return () => breakpoint.removeEventListener("change", onStoreChange);
    },
    () => {
      if (typeof window === "undefined") {
        return true;
      }
      return window.matchMedia(`(min-width: ${screens[size]})`).matches;
    },
    () => true
  );
};

// src/lib/hooks/use-clipboard.ts
import { useCallback, useState } from "react";
var DEFAULT_TIMEOUT = 2e3;
var useClipboard = () => {
  const [copied, setCopied] = useState(false);
  const fallback = (text, id) => {
    try {
      const textArea = document.createElement("textarea");
      textArea.value = text;
      textArea.style.position = "absolute";
      textArea.style.left = "-99999px";
      document.body.appendChild(textArea);
      textArea.select();
      const success = document.execCommand("copy");
      textArea.remove();
      setCopied(id || true);
      setTimeout(() => setCopied(false), DEFAULT_TIMEOUT);
      return success ? { success: true } : { success: false, error: new Error("execCommand returned false") };
    } catch (err) {
      return {
        success: false,
        error: err instanceof Error ? err : new Error("Fallback copy failed")
      };
    }
  };
  const copy = useCallback(async (text, id) => {
    if (navigator.clipboard && window.isSecureContext) {
      try {
        await navigator.clipboard.writeText(text);
        setCopied(id || true);
        setTimeout(() => setCopied(false), DEFAULT_TIMEOUT);
        return { success: true };
      } catch (e) {
        return fallback(text, id);
      }
    }
    return fallback(text);
  }, []);
  return { copied, copy };
};

// src/lib/hooks/use-resize-observer.ts
import { useEffect } from "react";
function hasResizeObserver() {
  return typeof window.ResizeObserver !== "undefined";
}
function useResizeObserver(options) {
  const { ref, box, onResize } = options;
  useEffect(() => {
    const element = ref == null ? void 0 : ref.current;
    if (!element) {
      return;
    }
    if (!hasResizeObserver()) {
      window.addEventListener("resize", onResize, false);
      return () => {
        window.removeEventListener("resize", onResize, false);
      };
    } else {
      const resizeObserverInstance = new window.ResizeObserver((entries) => {
        if (!entries.length) {
          return;
        }
        onResize();
      });
      resizeObserverInstance.observe(element, { box });
      return () => {
        if (element) {
          resizeObserverInstance.unobserve(element);
        }
      };
    }
  }, [onResize, ref, box]);
}

// src/lib/hooks/use-image-cycle.ts
import { useState as useState2, useEffect as useEffect2, useMemo } from "react";
var CYCLE_INTERVAL_MIN_MS = 6e3;
var CYCLE_INTERVAL_MAX_MS = 8e3;
var CROSSFADE_DURATION_MS = 600;
function seedToUnit(seed) {
  let h = 2166136261 >>> 0;
  for (let i = 0; i < seed.length; i++) {
    h ^= seed.charCodeAt(i);
    h = Math.imul(h, 16777619) >>> 0 >>> 0;
  }
  return (h >>> 0) / 4294967296;
}
function shuffleWithSeed(array, seed) {
  if (array.length <= 1) return array;
  const arr = [...array];
  let h = 2166136261 >>> 0;
  for (let i = 0; i < seed.length; i++) {
    h ^= seed.charCodeAt(i);
    h = Math.imul(h, 16777619) >>> 0 >>> 0;
  }
  const next = (step) => {
    h = Math.imul(1664525, h + step >>> 0) + 1013904223 >>> 0;
    return (h >>> 0) / 4294967296;
  };
  for (let i = arr.length - 1; i > 0; i--) {
    const j = Math.floor(next(i) * (i + 1));
    [arr[i], arr[j]] = [arr[j], arr[i]];
  }
  return arr;
}
function photoUrlFromAttachment(pa) {
  var _a, _b, _c;
  return ((_a = pa.photo) == null ? void 0 : _a.large_url) || ((_b = pa.photo) == null ? void 0 : _b.medium_url) || ((_c = pa.photo) == null ? void 0 : _c.thumbnail_url);
}
function photoAltFromAttachment(pa) {
  var _a, _b;
  return ((_a = pa.photo) == null ? void 0 : _a.alt_text) || ((_b = pa.photo) == null ? void 0 : _b.title) || "";
}
function useImageCycle(photoAttachments, seed) {
  const list = useMemo(() => {
    const arr = Array.isArray(photoAttachments) && photoAttachments.length > 0 ? photoAttachments : [];
    if (arr.length === 0) return [];
    return shuffleWithSeed(arr, seed).map((pa) => {
      var _a;
      return { url: (_a = photoUrlFromAttachment(pa)) != null ? _a : "", alt: photoAltFromAttachment(pa) };
    }).filter((x) => x.url);
  }, [photoAttachments, seed]);
  const [currentIndex, setCurrentIndex] = useState2(0);
  const [transitioning, setTransitioning] = useState2(false);
  const intervalMs = useMemo(
    () => CYCLE_INTERVAL_MIN_MS + Math.floor(seedToUnit(seed) * (CYCLE_INTERVAL_MAX_MS - CYCLE_INTERVAL_MIN_MS + 1)),
    [seed]
  );
  useEffect2(() => {
    if (list.length <= 1) return;
    const id = setInterval(() => setTransitioning(true), intervalMs);
    return () => clearInterval(id);
  }, [list.length, intervalMs]);
  useEffect2(() => {
    if (!transitioning || list.length <= 1) return;
    const t = setTimeout(() => {
      setCurrentIndex((i) => (i + 1) % list.length);
      setTransitioning(false);
    }, CROSSFADE_DURATION_MS);
    return () => clearTimeout(t);
  }, [transitioning, list.length]);
  const nextIndex = list.length > 1 ? (currentIndex + 1) % list.length : 0;
  return { list, currentIndex, nextIndex, transitioning };
}
export {
  useBreakpoint,
  useClipboard,
  useImageCycle,
  useResizeObserver
};
//# sourceMappingURL=index.js.map