import { defineArrayMember, defineField, defineType } from 'sanity';

export const imageWithAlt = defineType({
  name: 'imageWithAlt',
  title: 'תמונה',
  type: 'image',
  options: { hotspot: true },
  fields: [
    defineField({
      name: 'alt',
      title: 'תיאור התמונה',
      type: 'string',
      description: 'משפט קצר שמתאר את התמונה – לקוראות מסך ולגוגל. לתמונה דקורטיבית אפשר להשאיר ריק.',
    }),
  ],
});

export const button = defineType({
  name: 'button',
  title: 'כפתור',
  type: 'object',
  fields: [
    defineField({ name: 'label', title: 'טקסט', type: 'string', validation: (r) => r.required() }),
    defineField({
      name: 'href',
      title: 'קישור',
      type: 'string',
      description: 'עמוד באתר (/contact), קישור מלא, tel:050... או קישור וואטסאפ',
      validation: (r) => r.required(),
    }),
    defineField({
      name: 'variant',
      title: 'סגנון',
      type: 'string',
      options: { list: [{ title: 'מלא', value: 'primary' }, { title: 'מסגרת', value: 'ghost' }, { title: 'רך', value: 'soft' }], layout: 'radio', direction: 'horizontal' },
      initialValue: 'primary',
    }),
  ],
  preview: { select: { title: 'label', subtitle: 'href' } },
});

export const buttons = defineField({ name: 'buttons', title: 'כפתורים', type: 'array', of: [defineArrayMember({ type: 'button' })] });
