"use client";
'use strict';

var React = require('react');
var clsx = require('clsx');
var tailwindMerge = require('tailwind-merge');
var reactDayPicker = require('react-day-picker');
var lucideReact = require('lucide-react');
var jsxRuntime = require('react/jsx-runtime');
var classVarianceAuthority = require('class-variance-authority');
var dateFns = require('date-fns');
require('@base-ui/react/input');
var popover = require('@base-ui/react/popover');

function _interopNamespace(e) {
  if (e && e.__esModule) return e;
  var n = Object.create(null);
  if (e) {
    Object.keys(e).forEach(function (k) {
      if (k !== 'default') {
        var d = Object.getOwnPropertyDescriptor(e, k);
        Object.defineProperty(n, k, d.get ? d : {
          enumerable: true,
          get: function () { return e[k]; }
        });
      }
    });
  }
  n.default = e;
  return Object.freeze(n);
}

var React__namespace = /*#__PURE__*/_interopNamespace(React);

var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __objRest = (source, exclude) => {
  var target = {};
  for (var prop in source)
    if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
      target[prop] = source[prop];
  if (source != null && __getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(source)) {
      if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
        target[prop] = source[prop];
    }
  return target;
};
function cn(...inputs) {
  return tailwindMerge.twMerge(clsx.clsx(inputs));
}
function Calendar(_a) {
  var _b = _a, {
    className,
    classNames,
    showOutsideDays = true
  } = _b, props = __objRest(_b, [
    "className",
    "classNames",
    "showOutsideDays"
  ]);
  return /* @__PURE__ */ jsxRuntime.jsx(
    reactDayPicker.DayPicker,
    __spreadValues({
      "data-slot": "calendar",
      showOutsideDays,
      weekStartsOn: 1,
      className: cn("w-[250px]", className),
      classNames: __spreadValues({
        root: "p-0",
        months: "flex gap-0",
        month: "flex h-[304px] w-[250px] flex-col overflow-clip",
        month_caption: "flex shrink-0 items-center justify-center gap-2 border-b border-stroke-hairline p-2",
        caption_label: "flex-1 text-center text-sm font-medium text-foreground",
        nav: "contents",
        button_previous: "inline-flex size-6 shrink-0 items-center justify-center rounded-sm bg-transparent text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",
        button_next: "inline-flex size-6 shrink-0 items-center justify-center rounded-sm bg-transparent text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",
        month_grid: "flex flex-1 flex-col gap-1 p-2",
        weekdays: "flex flex-1 gap-1",
        weekday: "flex flex-1 items-center justify-center rounded-xs p-2 text-center text-xs font-medium text-foreground/30",
        weeks: "contents",
        week: "flex flex-1 gap-1",
        day: cn(
          "relative flex flex-1 items-center justify-center rounded-xs p-0 text-center text-xs font-medium text-foreground",
          "has-[button]:hover:bg-muted",
          "[&:has([aria-selected])]:bg-primary/10",
          "[&:has([aria-selected].range_start)]:rounded-l-xs [&:has([aria-selected].range_start)]:rounded-r-none",
          "[&:has([aria-selected].range_end)]:rounded-r-xs [&:has([aria-selected].range_end)]:rounded-l-none",
          "[&:has([aria-selected].range_start.range_end)]:rounded-xs"
        ),
        day_button: cn(
          "inline-flex size-full items-center justify-center rounded-xs text-xs font-medium transition-colors",
          "hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
        ),
        today: cn(
          "[&>button]:relative [&>button]:z-10",
          "[&>button]:before:absolute [&>button]:before:size-[21px] [&>button]:before:rounded-full [&>button]:before:bg-[#e74341]",
          "[&>button]:before:left-1/2 [&>button]:before:top-1/2 [&>button]:before:-translate-x-1/2 [&>button]:before:-translate-y-1/2",
          "[&>button]:text-white [&>button]:hover:text-white [&>button]:hover:bg-transparent",
          "[&>button[aria-selected]]:before:hidden"
        ),
        outside: "text-foreground/30 [&>button]:text-foreground/30 [&>button]:hover:text-foreground/50",
        disabled: "text-foreground/20 pointer-events-none",
        hidden: "invisible",
        selected: cn(
          "[&:not(.range_middle)]:bg-primary [&:not(.range_middle)]:rounded-xs",
          "[&:not(.range_middle)>button]:text-primary-foreground [&:not(.range_middle)>button]:hover:bg-primary [&:not(.range_middle)>button]:hover:text-primary-foreground"
        ),
        range_start: "range_start",
        range_end: "range_end",
        range_middle: cn(
          "range_middle",
          "[&>button]:bg-transparent [&>button]:text-primary [&>button]:hover:bg-primary/20 [&>button]:hover:text-primary"
        )
      }, classNames),
      components: {
        Chevron: ({ orientation }) => {
          const Icon = orientation === "left" ? lucideReact.ChevronLeft : lucideReact.ChevronRight;
          return /* @__PURE__ */ jsxRuntime.jsx(Icon, { className: "size-4" });
        }
      }
    }, props)
  );
}
var datePickerContainerVariants = classVarianceAuthority.cva(
  "group/date-picker flex w-full cursor-pointer items-center gap-1.5 overflow-clip rounded-[var(--radius-sm)] shadow-none transition-[background-color] duration-150 focus-visible:transition-none data-[state=open]:transition-none [&_svg]:pointer-events-none [&_svg]:shrink-0",
  {
    variants: {
      inputStyle: {
        default: "border border-border bg-white hover:border-input-hover hover:bg-[var(--theme-background-input-hover)] dark:bg-sidebar",
        shadow: "border border-border bg-white shadow-none hover:border-input-hover hover:bg-[var(--theme-background-input-hover)] dark:bg-sidebar",
        soft: "border border-border bg-white hover:border-input-hover hover:bg-[var(--theme-background-input-hover)] dark:bg-sidebar"
      },
      size: {
        sm: "p-1.5",
        lg: "p-2"
      }
    },
    defaultVariants: {
      inputStyle: "default",
      size: "sm"
    }
  }
);
function DateSegment({
  value,
  placeholder,
  width,
  isDisabled
}) {
  const isFilled = value !== void 0 && value !== "";
  return /* @__PURE__ */ jsxRuntime.jsx(
    "span",
    {
      "data-slot": "date-segment",
      className: cn(
        "inline-flex items-center justify-center rounded-xs px-1 text-sm leading-5 tabular-nums",
        isDisabled ? "text-foreground/30" : isFilled ? "text-foreground" : "text-muted-foreground",
        width
      ),
      children: isFilled ? value : placeholder
    }
  );
}
function DateSegmentSeparator() {
  return /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": true, className: "text-sm leading-5 text-foreground/30 select-none", children: "/" });
}
function DateSegmentGroup({
  value,
  isDisabled,
  className
}) {
  const day = value ? dateFns.format(value, "dd") : void 0;
  const month = value ? dateFns.format(value, "MM") : void 0;
  const year = value ? dateFns.format(value, "yyyy") : void 0;
  return /* @__PURE__ */ jsxRuntime.jsxs("span", { className: cn("inline-flex items-center gap-0.5", className), children: [
    /* @__PURE__ */ jsxRuntime.jsx(DateSegment, { value: day, placeholder: "dd", width: "w-[26px]", isDisabled }),
    /* @__PURE__ */ jsxRuntime.jsx(DateSegmentSeparator, {}),
    /* @__PURE__ */ jsxRuntime.jsx(DateSegment, { value: month, placeholder: "mm", width: "w-[33px]", isDisabled }),
    /* @__PURE__ */ jsxRuntime.jsx(DateSegmentSeparator, {}),
    /* @__PURE__ */ jsxRuntime.jsx(DateSegment, { value: year, placeholder: "yyyy", width: "w-[40px]", isDisabled })
  ] });
}
function DatePickerInput(_a) {
  var _b = _a, {
    className,
    type = "default",
    inputStyle = "default",
    size = "sm",
    value,
    endValue,
    invalid,
    isOpen,
    disabled
  } = _b, props = __objRest(_b, [
    "className",
    "type",
    "inputStyle",
    "size",
    "value",
    "endValue",
    "invalid",
    "isOpen",
    "disabled"
  ]);
  return /* @__PURE__ */ jsxRuntime.jsxs(
    "button",
    __spreadProps(__spreadValues({
      type: "button",
      "data-slot": "date-picker-input",
      disabled,
      "data-state": isOpen ? "open" : "closed",
      "data-invalid": invalid ? "true" : void 0,
      className: cn(
        datePickerContainerVariants({ inputStyle, size }),
        isOpen && "border-input-hover ring-0",
        invalid && !isOpen && "border-destructive",
        disabled && "pointer-events-none border-border bg-muted shadow-none after:hidden hover:bg-muted",
        className
      )
    }, props), {
      children: [
        /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "flex min-w-0 flex-1 items-center gap-0.5", children: [
          /* @__PURE__ */ jsxRuntime.jsx(DateSegmentGroup, { value, isDisabled: disabled }),
          type === "range" && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
            /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ArrowRight, { className: "mx-0.5 size-4 shrink-0 text-muted-foreground" }),
            /* @__PURE__ */ jsxRuntime.jsx(DateSegmentGroup, { value: endValue, isDisabled: disabled })
          ] })
        ] }),
        /* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex size-5 shrink-0 items-center justify-center text-muted-foreground", children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Calendar, { className: "size-4" }) })
      ]
    })
  );
}
function InputGroup(_a) {
  var _b = _a, {
    className,
    disabled
  } = _b, props = __objRest(_b, [
    "className",
    "disabled"
  ]);
  return /* @__PURE__ */ jsxRuntime.jsx(
    "div",
    __spreadValues({
      "data-slot": "input-group",
      "data-disabled": disabled || void 0,
      className: cn("flex w-full flex-col gap-2", className)
    }, props)
  );
}
function InputLabel(_a) {
  var _b = _a, {
    className,
    trailing,
    children
  } = _b, props = __objRest(_b, [
    "className",
    "trailing",
    "children"
  ]);
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
    /* @__PURE__ */ jsxRuntime.jsx(
      "label",
      __spreadProps(__spreadValues({
        "data-slot": "input-label",
        className: cn(
          "text-sm font-medium leading-5 text-foreground select-none group-data-[disabled]:pointer-events-none group-data-[disabled]:opacity-50",
          className
        )
      }, props), {
        children
      })
    ),
    trailing && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center gap-1 text-xs text-muted-foreground", children: trailing })
  ] });
}
var inputHelperTextVariants = classVarianceAuthority.cva(
  "text-xs leading-4",
  {
    variants: {
      variant: {
        default: "text-muted-foreground",
        error: "text-destructive",
        success: "text-[var(--theme-text-success)]"
      }
    },
    defaultVariants: {
      variant: "default"
    }
  }
);
function InputHelperText(_a) {
  var _b = _a, {
    className,
    variant = "default"
  } = _b, props = __objRest(_b, [
    "className",
    "variant"
  ]);
  return /* @__PURE__ */ jsxRuntime.jsx(
    "p",
    __spreadValues({
      "data-slot": "input-helper-text",
      className: cn(inputHelperTextVariants({ variant }), className)
    }, props)
  );
}
classVarianceAuthority.cva(
  "flex w-full items-center overflow-clip rounded-[var(--radius-sm)] transition-[background-color,border-color] duration-150 has-[:focus-within]:transition-none has-[:focus-visible]:border-input-hover has-[:focus-visible]:ring-0 has-[:disabled]:pointer-events-none has-[:disabled]:opacity-50 has-[aria-invalid]:border-destructive has-[aria-invalid]:ring-3 has-[aria-invalid]:ring-destructive/20 dark:has-[aria-invalid]:border-destructive/50 dark:has-[aria-invalid]:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
  {
    variants: {
      inputStyle: {
        default: "border border-border bg-card shadow-none hover:bg-[var(--theme-background-input-hover)] dark:bg-sidebar dark:hover:bg-[var(--theme-background-input-hover)] dark:has-[:disabled]:hover:bg-sidebar dark:has-[:disabled]:bg-input/80",
        soft: "border border-transparent bg-card hover:bg-[var(--theme-background-input-hover)] has-[:disabled]:hover:bg-card dark:bg-sidebar dark:hover:bg-[var(--theme-background-input-hover)] dark:has-[:disabled]:hover:bg-sidebar"
      },
      size: {
        sm: "min-h-8",
        /** Fixed height (not min-height) so flex children cannot grow the row past 36px (e.g. toolbar alignment). */
        lg: "h-9"
      }
    },
    defaultVariants: {
      inputStyle: "default",
      size: "sm"
    }
  }
);
classVarianceAuthority.cva(
  "w-full min-w-0 bg-transparent text-sm text-foreground outline-none transition-colors placeholder:text-muted-foreground file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground disabled:pointer-events-none disabled:cursor-not-allowed",
  {
    variants: {
      size: {
        sm: "h-8 px-2.5 py-1",
        /** `py-0` avoids UA + padding stacking past 36px; `leading-5` matches `text-sm` line box. */
        lg: "h-9 px-2.5 py-0 leading-5"
      },
      standalone: {
        true: "rounded-[var(--radius-sm)] border border-border bg-card shadow-none transition-[background-color,border-color] duration-150 hover:bg-[var(--theme-background-input-hover)] focus-visible:transition-none focus-visible:border-input-hover focus-visible:ring-0 disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:bg-sidebar dark:hover:bg-[var(--theme-background-input-hover)] dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",
        false: "border-none focus-visible:ring-0 focus-visible:ring-offset-0"
      }
    },
    defaultVariants: {
      size: "sm",
      standalone: true
    }
  }
);
function Popover(_a) {
  var props = __objRest(_a, []);
  return /* @__PURE__ */ jsxRuntime.jsx(popover.Popover.Root, __spreadValues({ "data-slot": "popover" }, props));
}
function PopoverTrigger(_a) {
  var props = __objRest(_a, []);
  return /* @__PURE__ */ jsxRuntime.jsx(popover.Popover.Trigger, __spreadValues({ "data-slot": "popover-trigger" }, props));
}
function PopoverContent(_a) {
  var _b = _a, {
    className,
    align = "center",
    alignOffset = 0,
    side = "bottom",
    sideOffset = 4,
    collisionPadding,
    collisionBoundary,
    collisionAvoidance
  } = _b, props = __objRest(_b, [
    "className",
    "align",
    "alignOffset",
    "side",
    "sideOffset",
    "collisionPadding",
    "collisionBoundary",
    "collisionAvoidance"
  ]);
  return /* @__PURE__ */ jsxRuntime.jsx(popover.Popover.Portal, { children: /* @__PURE__ */ jsxRuntime.jsx(
    popover.Popover.Positioner,
    {
      align,
      alignOffset,
      side,
      sideOffset,
      collisionPadding,
      collisionBoundary,
      collisionAvoidance,
      className: "isolate z-50",
      children: /* @__PURE__ */ jsxRuntime.jsx(
        popover.Popover.Popup,
        __spreadValues({
          "data-slot": "popover-content",
          className: cn(
            "z-50 flex w-72 origin-(--transform-origin) flex-col gap-2.5 rounded-sm bg-popover p-2.5 text-sm text-popover-foreground shadow-md ring-1 ring-foreground/10 outline-hidden duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
            className
          )
        }, props)
      )
    }
  ) });
}
var PANEL_CLASSES = "w-auto overflow-clip rounded-[var(--radius-Card-sm,8px)] border-0 bg-card p-0 shadow-[0px_0px_0px_1px_var(--theme-stroke-hairline),0px_12px_12px_-6px_rgba(0,0,0,0.04),0px_6px_6px_-3px_rgba(0,0,0,0.04),0px_3px_3px_-1.5px_rgba(0,0,0,0.04),0px_1px_1px_-0.5px_rgba(0,0,0,0.04),inset_0px_-1px_0px_0px_var(--theme-stroke-soft)] ring-0";
var CALENDAR_MONTH_TRIGGER_SHELL = "inline-flex items-center overflow-hidden rounded-[var(--radius-sm)] border border-border bg-card text-foreground shadow-none transition-colors hover:border-input-hover active:border-input-hover dark:border-border dark:bg-secondary dark:text-secondary-foreground dark:hover:border-input-hover dark:active:border-input-hover";
function DatePicker({
  value,
  onChange,
  defaultMonth,
  inputStyle = "default",
  size = "sm",
  label,
  labelTrailing,
  helperText,
  error,
  disabled,
  className
}) {
  const [isOpen, setIsOpen] = React__namespace.useState(false);
  const handleSelect = React__namespace.useCallback(
    (date) => {
      onChange == null ? void 0 : onChange(date);
      setIsOpen(false);
    },
    [onChange]
  );
  const hasError = !!error;
  const captionText = error || helperText;
  return /* @__PURE__ */ jsxRuntime.jsxs(InputGroup, { className, disabled, children: [
    label && /* @__PURE__ */ jsxRuntime.jsx(InputLabel, { trailing: labelTrailing, children: label }),
    /* @__PURE__ */ jsxRuntime.jsxs(Popover, { open: isOpen, onOpenChange: setIsOpen, children: [
      /* @__PURE__ */ jsxRuntime.jsx(
        PopoverTrigger,
        {
          render: /* @__PURE__ */ jsxRuntime.jsx(
            DatePickerInput,
            {
              type: "default",
              inputStyle,
              size,
              value,
              invalid: hasError,
              isOpen,
              disabled
            }
          )
        }
      ),
      /* @__PURE__ */ jsxRuntime.jsx(
        PopoverContent,
        {
          align: "start",
          sideOffset: 4,
          className: cn(PANEL_CLASSES),
          children: /* @__PURE__ */ jsxRuntime.jsx(
            Calendar,
            {
              mode: "single",
              selected: value,
              onSelect: handleSelect,
              defaultMonth: defaultMonth != null ? defaultMonth : value
            }
          )
        }
      )
    ] }),
    captionText && /* @__PURE__ */ jsxRuntime.jsx(InputHelperText, { variant: hasError ? "error" : "default", children: captionText })
  ] });
}

exports.CALENDAR_MONTH_TRIGGER_SHELL = CALENDAR_MONTH_TRIGGER_SHELL;
exports.DatePicker = DatePicker;
exports.PANEL_CLASSES = PANEL_CLASSES;
//# sourceMappingURL=date-picker.cjs.map
//# sourceMappingURL=date-picker.cjs.map