export function soundCategory({ hasSpeaker = false } = {}) {
  const contents = [];

  if (hasSpeaker) {
    contents.push(
      {
        kind: 'block',
        type: 'sound_play_tone_speaker',
        inputs: {
          FREQ: { shadow: { type: 'math_number', fields: { NUM: 440 } } },
          DURATION: { shadow: { type: 'math_number', fields: { NUM: 500 } } },
        },
      },
      {
        kind: 'block',
        type: 'sound_play_note_speaker',
        inputs: {
          DURATION: { shadow: { type: 'math_number', fields: { NUM: 500 } } },
        },
      },
      {
        kind: 'block',
        type: 'sound_play_staff_note_speaker',
        inputs: {
          DURATION: { shadow: { type: 'math_number', fields: { NUM: 500 } } },
        },
      },
      { kind: 'block', type: 'sound_stop_speaker' },
    );
  }

  contents.push(
    {
      kind: 'block',
      type: 'sound_play_tone',
      inputs: {
        FREQ: { shadow: { type: 'math_number', fields: { NUM: 440 } } },
        DURATION: { shadow: { type: 'math_number', fields: { NUM: 500 } } },
      },
    },
    {
      kind: 'block',
      type: 'sound_play_note',
      inputs: {
        DURATION: { shadow: { type: 'math_number', fields: { NUM: 500 } } },
      },
    },
    {
      kind: 'block',
      type: 'sound_play_staff_note',
      inputs: {
        DURATION: { shadow: { type: 'math_number', fields: { NUM: 500 } } },
      },
    },
    { kind: 'block', type: 'sound_stop' },
  );

  // Buzzer blocks (init once, play without specifying pin each time)
  contents.push(
    { kind: 'block', type: 'sound_buzzer_init' },
    {
      kind: 'block',
      type: 'sound_buzzer_tone',
      inputs: {
        FREQ: { shadow: { type: 'math_number', fields: { NUM: 440 } } },
        DURATION: { shadow: { type: 'math_number', fields: { NUM: 500 } } },
      },
    },
    {
      kind: 'block',
      type: 'sound_buzzer_note',
      inputs: {
        DURATION: { shadow: { type: 'math_number', fields: { NUM: 500 } } },
      },
    },
    {
      kind: 'block',
      type: 'sound_buzzer_staff_note',
      inputs: {
        DURATION: { shadow: { type: 'math_number', fields: { NUM: 500 } } },
      },
    },
    { kind: 'block', type: 'sound_buzzer_stop' },
  );

  // Melodies – pin versions first, then buzzer versions
  contents.push(
    { kind: 'block', type: 'sound_melody_mario' },
    { kind: 'block', type: 'sound_melody_happy' },
    { kind: 'block', type: 'sound_melody_sad' },
    { kind: 'block', type: 'sound_melody_mario_buzzer' },
    { kind: 'block', type: 'sound_melody_happy_buzzer' },
    { kind: 'block', type: 'sound_melody_sad_buzzer' },
  );

  return {
    kind: 'category',
    name: 'Sound',
    colour: '300',
    contents,
  };
}
