"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.EditLinksModal = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _vectorIcons = require("@expo/vector-icons");
var _useThemeStyles = require("../../hooks/useThemeStyles");
var _useColorScheme = require("../../hooks/use-color-scheme");
var _useI18n = require("../../hooks/useI18n");
var _fonts = require("../../styles/fonts");
var _useProfileEditing = require("../../hooks/useProfileEditing");
var _jsxRuntime = require("react/jsx-runtime");
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 EditLinksModal = ({
  visible,
  onClose,
  initialLinks = [],
  theme = 'light',
  onSave
}) => {
  const {
    t
  } = (0, _useI18n.useI18n)();
  const colorScheme = (0, _useColorScheme.useColorScheme)();
  const themeStyles = (0, _useThemeStyles.useThemeStyles)(theme || 'light', colorScheme);
  const colors = themeStyles.colors;
  const {
    saveProfile,
    isSaving
  } = (0, _useProfileEditing.useProfileEditing)();
  const [links, setLinks] = (0, _react.useState)(initialLinks);
  const [newLinkUrl, setNewLinkUrl] = (0, _react.useState)('');
  (0, _react.useEffect)(() => {
    if (visible) {
      setLinks(initialLinks);
      setNewLinkUrl('');
    }
  }, [visible, initialLinks]);
  const handleAddLink = () => {
    if (!newLinkUrl.trim()) return;
    const link = {
      id: `link-${Date.now()}`,
      url: newLinkUrl.trim(),
      title: newLinkUrl.replace(/^https?:\/\//, '').replace(/\/$/, ''),
      description: `Link to ${newLinkUrl}`
    };
    setLinks([...links, link]);
    setNewLinkUrl('');
  };
  const handleRemoveLink = id => {
    setLinks(links.filter(link => link.id !== id));
  };
  const handleSave = async () => {
    const success = await saveProfile({
      linksMetadata: links,
      links: links.map(link => link.url)
    });
    if (success) {
      onSave?.();
      onClose();
    }
  };
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Modal, {
    visible: visible,
    animationType: "slide",
    transparent: true,
    onRequestClose: onClose,
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
      style: styles.modalOverlay,
      children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
        style: [styles.modalContent, {
          backgroundColor: colors.background
        }],
        children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
          style: styles.modalHeader,
          children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TouchableOpacity, {
            onPress: onClose,
            style: styles.closeButton,
            children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_vectorIcons.Ionicons, {
              name: "close",
              size: 24,
              color: colors.text
            })
          }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
            style: [styles.modalTitle, {
              color: colors.text
            }],
            children: t('editProfile.items.links.title') || 'Links'
          }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TouchableOpacity, {
            onPress: handleSave,
            disabled: isSaving,
            style: [styles.saveButton, {
              opacity: isSaving ? 0.5 : 1
            }],
            children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
              style: [styles.saveButtonText, {
                color: colors.tint
              }],
              children: isSaving ? 'Saving...' : 'Save'
            })
          })]
        }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.ScrollView, {
          style: styles.modalBody,
          children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
            style: styles.inputGroup,
            children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
              style: [styles.label, {
                color: colors.text
              }],
              children: t('editProfile.items.links.add') || 'Add Link'
            }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
              style: styles.addLinkRow,
              children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TextInput, {
                style: [styles.input, {
                  backgroundColor: colors.card,
                  color: colors.text,
                  borderColor: colors.border,
                  flex: 1
                }],
                value: newLinkUrl,
                onChangeText: setNewLinkUrl,
                placeholder: t('editProfile.items.links.placeholder') || 'Enter URL (e.g., https://example.com)',
                placeholderTextColor: colors.secondaryText,
                keyboardType: "url",
                autoCapitalize: "none",
                autoCorrect: false,
                selectionColor: colors.tint
              }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TouchableOpacity, {
                style: [styles.addButton, {
                  backgroundColor: colors.tint
                }],
                onPress: handleAddLink,
                disabled: !newLinkUrl.trim(),
                children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_vectorIcons.Ionicons, {
                  name: "add",
                  size: 20,
                  color: "#fff"
                })
              })]
            })]
          }), links.length > 0 && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
            style: styles.linksList,
            children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.Text, {
              style: [styles.listTitle, {
                color: colors.text
              }],
              children: [t('editProfile.items.links.yourLinks') || 'Your Links', " (", links.length, ")"]
            }), links.map((link, index) => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
              style: [styles.linkItem, {
                backgroundColor: colors.card,
                borderColor: colors.border
              }, index < links.length - 1 && {
                borderBottomWidth: _reactNative.StyleSheet.hairlineWidth
              }],
              children: [link.image && /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Image, {
                source: {
                  uri: link.image
                },
                style: styles.linkImage
              }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
                style: styles.linkInfo,
                children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
                  style: [styles.linkTitle, {
                    color: colors.text
                  }],
                  numberOfLines: 1,
                  children: link.title || link.url
                }), link.description && link.description !== link.title && /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
                  style: [styles.linkDescription, {
                    color: colors.secondaryText
                  }],
                  numberOfLines: 1,
                  children: link.description
                }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
                  style: [styles.linkUrl, {
                    color: colors.secondaryText
                  }],
                  numberOfLines: 1,
                  children: link.url
                })]
              }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TouchableOpacity, {
                onPress: () => handleRemoveLink(link.id),
                style: styles.removeButton,
                children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_vectorIcons.Ionicons, {
                  name: "trash-outline",
                  size: 18,
                  color: "#FF3B30"
                })
              })]
            }, link.id))]
          })]
        })]
      })
    })
  });
};
exports.EditLinksModal = EditLinksModal;
const styles = _reactNative.StyleSheet.create({
  modalOverlay: {
    flex: 1,
    backgroundColor: 'rgba(0, 0, 0, 0.5)',
    justifyContent: 'flex-end'
  },
  modalContent: {
    borderTopLeftRadius: 20,
    borderTopRightRadius: 20,
    paddingTop: _reactNative.Platform.OS === 'ios' ? 20 : 16,
    maxHeight: '80%'
  },
  modalHeader: {
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'space-between',
    paddingHorizontal: 16,
    paddingBottom: 16,
    borderBottomWidth: _reactNative.StyleSheet.hairlineWidth,
    borderBottomColor: '#E5E5EA'
  },
  closeButton: {
    width: 40,
    height: 40,
    alignItems: 'center',
    justifyContent: 'center'
  },
  modalTitle: {
    fontSize: 18,
    fontWeight: '600',
    fontFamily: _fonts.fontFamilies.phuduSemiBold,
    flex: 1,
    textAlign: 'center'
  },
  saveButton: {
    paddingHorizontal: 16,
    paddingVertical: 8
  },
  saveButtonText: {
    fontSize: 16,
    fontWeight: '600',
    fontFamily: _fonts.fontFamilies.phuduSemiBold
  },
  modalBody: {
    padding: 16
  },
  inputGroup: {
    gap: 8,
    marginBottom: 24
  },
  label: {
    fontSize: 14,
    fontWeight: '600',
    fontFamily: _fonts.fontFamilies.phuduSemiBold
  },
  addLinkRow: {
    flexDirection: 'row',
    gap: 8,
    alignItems: 'center'
  },
  input: {
    borderWidth: _reactNative.StyleSheet.hairlineWidth,
    borderRadius: 12,
    padding: 16,
    fontSize: 16,
    minHeight: 52
  },
  addButton: {
    width: 52,
    height: 52,
    borderRadius: 12,
    alignItems: 'center',
    justifyContent: 'center'
  },
  linksList: {
    gap: 8
  },
  listTitle: {
    fontSize: 16,
    fontWeight: '600',
    fontFamily: _fonts.fontFamilies.phuduSemiBold,
    marginBottom: 8
  },
  linkItem: {
    flexDirection: 'row',
    alignItems: 'center',
    padding: 16,
    borderRadius: 12,
    borderWidth: _reactNative.StyleSheet.hairlineWidth,
    gap: 12
  },
  linkImage: {
    width: 40,
    height: 40,
    borderRadius: 8
  },
  linkInfo: {
    flex: 1,
    gap: 4
  },
  linkTitle: {
    fontSize: 16,
    fontWeight: '600'
  },
  linkDescription: {
    fontSize: 14
  },
  linkUrl: {
    fontSize: 12
  },
  removeButton: {
    padding: 8
  }
});
//# sourceMappingURL=EditLinksModal.js.map