class FieldOptionsController < ApplicationController
  layout "user"
  before_action :select_syndicate
  before_action :set_field_option, only: [:show, :edit, :update, :destroy]

  def index
    @field_options = @syndicate.field_options.page(params[:page]).order(label: :asc)
  end

  def show
  end

  def new
    @field_option = FieldOption.new
  end

  def create
    @field_option = @syndicate.field_options.create! field_option_params

    if @field_option.id
      return render :show, status: :ok
    end

    render :new, status: :unprocessable_entity
  end

  def edit
  end

  def update
    if @field_option.update field_option_params
      return render :show, status: :ok
    end

    render :edit, status: :unprocessable_entity
  end

  def destroy
    @field_option.destroy

    redirect_to settings_field_options_url, notice: 1
  end

  private
    def field_option_params
      params.require(:field_option).permit(:label, :value)
    end

    def set_field_option
      @field_option = @syndicate.field_options.find_by id: params[:id]
    end
end
