var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: !0 });
}, __copyProps = (to, from, except, desc) => {
  if (from && typeof from == "object" || typeof from == "function")
    for (let key of __getOwnPropNames(from))
      !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
var YearPicker_exports = {};
__export(YearPicker_exports, {
  YearPicker: () => YearPicker
});
module.exports = __toCommonJS(YearPicker_exports);
var import_icons_ui = require("@truststack/icons-ui"), import_react = require("react"), import_react_native = require("react-native-web"), import_tamagui = require("tamagui"), import_DatePickerProvider = require("./DatePickerProvider"), import_Dialog = require("./Dialog"), import_Grid = require("./Grid"), import_Icon = require("./Icon"), import_IconButton = require("./IconButton"), import_Sheet = require("./Sheet"), import_typography = require("./typography"), import_jsx_runtime = require("react/jsx-runtime");
function YearPicker({ value, ...props }) {
  const [startYear, setStartYear] = (0, import_react.useState)(value - value % 12), [open, setOpen] = (0, import_react.useState)(!1), { goToPreviousYear } = (0, import_DatePickerProvider.useDatepickerContext)(), getYears = (start) => Array.from({ length: 12 }, (_, i) => start + i), nextYears = () => {
    setStartYear(startYear + 12);
  }, previousYears = () => {
    setStartYear(startYear - 12);
  }, years = getYears(startYear), handelChange = (year) => {
    setOpen(!1), goToPreviousYear(value - year);
  };
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_Dialog.Dialog, { allowFlip: !0, open, onOpenChange: setOpen, children: [
    /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      import_react_native.Pressable,
      {
        onPress: () => {
          setOpen(!0);
        },
        style: { flexGrow: 1 },
        children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_tamagui.XStack, { gap: 4, alignItems: "center", justifyContent: "center", children: [
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Icon.Icon, { size: 14, Icon: import_icons_ui.ChevronDown }),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_typography.Body, { textAlign: "center", children: value })
        ] })
      }
    ),
    /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tamagui.Adapt, { when: "sm", platform: "touch", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_Sheet.Sheet, { modal: !0, snapPoints: [40], children: [
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Sheet.Sheet.Overlay, {}),
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Sheet.Sheet.Handle, {}),
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Sheet.Sheet.Frame, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Sheet.SheetContent, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tamagui.Adapt.Contents, {}) }) })
    ] }) }),
    /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_Dialog.Dialog.Portal, { children: [
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Dialog.Dialog.Overlay, {}, "year-picker-overlay"),
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
        import_Dialog.Dialog.Content,
        {
          width: 360,
          marginTop: 12,
          backgroundColor: "$surfaceContainerHigh",
          borderRadius: "$shape.corner_l",
          padding: "$spacing.margin_compact",
          borderColor: "$color.outline",
          borderWidth: "$border.outline",
          children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_tamagui.YStack, { width: "100%", children: [
            /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_tamagui.XStack, { ai: "center", justifyContent: "center", width: "100%", children: [
              /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Pressable, { onPress: () => previousYears(), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Icon.Icon, { icon: import_icons_ui.ChevronLeft }) }),
              /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_typography.Body, { textAlign: "center", children: `${years[0]} - ${years[years.length - 1]}` }),
              /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Pressable, { onPress: () => nextYears(), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Icon.Icon, { icon: import_icons_ui.ChevronRight }) })
            ] }),
            /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Grid.Grid, { children: years.map((year, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
              import_Grid.Grid.Item,
              {
                compact: 4,
                exp: 4,
                ai: "center",
                children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
                  YearButton,
                  {
                    onPress: () => handelChange(year),
                    hoverStyle: {
                      col: "$onSurfaceVariant"
                    },
                    col: "$onSurface",
                    selected: year == value,
                    ...props,
                    children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(YearText, { children: year })
                  }
                )
              },
              `year-${index}`
            )) })
          ] })
        },
        "year-picker-content"
      )
    ] }, "year-picker-portal")
  ] });
}
const YearButton = (0, import_tamagui.styled)(import_IconButton.IconButton, {
  name: "YearButton",
  bc: "transparent",
  m: 4,
  mb: 4,
  w: 100,
  hoverStyle: {
    col: "$onSurfaceVariant"
  },
  variants: {
    selected: {
      true: {
        backgroundColor: "$outlineVariant"
      }
    }
  }
}), YearText = (0, import_tamagui.styled)(import_tamagui.Text, {
  name: "YearText",
  bc: "transparent",
  variants: {
    selected: {
      true: {
        color: "$onTertiary"
      }
    }
  }
});
//# sourceMappingURL=YearPicker.js.map
