# frozen_string_literal: true

class Dummy::Atom::ImagesCell < ApplicationCell
  DYNAMIC_TARGET_HEIGHT = 260
  DYNAMIC_THUMB_MAX_WIDTH = 600
  DYNAMIC_THUMB_MAX_HEIGHT = 400
  DYNAMIC_MARGIN = 15

  GRID_SIZE = 266

  def show
    render if model && model.image_placements.present?
  end

  def dynamic_geometry
    @dynamic_geometry ||= "#{DYNAMIC_THUMB_MAX_WIDTH}x#{DYNAMIC_THUMB_MAX_HEIGHT}>"
  end

  def dynamic_item_data(placement)
    t = placement.file.thumb(dynamic_geometry)
    ratio = t.width.to_f / t.height

    {
      ratio: ratio,
      width: (DYNAMIC_TARGET_HEIGHT.to_f * ratio).round,
    }
  end
end
