"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var z = _interopRequireWildcard(require("zod"));
var _styles = require("./styles");
var _Header = _interopRequireDefault(require("./components/Header"));
var _reactNative = require("react-native");
var _reactQuery = require("@tanstack/react-query");
var _zod2 = require("@hookform/resolvers/zod");
var _reactHookForm = require("react-hook-form");
var _reactNativeSafeAreaContext = require("react-native-safe-area-context");
var _Typography = require("../../../../core/components/Typography/Typography");
var _tsSdkReactNative = require("@amityco/ts-sdk-react-native");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
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); }
const schema = z.object({
  storySetting: z.boolean()
});
const useCommunityStorySetting = ({
  community
}) => {
  const {
    styles,
    theme
  } = (0, _styles.useStyles)();
  const {
    control,
    handleSubmit,
    formState: {
      isDirty,
      isSubmitting,
      isValid
    }
  } = (0, _reactHookForm.useForm)({
    resolver: (0, _zod2.zodResolver)(schema),
    mode: 'onChange',
    values: {
      storySetting: community.allowCommentInStory
    }
  });
  const {
    mutateAsync
  } = (0, _reactQuery.useMutation)({
    mutationFn: payload => _tsSdkReactNative.CommunityRepository.updateCommunity(community.communityId, {
      storySetting: {
        enableComment: payload.storySetting
      }
    })
  });
  const onSubmit = async data => {
    await mutateAsync(data);
  };
  return {
    styles,
    theme,
    control,
    handleSubmit,
    disabled: !isDirty || !isValid || isSubmitting,
    onSubmit
  };
};
const CommunityStorySetting = ({
  community
}) => {
  const {
    styles,
    control,
    theme,
    handleSubmit,
    onSubmit
  } = useCommunityStorySetting({
    community
  });
  return /*#__PURE__*/React.createElement(_reactNativeSafeAreaContext.SafeAreaView, {
    style: styles.container,
    edges: ['top']
  }, /*#__PURE__*/React.createElement(_Header.default, null), /*#__PURE__*/React.createElement(_reactHookForm.Controller, {
    control: control,
    name: "storySetting",
    render: ({
      field: {
        onChange,
        value
      }
    }) => /*#__PURE__*/React.createElement(_reactNative.View, {
      style: styles.switchContainer
    }, /*#__PURE__*/React.createElement(_reactNative.View, {
      style: styles.labelContainer
    }, /*#__PURE__*/React.createElement(_Typography.Typography.BodyBold, {
      style: styles.colorBase
    }, "Allow comments on community stories"), /*#__PURE__*/React.createElement(_Typography.Typography.Caption, {
      style: styles.colorBaseShade1
    }, "Turn on to receive comments on stories in this community.")), /*#__PURE__*/React.createElement(_reactNative.Switch, {
      value: value,
      thumbColor: theme.colors.background,
      ios_backgroundColor: theme.colors.baseShade3,
      trackColor: {
        false: theme.colors.baseShade3,
        true: theme.colors.primary
      },
      onValueChange: selected => {
        onChange(selected);
        handleSubmit(onSubmit)();
      }
    }))
  }));
};
var _default = exports.default = CommunityStorySetting;
//# sourceMappingURL=StorySetting.js.map