class SelectFacet < FilterableFacet
  delegate :allowed_values, to: :facet

  def options
    allowed_values.map do | allowed_value |
      {
        "value" => allowed_value.value,
        "label" => allowed_value.label,
        "id" => allowed_value.value,
        "checked" => selected_values.include?(allowed_value),
      }
    end
  end

  def value=(new_value)
    @value = Array(new_value)
  end

  def sentence_fragment
    return nil unless selected_values.any?

    OpenStruct.new(
      preposition: preposition,
      values: value_fragments,
    )
  end

private
  def value_fragments
    selected_values.map { |v|
      OpenStruct.new(
        label: v.label,
        parameter_key: key,
        other_params: other_params(v),
      )
    }
  end

  def other_params(v)
    selected_values
      .map(&:value)
      .reject { |selected_value|  selected_value == v.value }
  end

  def selected_values
    return [] if @value.nil?
    allowed_values.select { |option|
      @value.include?(option.value)
    }
  end
end

class SelectFacet < FilterableFacet
  delegate :allowed_values, to: :facet

  def options
    allowed_values.map do | allowed_value |
      {
        value: allowed_value.value,
        label: allowed_value.label,
        id: allowed_value.value,
        checked: selected_values.include?(allowed_value),
      }
    end
  end

  def value=(new_value)
    @value = Array(new_value)
  end

  def sentence_fragment
    return nil unless selected_values.any?

    OpenStruct.new(
      preposition: preposition,
      values: value_fragments,
    )
  end

private
  def value_fragments
    selected_values.map { |v|
      OpenStruct.new(
        label: v.label,
        parameter_key: key,
        other_params: other_params(v),
      )
    }
  end

  def other_params(v)
    selected_values
      .map(&:value)
      .reject { |selected_value|  selected_value == v.value }
  end

  def selected_values
    return [] if @value.nil?
    allowed_values.select { |option|
      @value.include?(option.value)
    }
  end
end

Use symbols, not strings, for component object keys
Use symbols, not strings, for component object keys

We should only use one style of keys for objects used in components,
to avoid reduce confusion when using components. Consistency is good.

After discussion with @edds we agreed to use symbols as this makes
more sense in a ruby/rails environment.

The first step was to support both, as clients of those components
will still be sending string key'd objects and can't be updated
at the time as this app, so we have to;

1. Support both kinds of keys on components that expect strings
2. Update clients sending string keys to use symbols instead
3. Remove support for string keys from those components

This PR is step 2. for `options_select`, but also needs doing in
`manuals-frontend` for `previous_and_next_navigation`.

Step 1 is: https://github.com/alphagov/static/pull/601
