"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.AndroidPollDurationPicker = AndroidPollDurationPicker;
exports.IOSPollDurationPicker = IOSPollDurationPicker;
var _reactNative = require("react-native");
var _reactNativeSvg = require("react-native-svg");
var _styles = require("../styles");
var _icons = require("../../../../../core/assets/icons");
var _Typography = require("../../../../../core/components/Typography/Typography");
var _dayjs = _interopRequireDefault(require("dayjs"));
var _datetimepicker = _interopRequireWildcard(require("@react-native-community/datetimepicker"));
var _PollPostComposer = require("../PollPostComposer");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function AndroidPollDurationPicker() {
  const {
    styles
  } = (0, _styles.useStyles)();
  const {
    duration,
    selectedDate,
    setSelectedTime,
    selectedTime,
    setSelectedDate
  } = (0, _PollPostComposer.usePollPostComposerContext)();
  const endOn = (0, _dayjs.default)().add(duration.value, 'day');
  const isCustom = duration.value === 0;
  const openDatePicker = () => {
    _datetimepicker.DateTimePickerAndroid.open({
      mode: 'date',
      value: selectedDate,
      minimumDate: (0, _dayjs.default)().toDate(),
      maximumDate: (0, _dayjs.default)().add(1, 'month').toDate(),
      onChange: (event, date) => {
        if (event.type === 'set' && date) {
          setSelectedDate(date);
        }
      }
    });
  };
  const openTimePicker = () => {
    _datetimepicker.DateTimePickerAndroid.open({
      mode: 'time',
      value: selectedTime,
      is24Hour: true,
      onChange: (event, time) => {
        if (event.type === 'set' && time) {
          setSelectedTime(time);
        }
      }
    });
  };
  return /*#__PURE__*/React.createElement(_reactNative.View, null, !isCustom ? /*#__PURE__*/React.createElement(_Typography.Typography.Caption, {
    style: styles.base
  }, "Ends on ", endOn.format('DD MMM'), " at ", endOn.format('HH:mm A')) : /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.androidDateTimeContainer
  }, /*#__PURE__*/React.createElement(_Typography.Typography.Body, {
    style: styles.base
  }, "Ends on"), /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.androidDateTimeContainer
  }, /*#__PURE__*/React.createElement(_reactNative.TouchableOpacity, {
    style: styles.androidDateTimeButton,
    onPress: openDatePicker
  }, /*#__PURE__*/React.createElement(_Typography.Typography.Body, {
    style: styles.base
  }, (0, _dayjs.default)(selectedDate).format('DD MMM YYYY'))), /*#__PURE__*/React.createElement(_reactNative.TouchableOpacity, {
    style: styles.androidDateTimeButton,
    onPress: openTimePicker
  }, /*#__PURE__*/React.createElement(_Typography.Typography.Body, {
    style: styles.base
  }, (0, _dayjs.default)(selectedTime).format('HH:mm A'))))));
}
function IOSPollDurationPicker() {
  const {
    styles,
    theme
  } = (0, _styles.useStyles)();
  const {
    width
  } = (0, _reactNative.useWindowDimensions)();
  const {
    setDuration,
    selectedDate,
    bottomSheetRef,
    setSelectedDate,
    setIsShowingDatePicker
  } = (0, _PollPostComposer.usePollPostComposerContext)();
  return /*#__PURE__*/React.createElement(_reactNative.View, null, /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.iOSDateTimeHeader
  }, /*#__PURE__*/React.createElement(_reactNative.TouchableOpacity, {
    onPress: () => setIsShowingDatePicker(false)
  }, /*#__PURE__*/React.createElement(_reactNative.View, null, /*#__PURE__*/React.createElement(_reactNativeSvg.SvgXml, {
    width: "24",
    height: "24",
    xml: (0, _icons.arrowLeft)(),
    color: theme.colors.base
  }))), /*#__PURE__*/React.createElement(_Typography.Typography.TitleBold, {
    style: styles.base
  }, "Ends on"), /*#__PURE__*/React.createElement(_reactNative.TouchableOpacity, {
    disabled: !selectedDate,
    onPress: () => {
      var _bottomSheetRef$curre;
      (_bottomSheetRef$curre = bottomSheetRef.current) === null || _bottomSheetRef$curre === void 0 || _bottomSheetRef$curre.close();
      setDuration({
        value: 0,
        label: `End on ${(0, _dayjs.default)(selectedDate).format('DD MMM')} at ${(0, _dayjs.default)(selectedDate).format('HH:mm A')}`
      });
    }
  }, /*#__PURE__*/React.createElement(_Typography.Typography.Body, {
    style: [styles.cta, !selectedDate && styles.disabled]
  }, "Done"))), /*#__PURE__*/React.createElement(_datetimepicker.default, {
    locale: "en_US",
    mode: "datetime",
    display: "inline",
    value: selectedDate,
    minimumDate: (0, _dayjs.default)().toDate(),
    style: [styles.iOSDateTimePicker, {
      width
    }],
    accentColor: theme.colors.primary,
    maximumDate: (0, _dayjs.default)().add(1, 'month').toDate(),
    onChange: (event, date) => {
      if (event.type === 'set') {
        setSelectedDate(date);
      }
    }
  }));
}
//# sourceMappingURL=PollDurationPicker.js.map