export type LinkTarget = 'new' | 'same';
export type LinkRel = 'follow' | 'nofollow' | 'sponsored';

export const LINK_FIELDS = {
  openInNewTab: {
    type: "radio" as const,
    label: "リンクの開き方",
    options: [
      { label: "現在のタブ", value: "same" as const },
      { label: "新しいタブ", value: "new" as const },
    ],
  },
  relAttribute: {
    type: "radio" as const,
    label: "SEO リンク関係性",
    options: [
      { label: "通常 (follow)", value: "follow" as const },
      { label: "広告/不審なリンク (nofollow)", value: "nofollow" as const },
      { label: "スポンサーリンク (sponsored)", value: "sponsored" as const },
    ],
  },
};

export function getLinkAttributes({ openInNewTab, relAttribute }: { openInNewTab?: LinkTarget; relAttribute?: LinkRel }) {
  const attrs: { target?: string; rel?: string } = {};
  if (openInNewTab === 'new') {
    attrs.target = '_blank';
    attrs.rel = 'noopener noreferrer';
  }
  if (relAttribute === 'nofollow') {
    attrs.rel = attrs.rel ? `${attrs.rel} nofollow` : 'nofollow';
  } else if (relAttribute === 'sponsored') {
    attrs.rel = attrs.rel ? `${attrs.rel} sponsored` : 'sponsored';
  }
  return attrs;
}
